Re:Gravity – An embeddable programming language
by ainar-g on Friday June 22, 2018 @11:10AM
(#17374529)
In Go, one has to always write the if-else bodies in curly braces (and, the opening brace should always be on the same line). I think this is great for two reasons. Firstly, it prevents bugs where a very tired programmer needs to add something to the else body, which is written like this:
else
foo();
and writes else
foo();
bar();
which compiles, but doesn't do what you think it does. And I have seen this bug in actual projects.Secondly, along with gofmt, it prevents style wars.
Re:Gravity – An embeddable programming language
by jerf on Friday June 22, 2018 @11:41AM
(#17374829)
"In Go, one has to always write the if-else bodies in curly braces (and, the opening brace should always be on the same line)."
If you really want to twist the knife... even Perl 5 gets this right. Even Perl 5 thinks that naked if/else bodies is too crazy and error prone.
Re:Gravity – An embeddable programming language
by renox on Friday June 22, 2018 @08:35PM
(#17378688)
'even Perl5'?
Perl5 has also 'use strict' which ensure that variables ate declared before usage, a feature that Python doesn't have AFAIK.
Re:Gravity – An embeddable programming language
by krylon on Friday June 22, 2018 @04:44PM
(#17377181)
That is why I got into the habit, very early on, to always, always enclose blocks in curly braces (or begin-end, depending on the language). If it is ingrained deeply enough, one no longer has to think about it.
But it is nice if the language enforces it. I would even go so far as to claim it is common sense.
For my own interest, do you have examples of the way other languages do it? I'm interested, and but I'm afraid to google that.