I'm speechless about this piece of code.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
That's right. You can't have enough casting and converting going on.
Deja View - the feeling that you've seen this post before.
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
Rediculous .. you need to convert both to decimal to guarentee precision and get rid of that pesky implicit conversion ...
if(Convert.ToDecimal(Convert.ToInt16(chkdate.Length.ToString())) != Convert.ToDecimal("11")) {
doNoRealValidationCheck_NeverLearnRegex();
}
I'm largely language agnostic
After a while they all bug me :doh:
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."Except you forgot to convert the char types to some int type to ensure it would be a numeric comparison. :rolleyes: :)
Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]
-
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."leppie wrote:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0]){ if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0]) { return false; }}
Not so fast, your code does not work while his does. ;P [Hint] Your code will not return false for strings of length 1, 10, 101, etc.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
-
It's dead! =\
ROFLOLMFAO
-
Pete O`Hanlon wrote:
Convert.ToInt16(chkdate.Length.ToString()) != 11
why do you rely on an implicit Int16-to-Int32 conversion? I would recommend an explicit cast to make things more clear. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
I think this improves the code a lot… Extra precisions and conversions to make sure we're getting exactly what we want. :) ((Decimal)Convert.ToDecimal(chkdate.Length.ToString()) != (Decimal)Convert.ToDecimal(((Decimal)(11.0000000000000000000000000000)).ToString())).ToString() == Boolean.TrueString; The optimizing JITter is going to have fun with this one…
ROFLOLMFAO
-
I think this improves the code a lot… Extra precisions and conversions to make sure we're getting exactly what we want. :) ((Decimal)Convert.ToDecimal(chkdate.Length.ToString()) != (Decimal)Convert.ToDecimal(((Decimal)(11.0000000000000000000000000000)).ToString())).ToString() == Boolean.TrueString; The optimizing JITter is going to have fun with this one…
ROFLOLMFAO
You left out the string.compare call with the ignore case option, and specifying the CultureInfo on the ToString calls. :doh:
This blanket smells like ham
-
leppie wrote:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0]){ if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0]) { return false; }}
Not so fast, your code does not work while his does. ;P [Hint] Your code will not return false for strings of length 1, 10, 101, etc.
Of course not ! :) Thats an exercise for the next poor soul that works on the code :p
xacc.ide
IronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach." -
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
Is this what they call optimized code? :confused:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->ßRÅhmmÃ<-·´¯`·.
-
I've just read an article that included this little gem
://it checks it contains 11 char (dd/MMM/yyyy) if (Convert.ToInt16(chkdate.Length.ToString()) != 11) { //if it does not have 11 char then it will return false return false; }
I really don't know where to start (and yes, chkdate is a string).
Deja View - the feeling that you've seen this post before.
-
For checking whether the string contains a valid date the code is crap. (SCNR) This shows what the results of "high level" programming languages are. X|
Greetings from Germany
KarstenK wrote:
This shows what the results of "high level" programming languages are
Idiot developers who shouldn't be let anywhere near a keyboard without being wired up to the mains and given a shock everytime they produce crap like this.
Deja View - the feeling that you've seen this post before.
-
It's dead! =\
ROFLOLMFAO
It is now. It was removed because it was so bad and about the best comment against it was that it was complete and utter rubbish.
Deja View - the feeling that you've seen this post before.
-
It is now. It was removed because it was so bad and about the best comment against it was that it was complete and utter rubbish.
Deja View - the feeling that you've seen this post before.
Pete O`Hanlon wrote:
It was removed
It should have been '
An Article of Horror
'. It is bad that it was removed and CP deprived many of a viewing pleasure. :mad:Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
Regional Weblog (in Tamil) :: Voicing for the Society
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT. -
It worries me that we are spiralling into some kind of recursive software hellhole:
void WritePoorCode()
{
bool stuck = true;if (stuck) { GetHelpFromAnotherMuppet(); }
}
void GetHelpFromAnotherMuppet()
{
WritePoorCode();
}void Main() { if (CantAffordAProfessionalDeveloper()) { CreateACompleteMessOfASystem(); } } void CantAffordAProfessionalDeveloper() { PayPeanuts(); } void PayPeanuts() { HireSomebodyWithLittleOrNoExperience(); } void HireSomebodyWithLittleOrNoExperience() { if (LearnedFromSchool()) { GuessCode(); } if (LearnedFromInternet()) { GrapSampleFromSomePlace(); } }
WPF - Imagineers Wanted Follow your nose using DoubleAnimationUsingPath
-
void Main() { if (CantAffordAProfessionalDeveloper()) { CreateACompleteMessOfASystem(); } } void CantAffordAProfessionalDeveloper() { PayPeanuts(); } void PayPeanuts() { HireSomebodyWithLittleOrNoExperience(); } void HireSomebodyWithLittleOrNoExperience() { if (LearnedFromSchool()) { GuessCode(); } if (LearnedFromInternet()) { GrapSampleFromSomePlace(); } }
WPF - Imagineers Wanted Follow your nose using DoubleAnimationUsingPath
I'm not sure that compiles... ;)
-
I'm not sure that compiles... ;)
-
It worries me that we are spiralling into some kind of recursive software hellhole:
void WritePoorCode()
{
bool stuck = true;if (stuck) { GetHelpFromAnotherMuppet(); }
}
void GetHelpFromAnotherMuppet()
{
WritePoorCode();
}catch (System.OutOfMemoryException) { GetHelpFromAnotherMuppet(); }
Ninja (the Nerd)
Confused? You will be...