3 ms·
Up to a point, perhaps. Say you have both `if` and `unless` control structures. Two keywords where you could have just one, but they're closely related enough t
by wool_gather 8y ago
Up to a point, perhaps. Say you have both `if` and `unless` control structures. Two keywords where you could have just one, but they're closely related enough that there's not much burden. But what if their grammar was completely different, like say:
ifStmt := "if" "(" expression ")" statement ( "else" statement )?
unlessStmt := "{" exprStmt exprStmt* "}" "unless" expression ";"
I doubt this additional syntax would be a positive for the language's user. And the divergence will almost certainly make implementation changes more difficult. If we had instead:
ifStmt := "if" "(" expression ")" statement ( "else" statement )?
| "unless" "(" expression ")" statement
This smaller amount of syntax is easily understood, increases expressibility, and `unless` will most likely be implemented as simple sugar, just a negation of the expression in an `if`.
There's definitely some sweet spot in the middle, taking scan-ability and symmetry both into account.
- fooker 8y agoWould you same the same thing about loops? You can get away with just providing a 'while' loop (or maybe just goto and labels). Most languages end up with a for and maybe a repeat-until syntax for the sake of natural looking constructs.