- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Why am I first?
Admin
protected Long getStatusCode() throws ProductCustomException{ Long statusCode = null; try{ statusCode = Long.valueOf(frist); //Why is this here?
}
Admin
I'm with the comment. Why is this a problem? Why try? Do 1, or do 0. There is no try.
Admin
I just had to mention that "Oma" is German (and Dutch) for "grandmother". It made me laugh to think of my grandma afflicted by code WTFs. She has enough trouble with technology already!
Admin
I bet the tab/spacing discrepancy is based on the copy/paste from Stack Overflow.
Admin
TRWTF is why in the first code block does the comment have a border? It's making the code look messed up
Admin
TRWTF is why statusCode is always set to 1. If all status codes are equal, what do they track?
Admin
Because it was a stub for some functionality that was never implemented - because management said "It works. Ship it!"
Admin
'Why is this here?' seems like the wrong question to ask. That answer is easy. That line is there so that statusCode does not stay null.
Other questions that I have:
Admin
Wait, this is Java. I know that one.
protected Long getStatusCode() { return 1L; }
Admin
So the right comment would be:
Why is this function here?
Admin
Looks like a test or god mode that you activate by changing the 1 to something else.
And who cares about spaces v tabs?
Admin
Let the holy wars begin.........
Admin
This must be some weird rendering bug on Chrome, all of the comments have borders, but it's only this one that looks weird.
Admin
In case of large values of 1...
Admin
Use spaces, use tabs, whatever you want. But mixing spaces and tabs is always The Real WTF and your instant clue you're dealing with a brillant programmer.
Admin
Long.valueOf(1) doesn't parse anything (as it would if you passed it a string), but rather boxes it into a Long instance (an object). Basically the same as new Long(1), but supposedly more efficient in cases such as this where the same values are often used (see https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html#valueOf-long-). This is different from 1L, which is a primitive number type.
And no, it never raises an exception of any kind nor can it ever return null. Unless there is something messing with your JVM / memory (damn gamma rays!).
Admin
Returning a constant result makes perfect sense if it is an implementation of an interface. Also, this might be the origin the WTF code: the implementor copied from another implementation without removing the try catch block.
Admin
Thought about this, too. But then, my kids' grandmother is a programmer. Also apparently there was "Grandma COBOL".
Admin
Had a colleague once who used to get me to help her debug her javascript errors. 9 times out of 10 (possible exaggeration for rhetorical flourish) it was caused by unbalanced braces and/or brackets.
My first advice to her was always "Format your code neatly." This is before resolving the tabs / spaces question -- this is to get the lines of the code to line up properly in the first place.
Once she had indented consistently, and got things to line up in a neat little pattern, the missing and unbalanced braces and brackets were usually immediately apparent.
The real WTF was that she never seemed to learn this lesson.
Admin
Format it however you want when you're writing it, then run the code through a styler that is configured to the in-house standard. Similarly when looking at existing code reformat it to start with.
Admin
"the indenting is provided via a mix of spaces and tabs"...reminds me of a story about someone who didn't know how to do "carriage returns", and added spaces to the END of every line, trying to make them match up on the screen!
Admin
Or in vim, 1GVG=
Admin
Or maybe an experienced programmer. One who started out with real computer terminals where a TAB always advanced to the next column of 8, connected to time-sharing systems where disk space was at a premium and wasted by lots of spaces.
Admin
It looks like whatever lib TDWTF uses to display the code blocks wrap parts of the code with span's to allow parts of it to be styled (eg the blue colour of the number literal and the red of the method name). A span with the class
comment
wraps the comment text, and it looks like this conflicts with the sites own stylesheet at https://thedailywtf.com/Content/Css/main.css which defines it's own styles for the.comment
selector, which is used for these comments.Admin
I think the answer to "why this is here"? Is that the developer never finished the code, probably got distracted by the phone ringing or going home time.
Admin
"what's not immediately clear here is that the indenting is provided via a mix of spaces and tabs."
Sad people don't seem to understand what fixed-width fonts are, or how to use a CLI editor (this is why we have things like Yaml).