Comment On Safety In Numbers

I suppose one advantage to working with other people's code is that it's a good learning experience. Sometimes you walk away enlightened, "hey, cool! I didn't know you could do that!" Other times the lesson learned is something like, "I swear, if I'm ever this guy's boss, the only thing he'll be allowed to develop with is an Etch-a-Sketch." Jeffrey Johnson was fortunate to learn something a bit closer to the former after looking over his predecessor's code. He still can't believe how naïve he was for never checking for upper and lower case numbers ... [expand full text]
« PrevPage 1 | Page 2Next »

Re: Safety In Numbers

2005-08-16 14:02 • by Ytram
Duh.  Obviously an uppercase 1 is !



2 = @

3 = #



You get the picture [:P]

Re: Safety In Numbers

2005-08-16 14:03 • by Kiriai

My first thought is that perhaps he is checking if the Ignore Case of an Approval Type Code is a particular case.  Magic numbers sure, bad.


But somehow I'm guessing that it is a case insensative string compair....

Re: Safety In Numbers

2005-08-16 14:05 • by dubwai

Beyond the obvious but harmless WTF:


How about a variable to hold secApp.getApprovalTypeCode()?


And it should be "1".equals(... to avoid null pointer exception, assuming this is Java.

Re: Safety In Numbers

2005-08-16 14:06 • by DZ-Jay
Alex Papadimoulis:

I suppose one advantage to working
with other people's code is that it's a good learning experience.
Sometimes you walk away enlightened, "hey, cool! I didn't know you
could do that!" Other times the lesson learned is something like, "I
swear, if I'm ever this guy's boss, the only thing he'll be allowed to
develop with is an Etch-a-Sketch." Jeffrey Johnson was
fortunate to learn something a bit closer to the former after looking
over his predecessor's code. He still can't believe how naïve he was
for never checking for upper and lower case numbers ...

if (secApp.getApprovalTypeCode().equalsIgnoreCase("1"))
{
...
}
else if (secApp.getApprovalTypeCode().equalsIgnoreCase("2"))
{
...
}

...

else if (secApp.getApprovalTypeCode().equalsIgnoreCase("7"))
{
...
}




Well, of course the number does not have upper/lower case.  But he
is checking, in case the getApprovalTypeCode return does, duh!



    dZ.



Re: Safety In Numbers

2005-08-16 14:06 • by ferrengi
This functionality is necessary because in the future people will start using lowercase numbers.

Re: Safety In Numbers

2005-08-16 14:07 • by DZ-Jay
40910 in reply to 40908
DZ-Jay:


Well, of course the number does not have upper/lower case.  But he
is checking, in case the getApprovalTypeCode return does, duh!



    dZ.






Oh, and by the way, don't flame me; it was a joke.



    dZ.

Re: Safety In Numbers

2005-08-16 14:09 • by Anonymous Coward
thedailywtf.com is the forum where so-called "masters of their domain"
people pore over poor, wasted, (illegal), illogical, unoptimized,
lengthy code for hours and offer comments, correct code, thinking that
they are the Founders of The WTF? phenomenon, with the ultimate command
of their skills.



...while their productivity in their workplaces is often measured in
single digit scores, and the time that they waste in poring over the
poor, wasted code could have been best spent on good, improvisable code.



Don't ask why I am wasting time now...



Re: Safety In Numbers

2005-08-16 14:12 • by x-sol (to lazy to login)
slow wtf week huh

Re: Safety In Numbers

2005-08-16 14:31 • by xTMFWahoo
40913 in reply to 40904
Ytram:
Duh.  Obviously an uppercase 1 is !



2 = @

3 = #



You get the picture [:P]


OMG!  that is funny!

Re: Safety In Numbers

2005-08-16 14:33 • by David
40914 in reply to 40911

Anonymous:

Don't ask why I am wasting time now...


 


So why are you wasting your time now?


 


No, but seriously, how much you want to bet this guy is the writer of today's WTF?  [:P][:P]

Re: Safety In Numbers

2005-08-16 14:40 • by Tom
It's probably to tell the difference between 1 and 1.

Re: Safety In Numbers

2005-08-16 14:42 • by RayS
The numbers in caps:

ONE!!!!

TWO!!!!

...

NINE!!!!





After all, capitals are just shouting, right? I guess what this means
is that this program cleverly counts "ONE!!!!" and "1" as equal. Quite
an elegant solution.

Re: Safety In Numbers

2005-08-16 14:52 • by podperson
40918 in reply to 40917
He probably did it because of bad experiences with uppercase booleans...

Re: Safety In Numbers

2005-08-16 14:56 • by Devil's advocate
In Java, (at least last time I checked) equalsIgnorCase performs better than equals.

Re: Safety In Numbers

2005-08-16 15:01 • by osp70
I think that this is absolutely brillant!

Re: Safety In Numbers

2005-08-16 15:02 • by dubwai
40921 in reply to 40919

Anonymous:
In Java, (at least last time I checked) equalsIgnorCase performs better than equals.


How's that?

Re: Safety In Numbers

2005-08-16 15:05 • by DisturbedSaint
40922 in reply to 40914
Anonymous:

No, but seriously, how much you want to bet this guy is the writer of today's WTF?  [:P][:P]





I was thinking the exact same thing...



-ds

Re: Safety In Numbers

2005-08-16 15:05 • by dubwai
40923 in reply to 40911

Anonymous:
thedailywtf.com is the forum where so-called "masters of their domain" people pore over poor, wasted, (illegal), illogical, unoptimized, lengthy code for hours and offer comments, correct code, thinking that they are the Founders of The WTF? phenomenon, with the ultimate command of their skills.

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

Don't ask why I am wasting time now...


There's always some douche-bag that feels the need to waste his time chiding others for wasting theirs.  It's pretty stupid, especially when its's done with a sanctimonious tone like the above.

Re: Safety In Numbers

2005-08-16 15:05 • by CornedBee
40924 in reply to 40919
Anonymous:
In Java, (at least last time I checked) equalsIgnoreCase performs better than equals.


That's technically impossible unless the implementation of String.equals is a WTF in itself.

Re: Safety In Numbers

2005-08-16 15:16 • by Paul Tomblin
40925 in reply to 40923
dubwai:

There's always some douche-bag that feels the
need to waste his time chiding others for wasting theirs. 
It's pretty stupid, especially when its's done with a
sanctimonious tone like the above.





There's always some douche-bag that feels the need to waste his time
chiding douche-bags who chide others for wasting their time.  :-)



ObMontyPython: I know I'm not, and I'm sick and tired of being told that I am.

Re: Safety In Numbers

2005-08-16 15:30 • by dubwai
40926 in reply to 40925
Anonymous:
dubwai:

There's always some douche-bag that feels the need to waste his time chiding others for wasting theirs.  It's pretty stupid, especially when its's done with a sanctimonious tone like the above.




There's always some douche-bag that feels the need to waste his time chiding douche-bags who chide others for wasting their time.  :-)


Since I am already an admitted time-waster, your time is wasted writing the above.

Re: Safety In Numbers

2005-08-16 15:30 • by stevekj
Oh oh!  I know!  He should've used a switch statement!



Right?  Right?



Re: Safety In Numbers

2005-08-16 15:35 • by Hank Miller
Thats not funny.    Back in college I once caught myself
writing a 9 while pressing really hard on the paper where the 'shift'
key would be.   Sadly my pencil didn't understand such
notation and produced a 9, not a ( like I obviously wanted...



I caught this because while looking over my answers some didn't make
sense so I was re-doing them carefully.    Fortunately it
was one assignment so it didn't cost me a grade, and it gives me this
really err... interesting... story to tell.

Re: Safety In Numbers

2005-08-16 15:38 • by DanielR
Obviously, we need to replace the type code with inheritance and move this method to the secApp object.

Re: Safety In Numbers

2005-08-16 15:38 • by Mung Kee
40931 in reply to 40919
Anonymous:
In Java, (at least last time I checked) equalsIgnorCase performs better than equals.




It doesn't, especially for long Strings.  While equals() does use
the instanceof comparison operator, equalsIgnoreCase calls
Character.toUpperCase() AND Character.toLowerCase() on every single
character of both Strings, unless it finds one that doesn't match.



if (ignoreCase) {

    char u1 = Character.toUpperCase(c1);

    char u2 = Character.toUpperCase(c2);

    if (u1 == u2) {

        continue;

    }

    if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {

        continue;

    }

}

Re: Safety In Numbers

2005-08-16 15:46 • by John Stracke
40933 in reply to 40931
This is even worse than you'd think, since Character.to{Upper,Lower}Case()
are locale-dependent, which makes them hideously slow.  If you're
writing, say, a compiler for a
language with case-insensitive identifiers, your best bet is to downcase all identifiers as soon as you see them, rather than doing case-insensitive comparisons all over the place.

Re: Safety In Numbers

2005-08-16 15:55 • by rbriem
40934 in reply to 40911

Anonymous:
thedailywtf.com is the forum where so-called "masters of their domain" people pore over poor, wasted, (illegal), illogical, unoptimized, lengthy code for hours and offer comments, correct code, thinking that they are the Founders of The WTF? phenomenon, with the ultimate command of their skills.

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

Don't ask why I am wasting time now...


"Master of their domains ... hours"? More like "newbies with a clue ... minutes".


I don't even code in the languages represented here and I see the WTFs right off ...


OHHHHH. Whoops. I missed the <sarcasm> tag there.


Never mind.

Re: Safety In Numbers

2005-08-16 15:56 • by dubwai
40935 in reply to 40929

Anonymous:
Thats not funny.    Back in college I once caught myself writing a 9 while pressing really hard on the paper where the 'shift' key would be.   Sadly my pencil didn't understand such notation and produced a 9, not a ( like I obviously wanted...


Were you on acid?

Re: Safety In Numbers

2005-08-16 15:56 • by Mister Smith
40936 in reply to 40924
CornedBee:
Anonymous:
In Java, (at least last
time I checked) equalsIgnoreCase performs better than equals.


That's technically impossible unless the implementation of String.equals is a WTF in itself.


I think its more of a Java thing. I recall reading that inherited
methods are somewhat inefficient in java, in that String.equals()
[which overrides Object.equals()] will have a higher overhead than
String.equalsIgnoreCase() [because it is only declared for String].

In practise, it depends on the environment and on the version of java you are using, but equalsIgnoreCase can be faster when dealing with very small (1 or 2 character) strings.



Even if I misremembered, I don't think such a simple oddity is worthy
of being called a WTF. Maybe the code used to be a letter, and they
changed them to numbers without changing the code. (Actually, that's
probably a Bad Thing in itself, but I wouldn't think it deserves to be
a WTF.



(Wow, my CAPTCHA for today is 'random'... self descriptive spamblocking)



(except that when I hit "post", it says its wrong. Now its 'image'... self descriptive again)

Re: Safety In Numbers

2005-08-16 15:57 • by Mung Kee
40937 in reply to 40933
Anonymous:
This is even worse than you'd think, since Character.to{Upper,Lower}Case()
are locale-dependent, which makes them hideously slow.  If you're
writing, say, a compiler for a
language with case-insensitive identifiers, your best bet is to downcase all identifiers as soon as you see them, rather than doing case-insensitive comparisons all over the place.





Even simpler than a compiler...any global web application.  At my
last company they preached i18n through the whole dev cycle, yet there
are ASCII depenedent comparisons all over the app.

Re: Safety In Numbers

2005-08-16 15:59 • by dubwai
40938 in reply to 40911

Anonymous:

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.

Re: Safety In Numbers

2005-08-16 16:01 • by Mung Kee
40939 in reply to 40938
dubwai:

Anonymous:

...while their
productivity in their workplaces is often measured in single digit
scores, and the time that they waste in poring over the poor, wasted
code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.





I think it falls into one of these categories:

http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns

Re: Safety In Numbers

2005-08-16 16:06 • by dubwai
40940 in reply to 40936

Anonymous:
CornedBee:
Anonymous:
In Java, (at least last time I checked) equalsIgnoreCase performs better than equals.

That's technically impossible unless the implementation of String.equals is a WTF in itself.

I think its more of a Java thing. I recall reading that inherited methods are somewhat inefficient in java, in that String.equals() [which overrides Object.equals()] will have a higher overhead than String.equalsIgnoreCase() [because it is only declared for String].


This is nonsense.  Java method lookups go from the most specific up the heirarchy.  Even if the compiler did apply some optimization to equalsIgnoreCase method call, it's going to be miniscule in comparison to extra work required for an equals ignore case comparison.


Anonymous:

In practise, it depends on the environment and on the version of java you are using, but equalsIgnoreCase can be faster when dealing with very small (1 or 2 character) strings.


There are so many myths about Java it's unbelievable.  They seem to have reached this critical mass where they cannot be stopped.


 

Re: Safety In Numbers

2005-08-16 16:12 • by dubwai
40942 in reply to 40939
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Great link.  The 'Absolver' and 'Chain of Possibilities' really apply to my current work.

Re: Safety In Numbers

2005-08-16 16:21 • by rsynnott
40944 in reply to 40913
xTMFWahoo:
Ytram:
Duh.  Obviously an uppercase 1 is !



2 = @

3 = #



You get the picture [:P]


OMG!  that is funny!




Wrong tho; it's obviously region specific. Here, uppercase 2 is '"' and
uppercase 3 is '£'. (Incidentally, the caps lock key on some old
typewriters was actually a shift lock ;) )

Re: Safety In Numbers

2005-08-16 16:26 • by JohnO

This is certainly the weakest WTF I have seen since I started reading this site.

Re: Safety In Numbers

2005-08-16 16:29 • by AK
Not a huge WTF..  on modern machines, with Strings with lengths of
one, using the equal instead of the ignoreCase will yield about 0.15
second difference...  For every million call! :P



1 000 000 iterations:  15ms for equals, 172ms for ignorecase,



I've seen MUCH worst than this!

Re: Safety In Numbers

2005-08-16 16:41 • by rsynnott
40949 in reply to 40947
Anonymous:
Not a huge WTF..  on modern machines, with Strings with lengths of
one, using the equal instead of the ignoreCase will yield about 0.15
second difference...  For every million call! :P



1 000 000 iterations:  15ms for equals, 172ms for ignorecase,



I've seen MUCH worst than this!




First, that's no joke in certain cases. Besides that, though... it's
just STUPID. The programmer is obviously an idiot doing copy-and-paste
with no real understanding.

Re: Safety In Numbers

2005-08-16 16:52 • by tiro
40950 in reply to 40939
Mung Kee:


I think it falls into one of these categories:

http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns




At my current job, from which I have just given my two weeks notice, I
was told to "use less classes".  I created a class called
${SomeDomainSpecificGarbage}Adopter.  This was not questioned at
code review, and is now a part of our (soon to be their) production
code.   Truly a resign pattern in this case, and a WTF to
call my own!

Re: Safety In Numbers

2005-08-16 17:01 • by WTFer
40951 in reply to 40947
Anonymous:
Not a huge WTF..  on modern machines, with Strings with lengths of
one, using the equal instead of the ignoreCase will yield about 0.15
second difference...  For every million call! :P



1 000 000 iterations:  15ms for equals, 172ms for ignorecase,



I've seen MUCH worst than this!


The WTF are not only related to the slowness of the code, but also if the code is idiotic.

Re: Safety In Numbers

2005-08-16 17:02 • by Mung Kee
40952 in reply to 40950
tiro:
Mung Kee:


I think it falls into one of these categories:

http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns




At my current job, from which I have just given my two weeks notice, I
was told to "use less classes".  I created a class called
${SomeDomainSpecificGarbage}Adopter.  This was not questioned at
code review, and is now a part of our (soon to be their) production
code.   Truly a resign pattern in this case, and a WTF to
call my own!




So it's an Adopter pattern wrapped that will become an Absolver pattern
when you're gone.  It's always nice to leave a steaming pile for
the next guy.

Re: Safety In Numbers

2005-08-16 17:15 • by RaolinDarksbane
40954 in reply to 40939
Mung Kee:
dubwai:

Anonymous:

...while their
productivity in their workplaces is often measured in single digit
scores, and the time that they waste in poring over the poor, wasted
code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.





I think it falls into one of these categories:

http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns




Oh come on, it is a perfectly cromulent word.

Re: Safety In Numbers

2005-08-16 17:16 • by dubwai
40955 in reply to 40942
dubwai:
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Great link.  The 'Absolver' and 'Chain of Possibilities' really apply to my current work.



I also see a lot of the Simpleton pattern.

Re: Safety In Numbers

2005-08-16 17:18 • by dubwai
40956 in reply to 40954
Anonymous:
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Oh come on, it is a perfectly cromulent word.


That means?

Re: Safety In Numbers

2005-08-16 17:19 • by emptyset
40957 in reply to 40929

Anonymous:
Thats not funny.    Back in college I once caught myself writing a 9 while pressing really hard on the paper where the 'shift' key would be.   Sadly my pencil didn't understand such notation and produced a 9, not a ( like I obviously wanted...


that's the most awesome thing i've heard all day.

Re: Safety In Numbers

2005-08-16 17:40 • by Mung Kee
40958 in reply to 40956
dubwai:
Anonymous:
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their
workplaces is often measured in single digit scores, and the time that
they waste in poring over the poor, wasted code could have been best
spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Oh come on, it is a perfectly cromulent word.


That means?





Simpson's reference

http://en.wikipedia.org/wiki/Cromulent#Cromulent

Re: Safety In Numbers

2005-08-16 17:45 • by dubwai
40960 in reply to 40958
Mung Kee:
dubwai:
Anonymous:
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Oh come on, it is a perfectly cromulent word.


That means?




Simpson's reference
http://en.wikipedia.org/wiki/Cromulent#Cromulent


I meant what does 'improvisable' mean.

Re: Safety In Numbers

2005-08-16 18:21 • by joodie
40962 in reply to 40960
dubwai:
Mung Kee:
dubwai:
Anonymous:
Mung Kee:
dubwai:

Anonymous:

...while their productivity in their
workplaces is often measured in single digit scores, and the time that
they waste in poring over the poor, wasted code could have been best
spent on good, improvisable code.


What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.




I think it falls into one of these categories:
http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


Oh come on, it is a perfectly cromulent word.


That means?




Simpson's reference
http://en.wikipedia.org/wiki/Cromulent#Cromulent


I meant what does 'improvisable' mean.





The article on "cromulent" should have explained.





Re: Safety In Numbers

2005-08-16 18:38 • by Bill Kerney
40963 in reply to 40940
Believing that Equals with or without comparing case will have any sort
of noticeable performance impact is just laughable. People care about
performance at all the wrong times. :p



This code is not a WTF. Perhaps it is reading keys from the keyboard,
and at some point he might want to change a key binding from a '9' to a
'P'. If this was a possibility, he is 100% correct to use ignores case.
Especially so, if changing the key bindings is a common operation, or
if they might want to extend it into the future to perhaps read from a
.cfg file. Otherwise they make a trivial change and the code breaks.



There's nothing wrong with this code, especially if its within the context of a larger switch statement.



-Bill Kerney



Re: Safety In Numbers

2005-08-16 18:44 • by Anonymous
40964 in reply to 40914
this 'guy'??

dude! How the hell did you guess correctly!

I am a guy!!!

« PrevPage 1 | Page 2Next »

Add Comment