News for hackers. Stuff that matters.
Re:Sizeof(char) is 1 by rdtsc on Monday September 06, 2010 @02:21AM (#1666054)
While the author is ridiculing those "silly" Mozilla devs I would like to ridicule the author of the blog. He seems like the person who would try to write "clever" code. Code that not only works correctly but teaches everyone _all_ the intricate operator precedence rules and all the possibly usages of bit operators, perhaps also code where they "cleverly" manipulate the call stack with asm inline instructions to demonstrate their assembly and C knowledge.

One thing I know -- that person is dangerous. How do I know? I was (perhaps still am) that person. It was a bad habit and I am still trying to get rid it. It is a veiled show of immaturity and arrogance.

Re:Sizeof(char) is 1 by wlievens on Monday September 06, 2010 @03:16AM (#1666144)
Absolutely.

I once had to deal with code that did something like this:

  return a ? b : c ? d : e ? f : g;
I'm not kidding.
Re:Sizeof(char) is 1 by rix0r on Monday September 06, 2010 @05:29AM (#1666323)
Which is actually pretty useful and readable, imho (if formatted correctly):

  return a ? b :
         c ? d :
         e ? f :
         g;
Side note: this does not work in PHP, as the operator is left-associative instead of right-associative there. The above in PHP would be evaluated as:

  return ((a ? b : c) ? d : e) ? f : g;
Which is almost never what you want. I can't even format this properly to convey intent.
Re:Sizeof(char) is 1 by wlievens on Monday September 06, 2010 @06:13AM (#1666378)
The only sane thing is to use if statements, imho. No ninja cowboy engineer nonsense.
Re:Sizeof(char) is 1 by pbiggar on Monday September 06, 2010 @08:02AM (#1666485)
Correct bracketing would be plenty in this case. If-statements sometimes (not always) make code much less readable than ternary operations.
Re:Sizeof(char) is 1 by Ralith on Monday September 06, 2010 @02:42PM (#1667157)
This is why more languages should adopt the every-form-returns-a-value paradigm.
Re:Sizeof(char) is 1 by sukuriant on Monday September 06, 2010 @06:49AM (#1666416)
Sometimes, if-statements unnecessarily add lines, and the lines become harder to read.

I would say it's a case-by-case statement. Well, okay, more specifically, I would say that the use of a single ternary if is a case-by-case statement.

Re:Sizeof(char) is 1 by wlievens on Tuesday September 07, 2010 @03:58AM (#1668366)
Absolutely. I use ternary if when appropriate. But nesting ternary ifs is horrible, and nesting ternary ifs while discarding parentheses is malevolent.