- 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
If this were the first post, I'd mention, "first", else, provided this were a comment and I actually wrote it, i'd rather juster utter, "I wrote a comment."
Admin
I dispute the claim that that works. If e.FormTreeNode is null it should fall over at the first conditional.
Admin
I don't know about this code sample, but I've worked with people as described in this article. Back when I was green, a senior person was helping me fix some code that was calculating freight incorrectly. They told me how to change the code, I did, then we ran a test and checked the results. After a few repetitions I realized they were just guessing, and trying to see if they could make it produce the right answer. I kicked them out of my cube and found the root problem on my own.
Admin
Sounds like TDD.
Admin
And do you have any evidence that it ever could be null?
Admin
I have no question that this blog purposely adds tons of errors to posts, just to incite comments. This post is basically a code block between two sentences, and the first sentence barely makes sense.
Admin
The code is checking to see if it is null (which I think counts as evidence that it could be null), but only after it has already tried to dereference it earlier - which would have failed.
Admin
But if it is never called with a null
e.FormTreeNode
, it's not actually important to test for that case.Admin
That only counts as evidence that it was once null, so someone added that condition, and then later someone added the first condition because e.FormTreeNode is no longer null, without considering the function as a whole - this is how "simulated congealing" tends to happen
Admin
More like ADD.
Admin
This is a debugging technique that I call "beating the code into submission." But usually it includes random indentation, badly-named variables, and commented-out non-working versions.
Admin
Admin
If a FormTreeNode falls over and there's [nobody to hear]^W^W^W no code to catch it, does it make a [ sound]^W exception?
Admin
Gets paid by the line.
Admin
No, no, no. It's obvious. The coder had just learned about race conditions and is protecting against another thread modifying the content of e at the wrong time. Everyone knows that this is the correct way to handle it... What?
Admin
So THAT'S what the source code for the SQL Plan Query engine looks like when it estimates a good enough plan to pick based on statistics!
Admin
Well, this is TDD if you leave off the refactor step of red-green-refactor.
Admin
Writing "just enough code" that it works is a very powerful STEP, but it is just a step... Remember Red [Test Fails], Green [Test Passes], Refactor [make the code better without breaking it]. It is the failure of the third step that is the problem, not the existence of the second.
As far as the partial null, it is not so much that they needed to test that for the first part (though it certainly would be a good idea), but that there was a necessity to test it because of the latr conditional pass. Writing the test to check the flow at the bottom would have revealed the poor construct at the beginning.
Admin
Um, that's the definition of a CodeSOD. You must be new here.
Admin
Can you guarantee it won't be?
Admin
Wow you are so awesome.
Admin
If it could be null, the code wouldn't work. The article claims the code does work. Therefore, unless you're suggesting that the article is lying (and if so, on what grounds?), it can't be null.
Admin
This is actually Adiabatic programming (or rather Adiabuggic programming) Making small changes to the system while holding the total number of bugs constant.
Admin
I'm not sure if you're trolling here or just stupid. There's no way of knowing what gets passed in without checking it within the code. You cannot ever possibly guarantee it won't be null.
Admin
You encounter this method on a daily basis if you are a CS teacher/professor/TA/LA/etc. :-(
Admin
Not to mention, why are you just picking on e.FormTreeNode? e itself could be null, or any of the properties or methods used might throw exceptions when accessed/called. Or maybe they don't exist at all, and the code won't even compile. Or maybe it's actually supposed to be Lisp code, and the whole thing's just a giant syntax error. Speculating on any of those without evidence is pointless.
I, on the other hand, am sure that you are both trolling AND stupid.