9 ms·
I've written and committed my best bugs when drunk. Undoing them was a valuable learning exercie. The finest being, in C: if (nr = 0x56) ... That took and
by csmuk 13y ago
I've written and committed my best bugs when drunk. Undoing them was a valuable learning exercie. The finest being, in C:
if (nr = 0x56) ...
That took and entire day to find and made me religiously avoid lvalue assigments in expressions by doing:
if (0x56 == nr) ...
- girvo 13y agoI've written both my greatest (and most ingenious) code, and my absolute worst code while drunk. It seems to send me to one or the other extreme. No "average" drunk code here! Just awesome problem solving, or terrible terrible bugs!
- meowface 13y agoI'm sure everyone's seen this a thousand times by now, but it's incredibly pertinent for your comment: http://xkcd.com/323/ http://xkcd.com/323/
- InclinedPlane 13y agoThat should generate a compiler warning. And if you're not a criminal you have warnings set as errors.
- csmuk 13y agoThis was an oooold SunOS compiler that didn't warn about much other than you owe Sun more cash. Also when you're drunk, the warnings result in "ahh who cares" :)
- weland 13y agoThere is nothing incorrect or dubious in C about an expression like if (foo = bar), so it wasn't considered a reason to warn the user about for a long time, despite being a rather common culprit for bugs. Compilers popping up warnings about that is a fairly recent event.
- goldenkey 13y agoPretty sure that's been a warning for a long long time in most compilers. They require you to wrap the assignment to suppress it, that is: if ( (foo=bar) ) Anyho, it really depends on what your -W level is set to. It's good practice to use "-Wall"
- hipsters_unite 13y agoYoda assertions, nice.[0] [0] http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html http://www.codinghorror.com/blog/2012/07/new-programming-jar...
- delinka 13y agoconditions* ;-)
- hipsters_unite 13y agoHa, yeah that's what I meant. Love seeing them described that way!
- simias 13y agoI hate this convention to put literals on the left hand side of the comparison. Every time I stumble upon code like this my brains stalls for an instant trying to make sense of the expression. It just looks ugly and wrong in my opinion. It's also mostly useless because your compiler should warn you about your first construct (and tell you to add a layer of parens if that's what you really want to do). I realize I'm being a bit irrational with this whole thing but for some reason code like this drives me nuts (that and people not putting space around arithmetical operators and such: int a=2*4+foo(1,2,3)).
- benjamincburns 13y agoI do a ton of code reviews, often as part of an interview process, less often, for embedded developers. Conditionals written with literal lvalues is something of which I tend to take note. You're right, it's not natural, and it's less readable, but there's usually a reason why people do it: experience. If you often work in weakly typed languages, or those which allow for weird coercion in conditional statements, it's sadly often easier to form a habit which guarantees fewer bugs than it is to say "I'll always type the boolean equality/strict equality operator." "But why don't you use better languages, then?" Because in many cases (low-level resource-constrained systems programming), it's much, much easier to deal with these weird gotchas than to attempt to get exotic [1] languages such as Python, Ruby, Java, and sometimes even C++ (heap? who needs a heap??), to work. Even in cases where you're able to get these languages to work easily, you're just forcing yourself to become intimately familiar with the internals of some language with which you'll ultimately wind up wrestling [2]. Normally the point of such languages is to abstract away the system. This is the exact opposite of what you need in these environments. "But it annoys me when people use literal lvalues where they don't need to." Ah, but this is the rub of forming a habit. 1: I'm mostly sarcastic in my use of the word "exotic" here. Don't go crazy, now. ;-) 2: Though to totally contradict myself, I will say that both Rust and Go look very, very interesting here.
- danielweber 13y agoI still hate yoda-conditionals, but after reading your comment I now realize they have value.