News for hackers. Stuff that matters.
Re:Your programming language is probably unproductive by gravypod on Wednesday September 28, 2016 @11:03AM (#12598177)
I'd suggest you not leave if statements un-braced. I remember a study where they found the most common bug in most experienced open source developers was leaving out the braced initially, going back to make a change, and having that change introduce a bug.

Basically they had

   if (x)
      then()
and went back and did

   if (x)
      new_call()
      then()
and caused an error that happened silently.

This is something you definitely want to avoid and I personally don't trust myself, after a no-sleep code fixing bender, to remember to add {} around something if I'm editing an if. I'd probably forget.

Again, I'd say shorter does not mean better.

Re:Your programming language is probably unproductive by papaf on Wednesday September 28, 2016 @12:50PM (#12599219)
One way round this is to put single statement ifs on a single line:

    if (x) then();
If you add another statement to the if, its obvious from the indent that you need to use braces.
Re:Your programming language is probably unproductive by petre on Wednesday September 28, 2016 @01:21PM (#12599488)
Yup, I always do this when writing JavaScript or other languages that allow prefix single statements with or without braces. Otherwise I use braces if the statement is too long to fit in the editor w/o forcing you to scroll. Perl only allows postfixed single statements w/o braces, so you're safe:

    say "yes" if $condition;
    if ($condition) {
        say "yes";
        $affirmative++;
    }
Re:Your programming language is probably unproductive by gpderetta on Wednesday September 28, 2016 @04:35PM (#12601144)
7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]

if (x)

^~

9 : note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'

then();

^~~~

Re:Your programming language is probably unproductive by gravypod on Thursday September 29, 2016 @08:38AM (#12604764)
Relying on compiler-specific features.... where did I hear that before?

Oh yea, undefined behavior. Do you like using undefined behavior?

Re:Your programming language is probably unproductive by gpderetta on Thursday September 29, 2016 @09:26AM (#12605019)
That's just a warning. It has no effect on the generated code.

It is perfectly acceptable, and in fact considered proper engineering practice, to compile with multiple compilers to take advantage of their warning and static analysis capabilities.