3 ms·
Declarations don't need `end function` because it's always clear what you're closing. Statements need an `end if`, `end for` etc. because it lets you find your
by zetalyrae 3y ago
Declarations don't need `end function` because it's always clear what you're closing.
Statements need an `end if`, `end for` etc. because it lets you find your way in nested code. The rationale for the syntax explains it a bit: https://austral-lang.org/spec/spec.html#rationale-syntax https://austral-lang.org/spec/spec.html#rationale-syntax
FWIW I will probably get rid of the `module is ... end module.` bit because it adds unnecessary nesting.
- deleted 3y ago[deleted]
- imglorp 3y agoI appreciate the explicit nest around module. I was just suggesting a symmetric and consistent syntax that can be stated simply, to align with the stated goal. Dare I say, the (important) bit of Lisp syntax fits in a sentence! Yeah they hide the complexity in the library instead...
- webkike 3y agoWhy? No ability to nest functions? Why do you need a semicolon at the end of "end"?
- crabmusket 3y ago> No ability to nest functions? Correct > Why do you need a semicolon at the end of "end"? Per the rationale[1], "The purpose of the semicolon is to provide redundancy, which aids both reading and parser error recovery." Also, "For many people, semicolons represent the distinction between an old and crusty language and a modern one, in which case the semicolon serves a function similar to the use of Comic Sans by the OpenBSD project." [1]: https://austral-lang.org/spec/spec.html#rationale-syntax https://austral-lang.org/spec/spec.html#rationale-syntax
- lelanthran 3y ago> Statements need an `end if`, `end for` etc. because it lets you find your way in nested code. The rationale for the syntax explains it a bit: https://austral-lang.org/spec/spec.html#rationale-syntax https://austral-lang.org/spec/spec.html#rationale-syntax From the link: >> } >> } >> } >> } >> } >> Which one of these corresponds to the second for loop? Unless we have an editor with folding support, we have to find the column where the second for loop begins, scroll down to the closing curly brace at that column position, and insert the code there. This is manual and error-prone. I'm not fully convinced of that argument. Here's a devil's advocate take... The keywords do indeed help when the corresponding nested control structures are off-screen, but if the code you are reading is not refactored to move the control structures into their own function so that the indentation doesn't get that much out of hand, you likely have bigger problems with the code than determining which `end` corresponds to which control structure. IOW, having this sort of identification is moot: if it is needed, then the code itself is in such poor condition that it's likely not very readable anyway. In many cases it won't make a difference anyway (nested 'if's, for example - seeing multiple `end if` doesn't help) and the developer is still going to place a comment specifying which particular `if ()` is being ended. Having the unadorned closing braces (`}`) leaves the developer one of three options: 1. Refactor that code just to be able to read it, or 2. As you point out, add in comments like `// end if`, etc, or 3. Leave it as it is. If it's left as is, there's bigger problems in the code anyway.