Hacker News new | ask | show | jobs
by andyonthewings 2886 days ago
( ) are only optional if { } are mandatory, which is not true for some languages. e.g. in Haxe, one can write

    static function isEven(n)
        return if (n <= 1)
            n == 0;
        else
            isOdd(n - 1);

    static function isOdd(n)
        return if (n <= 1)
            n == 1;
        else
            isEven(n - 1);
i.e. An if expression consists of other expressions that may or may not be a block expression ({ }).
1 comments

There is a great deal of variability in languages about that.

Python ends if lines with a : which might help the parser, but maybe not because it was a late addition to help readability. For me it adds work when moving code around because I have to add or remove the :

Ruby does totally without any terminator in that context (in other contexts it has its own {} or do...end). The parser keeps processing successive lines until it understands that what follows can't belong to the conditional. I prefer that approach because it's the language/compiler that has to help me, not the other way around.