Even without any editor features from the last 20 years (like auto-adding and auto-closing braces), typing semicolons and curly braces should not end up taking a significant portion of time.
Typing doesn't take a significant portion of a programmer's time anyway. Automation on that half of the work is only so useful.
Checking the code on your screen against your internal mental model does take varying amounts of time. It depends on language syntax and how your mind works.
Different programmers internally think in different ways, it turns out.
In my case I found that I tend to look at the indentation primarily, and then I check parentheses and semicolons against the indentation.
(So in my case python lets me skip an entire step.)
Indenting is not hard, and programmers should be good at it, provided they care about clean code. I like that Python forces indentation rules because it means I'll never have to read code that has confusing/improper indentation. ESLint has an indent rule to enable it for JavaScript.
I was bitten so many times by un-indented code, thanks to copy / paste that took me hours for figure out what was the actual problem.
I wish Python had closing...how do we call them, tags(?), clauses?
Anyway, here's an example of what I mean:
Before:
def IsPalindrome(s) -> bool:
for i in range(len(s)):
if s[i] != s[len(s)-1-i]:
return False
return True
print("Is Anna a palindrome?", IsPalindrome('ANNa'.lower()))
after:
def IsPalindrome(s) -> bool
for i in range(len(s))
if s[i] != s[len(s)-1-i]
return False
endif
endfor
return True
enddef
print("Is Anna a palindrome?", IsPalindrome('ANNa'.lower()))
There is nothing wrong with properly indenting code. The lack of {} makes python very ugly when things no longer fit on one line. Because Python has an opinion about whitespace there are certain ways one can break a line an other ways one cannot. The result looks very ugly. Maybe the old way of using a backslash was not the worst, but linters nowadays don't like that anymore. Also having : also does not make things look better. Python must be one of the most ugly looking languages out there.
You might be already aware of this, but besides using the backslash, the other way you can allow an expression to span multiple lines in Python is to enclose it in brackets. I find this to be pretty unobtrusive. Often your line break will already be within a pair of brackets anyway.
I don't get it either. I mostly use C#, but I somehow manage to properly indent it anyway. Whenever I use python, I don't have any issues with indentation.
To me this discussion always sounds a bit like people complaining they can't find any brown underwear.
In Python, whitespace is explicit, so actually, the bug you just posted hadn't happened if they used Python. Indeed, in your link, the braces are implicit too.
Properly indenting code is fine. Now try modifying that code, like removing an if statement inside somewhat nested code and trying to ensure that everything still has the same meaning as before. With Python, you can never be sure you did it right.
Because everyone (and all their editors) on every project have to handle indentation identically or as soon as someone makes an edit, things won't run.
The purpose of parenthesis is too let the language know when the condition ends, and the statement begins. In a language with mandatory curly braces, the brace does that job already.
Can we also have multi line lambdas? It will make loops in trees of components (html, UI etc) easier. Generating html in Python will look much better than:
```
with lib.html():
with lib.body():
with lib.ul():
for i in items:
with lib.li():
lib.add(i)
```
I just wrote my code as normal (indented, thank you very much) and could ignore semicolons and curly braces, and the code just ran.
I was done in half the time!
This seems like a regression by people who are bad at indenting their code. ;-)
(see also: https://pypi.org/project/goto-statement/ )
Checking the code on your screen against your internal mental model does take varying amounts of time. It depends on language syntax and how your mind works.
Different programmers internally think in different ways, it turns out.
In my case I found that I tend to look at the indentation primarily, and then I check parentheses and semicolons against the indentation.
(So in my case python lets me skip an entire step.)
But nowadays it's autocompleted anyway.
b) When reformatting code like
you're liable to make a typo and commit a grave logic error.So there's arguments either way.
Now that I'm used to it, I do feel that indentation errors (or at least an indentation/paren mismatch) should probably be a syntax error either way.
Possibly people who argue for belts and suspenders might be on to something?
I put the cursor over a curly bracket, press CTRL-M, the cursor navigates to the other curly bracket.
My eyes also parse code much faster when it is both indented and with proper brackets.
Python just makes more difficult some common tasks like commenting out a try/catch block without having to reindent all the code inside.
Not a win IMO. In fact, Python presumes it is easier to use, while in reality, it is not.
I wish Python had closing...how do we call them, tags(?), clauses?
Anyway, here's an example of what I mean:
Before:
after:That sounds like a PEP-8 violation ;)
All your lines should be under 79 characters.
Might look ugly to some but to others it looks fine.
What are y'all doing??
To me this discussion always sounds a bit like people complaining they can't find any brown underwear.
Braces are explicit, whitespace implicit.
https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-...
https://en.wikipedia.org/wiki/Zen_of_Python#Principles
If you can call 2021 recent, that is.
[1] https://docs.scala-lang.org/scala3/reference/other-new-featu...
Won't fly with Python's "one way to do it" principle though.
Not having braces makes python very easy to teach where the keyboard layouts do not favour those characters accessibility.
Happy hacking!
if x = 5 then writeln;
I love how concise and clean Python looks. I would rather see other languages removing brackets.
``` with lib.html(): with lib.body(): with lib.ul(): for i in items: with lib.li(): lib.add(i) ```