-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use colons before blocks #34
Comments
Which seems to be the main use case in Python. However, another more important point is noted after that:
(emphasis mine) If you are going primarily for readability (in the Python sense) then the colon makes sense. However since one of the goals of Snirk seems to be "correctness" I'd like to see arguments in favor of that. Readability is always going to come down to what programmers are familiar with, and by that metric you might as well use braces since most programmers are more familiar with C style syntax (C, C++, C#/Java, Go, Javascript). I realize I'm expanding this argument away from colons to denote blocks to the use of whitespace itself, but I would like to see a justification for it since I can't find it anywhere else. |
Why whitespaceMy main inspiration for whitespace was Coffeescript. In particular, when I was first getting into writing a parser, I was looking at other languages and wondering "why do I need to write all these symbols?" This is a valid concern for, i.e. parentheses around I have seen Python's reasons directly from their FAQ, and I've also heard that a survey was done while Python was in development (the FAQ mentions "one of the results of the experimental ABC language") to see if people preferred the colons. (The answer was yes, they found the code more readable.) I also agree that programming languages have to simplify their syntax to make writing syntax highlighters and such easier. I think that requiring the Coffeescript tries very hard to have the fewest characters, and leads to a lot of tight, nearly ambiguous constructs. Not only do they tokenize indentation like Python does, they have a rewriter to handle all of the "optional syntax, implicit syntax, and shorthand syntax." To be fair, Snirk does have indentation rules in its parser to allow language constructs to ignore indentation (Python does this around parens, Snirk has this extra for function signatures and to allow midfix operators to parse between lines if indented) but some of that can go away once (To be fair to Coffeescript, they do work around the standard Javascript problems like My motivations for indentation build on top of Python's motivations:
Furthermore, every reasonable styleguide which seeks to increase readability in brace programming languages requires standardized spacing (or in Go's case, tabbing). This is also true for programming languages that use I think that most programming languages that have (In Snirk, indentation is currently handled in the Tokenizer super loosely, no indentation size checks - I've opened #46 to address this) CorrectnessIf you want a programming language whose syntax is engineered to be hard to make mistakes with (or just be an antithesis to Coffeescript), look no further than Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line ("Hello, world!");
end Hello; Two statements to import a library and name, Although I respect Ada greatly and feel that it is, to this day, an innovative programming language, I don't think we need this number of tokens to write correct code. I don't think we need the In the end, perhaps braces do allow code to be less ambiguous. I'm already introducing one token ( |
Do things the Python way:
Instead of
Do
This applies to block level constructs:
I think that the
:
ultimately provides more readability and appearance of structure. Now the symmetry is that:
is used before a block but=>
is used to represent that code inline.This does mean we have to be careful of
:
in expressions. However, as with Python, I don't think it will come up much.The text was updated successfully, but these errors were encountered: