News for hackers. Stuff that matters.
Re:Apple's SSL/TLS bug by SideburnsOfDoom on Saturday February 22, 2014 @04:48PM (#7283767)
> I do write single statement conditionals without braces, but I write them on one line

That's fine until you write

    if (something) do_something(); do_something();
or worse:

    if (something); do_something(); 
I've actually seen something very similar to that one.

You haven't really changed the dimensions of the problem by putting it all one one line. Only the whitespace is different. Sure it looks wrong to you; but so does the incorrect code from apple.

I don't understand the need to omit braces; it doesn't make the compiled program any smaller. And denser source code is not always more readable, or we'd prefer "? :" to "if" every time.

Re:Apple's SSL/TLS bug by gsg on Sunday February 23, 2014 @12:50AM (#7285072)
Note that braces won't save you from

    if (something); { do_something(); }
(Personally, I configure my editor to highlight if (...); in bright red.)
Re:Apple's SSL/TLS bug by SideburnsOfDoom on Sunday February 23, 2014 @10:00AM (#7286056)
This is true; there is no silver bullet. So we rely on defence in depth.

The first line of defence is consistent code layout; e.g. always use "{ }" after an if, and only one statement per line. This aims to make simple typos less likely to compile, make the code more readable and so make errors stand out.

Then there is using and paying attention to the linter / compiler warnings / jshint + 'use strict' / static analysis or whatever it’s called in your language of choice.

Then there are unit tests or integration tests.

Any of these might have caught the apple error, but there are no absolute guarantees.

IMHO it's a professionalism issue – gifted amateurs are great, and they can succeed... most of the time. But a professional engineer would put aside ego "I won’t make mistake like that" and laziness "I don’t need to type braces this time" and do the careful thing every time. Because each step raises the bar, and makes it harder to ship code with bugs like this. Because sometimes it matters.

Re:Apple's SSL/TLS bug by grogenaut on Sunday February 23, 2014 @12:07AM (#7285008)
well you can also write:

if (something); { do_something(); }

So..