- 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
First.getProcessor
Admin
I had a colleague who was screaming and shouting at me because he didn't like the fact that the language he was using behaved exactly as this post describes. I tried to explain about references.getProcessor but I'm still sure he never got it.
A few weeks later, when a manna-jar asked for input into questions for interview candidates, I sent him my colleagues faulty code to offer up to the candidate as a "What's wrong with this?" sort of question.
That suggestion was unfortunately not taken up, I believe because the manna-jar himself did not understand the code or the thinking behind it.
Admin
Eight lines of code and I count six red flags.
There are two instances of comparing strings in Java using
==
or!=
.There's a collection with 1-based indexing (not an issue with this code fragment but with the design of the collection).
There are two lines that assign a return value to a local variable that is immediately discarded/overwritten and not stored back to the collection.
There is inconsistent naming between the two
convertTo
methods (not an issue with this fragment but with the definition of an image processor).Admin
You misspelled "Frist" there.
Admin
I'm trying to figure out what the hidden meaning behind the extra "getProcessor" in the story is.
Admin
Python mostly avoids the problem of not knowing whether a method returns something new or modifies in place. Operations that work in place conventionally don't return anything, while operations that return a new object don't mutate it, so trying to use it the wrong way just fails. So we have list.sort() that works in place and returns None, and sorted() that returns a new list (and also accepts any iterable as the argument).
Beginners may take a little while to learn what's what (Stack Overflow is full of questions about why
list = list.append(thing)
sets list to None), but pretty soon it becomes second nature.Admin
No comments about string equality testing in Java needing to use the .equals method? I guess this isn't really a Java forum.
Admin
Jeremy Pereira did note that.
Admin
TRWTF is zero-based indexing. But if you're unfortunate enough to be working in a language/environment that forces it upon you (sadly, these days pretty much anything other than Fortran or VBA), it's still bad form to deviate.