What are the implicit line joining rules in Nim? (Like those described in Python docs.)
Why this code successfully works in Nim:
if false or
true:
echo(1)
whereas analogous code does not work in Python:
if False or
True:
print(1)
(Python requires you to use backslash character (\) after or, or put a whole if expression in parentheses.) Ok, thanks.
But may be this should be documented officially?
Also, it makes sense to allow such code:
if false
or true:
echo(1)
It is documented but admittedly well hidden: https://nim-lang.org/docs/tut1.html#statements-and-indentation
As a rule of thumb, indentation within expressions is allowed after operators, an open parenthesis and after commas.
(In the manual it's part of the official grammar rules.)
Also, it makes sense to allow such code:
if false
or true:
echo(1)
There's a reason grammar/style guides of many natural languages dictate putting punctuation and conjunctions before a line break.
It probably shouldn't be prohibited, but it's not a good style.
https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#variable-naming
https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#Optional-Indentation
It is useful to split long ternary operators and long conditionals.
but it's not a good style.
I disagree. Because the standard in mathematical typesetting is to write:
r = 1
+ 2
rather than:
r = 1 +
2