News for hackers. Stuff that matters.
Re:Notes on Haskell: What's Wrong with the For Loop by jawn on Tuesday March 08, 2011 @08:42PM (#2303426)
There is no check that array[i] actually exists. If array[] has 2 items but args[] has 5, you will overflow the array.
Re:Notes on Haskell: What's Wrong with the For Loop by feral on Tuesday March 08, 2011 @08:47PM (#2303439)
I've been trying to figure out what he was getting at, as well. The original article, by Elliotte, seems to have updated the code snippet to:

' String s = ""; for (int i = 0; i < args.length; i++) { s += args[i]; } '

I deduce from this that the error was in the copy/paste. The line that was supposed to be changed to 's+= args[i]' was accidentally left as 's+= array[i]'

As such, its a simple failure to replace all instances of 'array' in the pasted code, rather than anything to do with 'operator overloading', or even to do with checking if 'array[i]' was out of bounds - there is simply no variable 'array' supposed to be in that context.

I wish Turoff had been less obtuse about it, especially as the original Elliotte post seems to have been silently updated.

Re:Notes on Haskell: What's Wrong with the For Loop by Stormbringer on Tuesday March 08, 2011 @09:21PM (#2303518)
In the interest of being fair, it is (by internet standards) quite an old blog post, which was probably a bit of a toss off effort in the first place.

If 'the bug' is just a copy/paste problem of a variable that doesn't exist in that scope, then compilation will fail at that point, so again, I don't see how that could be the one that Turoff said would survive for weeks in the wild.

Re:Notes on Haskell: What's Wrong with the For Loop by kscaldef on Tuesday March 08, 2011 @11:55PM (#2303864)
But, if the bug is a copy/paste of a variable that does exist in that scope, he's exactly correct that it could survive for weeks and be very difficult to actually track down (because of the sort of blindness to details that happens when you read "idioms" like this by visual pattern matching rather than actually reading the code).
Re:Notes on Haskell: What's Wrong with the For Loop by Stormbringer on Tuesday March 08, 2011 @08:47PM (#2303438)
D'oh!!! You're right!

I was mentally substituting args[i] for array[i]

Talk about code blindness. What a colossal blunder.

Re:Notes on Haskell: What's Wrong with the For Loop by artsrc on Tuesday March 08, 2011 @10:52PM (#2303707)
I up voted you showed so wonderfully that forcing an fallible human to correctly specify the same thing twice can result in errors.

But I don't think errors are the biggest issue. The biggest issue is that this kind of stuff should be getting out of our way so we can focus on other things.