4 ms·
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
by stefanos82 3y ago
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()))
- zexbha 3y agoI like these end clauses but they can get cumbersome in heavily nested control structures. Ruby, I'm looking at you.
- jerpint 3y agoSome editors display permanent indentation lines which help visually resolve the indentation
- Chris2048 3y agoI prefer this idea, but instead of a shell-style ending unique to every scoped structure, maybe just a ";" character?: def IsPalindrome(s) -> bool for i in range(len(s)) if s[i] != s[len(s)-1-i] return False; ; return True; I'd also be inclined to skip it for 'def' as well, since they tend not be be as nested.
- jwineinger 3y agowhy not braces then?
- timbit42 3y agoThey either don't line up vertically, or take extra vertical space.
- fortyseven 3y ago...what?
- timbit42 3y agoThe braces.