Replies: 8 comments 4 replies
-
This suggestion is great and I hope it will be implemented. |
Beta Was this translation helpful? Give feedback.
-
Since Mojo is a superset of Python, it would need to support significant whitespace syntax. Adding braces also to define scope would be just two different ways of doing the same thing. I think Mojo would be worse for that, resulting in different coding styles, and large codebases would have difficulty in keeping things sane. Let's not do that. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
It's one or the other, and Mojo is Pythonic, i.e. indentation for code blocks. It's fine, most of us learn both ways depending on the language. |
Beta Was this translation helpful? Give feedback.
-
When I first learned python (probably around 2005), I was horrified at the syntax. How in the world could you not use braces? For 2 weeks, I clenched my teeth and just bared it. Over time, I noticed I stopped thinking about it. For me, as long as the syntax doesn't get too noisy, it is usually just something I deal with. The only real criticism I have of the indentation style syntax python uses is that it makes fluent builder style code ugly in python since you need to wrap the chained method calls in a parenthesis or use ugly \ for line continuation. I think if mojo deviates too far from python syntax, less python coders will want to dip their toes into the mojo side of the pool. The less divergent it looks to the average pythonista, the more willing they will be able to gradually learn. If mojo moved to a C-style braces world, I believe that will immediately off put a lot of pythonistas from even wanting to try it. Part of the reason I am putting my money on mojo over rust (and I love rust by the way...been programming in it almost 5 years), is that I think mojo picked the winning strategy by piggy backing off python syntax. At two companies I have worked at (one of them a well known streaming media company), I tried to get my coworkers into rust to no avail. And I believe a big part of that reason is rust's unfamiliarity and learning curve. While advanced rust does have a significant learning curve, IMHO, the basics of rust is not really that hard. But there is a significant onboarding cost where it may take 2-3 months until a user can start feeling even somewhat productive. And familiarity is most important for pythonistas, not rustaceans, gophers, or whatever it is swift language users call themselves :) Typescript "won" over purescript, elm, reasonml/rescript/bucklescript, or even flow, because it was the most similar to javascript. So I don't really see a compelling reason to use brackets in the syntax. Maybe mojo could use optional braces like Scala3 does, but even there I would be cautious. While I would like an implicit return, I think too much divergence is bad. The only real syntax change I hope mojo does, is allow for multi-lined lambdas. |
Beta Was this translation helpful? Give feedback.
-
-100 Apart from what the others already commented (that this would break the compatibility with Python), there're significant reasons why indentation is used for define blocks:
There is a good discussion posted here which explains why indentation is the best syntax. Furthermore, the syntax with braces and semicolons has its roots in the time when computers were programmed using punched cards. It was a way of telling the compiler when to begin and end the blocks and statements. Even with the end of punch cards, some languages continued to use this, because programmers ended up getting used to it. But today it's as if someone prefers a car with manual transmission when there are already cars with automatic transmission making their life easier. PS: As a former C# developer, I also was thought that the python syntax was weird (because my background), but along the time, I get used to it and today I think that is the best syntax ever to write and read. It's no wonder that Python is known for being one of the easiest languages made to date. |
Beta Was this translation helpful? Give feedback.
-
👎 Sorry but awful suggestion. |
Beta Was this translation helpful? Give feedback.
-
Hi @carpedil, our goal is for Mojo to be an extension of Python, not a brace language. Fragmenting the python ecosystem in this way wouldn't be adding value. 'fn' is added for specific reasons explained in the programmer's manual - we're diverging specifically because we /need/ different behavior than typical 'def' and we want to be compatible with python, so we need fn and def to be peers. |
Beta Was this translation helpful? Give feedback.
-
I agree that Mojo as a superset of Python is a good idea. However, Mojo replaces the def keyword with fn for function declaration. But why not abandon the use of indentation to denote code scope? This is also the reason why I don't like Python. Is this a common practice in dynamic languages? Even in shell scripting, the usual approach is to use {} to delineate scopes. I really hope Mojo can switch to using the {} style for coding. It wouldn't make Mojo more difficult to use, and I believe more people would like it. Using the fn keyword is reminiscent of modern programming languages like Rust and V. I hope the Mojo team can conduct more research during Mojo's early stages of development to see if more developers would be willing to accept the following style:
Compared to Python's original style:
At first glance, the second approach seems to have fewer characters because it's just two lines. However, when the code grows to dozens or hundreds of lines, the readability of the code will indeed be compromised. Do you agree?
Beta Was this translation helpful? Give feedback.
All reactions