4 ms·
This is why Ada disallows empty statements. You have to explicitly write "null;" which is a lot more obvious.
by kqr 4y ago
This is why Ada disallows empty statements. You have to explicitly write "null;" which is a lot more obvious.
- WalterBright 4y agoD's null statement is `{ }` which nobody is going to type by accident, whereas ';' is just a twitch of your pinky. `null` has another meaning in D, that of a null pointer. D also does not allow the syntax `a < b < c`. C does, to the eternal damnation of anyone who tries it.
- msla 4y ago> D also does not allow the syntax `a < b < c`. C does, to the eternal damnation of anyone who tries it. Far be it for me to teach the Pope to pray, but would it be reasonably reasonable to make that do the right thing? If your compiler can disallow it, it can detect it, so the grammar is obviously thinkable, and the semantics might be as well.
- lmz 4y agoI believe this is legal Python and does what you expect.
- afiori 4y agoIn the syntax `a < b < c` both the `<` are different operators than the `<` in `a < b`. It is more similar to the ternary operator `a ? b : c`. It could also just be a type error: `<` takes two integers and produces a boolean, so both `(a < b) < c` and `a < (b < c)` would be invalid.
- WalterBright 4y ago> would it be reasonably reasonable to make that do the right thing? I did think about that, and it's a good question. I did not out of concern for some C code translated to D then mysteriously misbehaving.
- rob74 4y agoThis is why in Go you always have to have a block after a condition or loop statement - a single instruction is not accepted.
- jabl 4y agoIt's a really minor point, but this is one thing I like about Rust syntax for conditionals vs. C/C++. It always requires the {} around the block, so it has no special rule for single-statement conditionals like C. At the same time, always requiring the {} means that it can get rid of the () around the condition. So all in all, it's as short or shorter than the C style syntax, and clearer without special cases.
- medo-bear 4y agothis sounds so silly to people writing in s-expressions
- rob74 4y agoLooks like several newer languages adopted that idea - Go does it too (also getting rid of the round brackets for loops and conditions, as well as of semicolons at the end of lines), but I'm not sure who started it...