Curly brackets instead of : #258
Replies: 5 comments 15 replies
-
This would be neat, but I also understand if it isn't added. There are existing languages that allow both indentation based blocks, as well as whitespace agnostic blocks surrounded in curly braces, so it is possible to pull off. Though one would have to consider if it clashes with any other Python syntax. |
Beta Was this translation helpful? Give feedback.
-
There are practical reasons why brackets will not work and why significant whitespace is crucial to the parser: lazy body parsing. Mojo's parser can trivially skip over the body of structs, functions, etc. because it can use the expected indentation to find the end of the indentation block. |
Beta Was this translation helpful? Give feedback.
-
Just my opinion but with modern code editors this whole issue of not seeing indentations with spaces is mostly gone, guard lines, coloring of blocks et rest. Adding curly brackets would also make it less Pythonic and also suddenly make use of curly brackets for some other purpose more complex concerning tokenization. |
Beta Was this translation helpful? Give feedback.
-
I see the point. I use black auto-save when formatting so it mostly handle such cases. I do think modern editors have made it much easier to avoid block notation in computer languages. Also, if this ever will happen, it should be an option as the idea of Mojo is to be a super-set of Python, you for example change the file postfix or use a simple translation tool to get going. Having the syntax very different will make Python coders very uncomfortable. |
Beta Was this translation helpful? Give feedback.
-
Hi all, This suggestion cuts directly against or goals for Mojo, which is to be a member of the Python family. Thank you for your suggestions, but our goal isn't to design a new language from first principles (been there done that :-) ), it is to lift an existing ecosystem. We are also not adding general syntactic sugar, we are focused on core systems programming features that Python lacks. -Chris |
Beta Was this translation helpful? Give feedback.
-
The option to use curly brackets instead of indents and :. The option to use both would make it easier to code and format the code. Some more python code gets extremly hard to read when there are too many indents and auto formatting isn’t working that well when you look at cargo fmt. It’s pretty useful to just write the code and format it later. It happens sometimes in rust that you mess up the indents, which will be fixed by the formatter later. A wrong indent will break python code and that happens fast.
Beta Was this translation helpful? Give feedback.
All reactions