Readit News logoReadit News
Kim_Bruning · a year ago
The first time I used python I was amazed.

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/ )

gkbrk · a year ago
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.
Kim_Bruning · a year ago
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.)

illiac786 · a year ago
It used to depend on your keyboard layout I will say.

But nowadays it's autocompleted anyway.

otabdeveloper4 · a year ago
a) All sorts of shitty code and text formatters will ignore or clobber whitespace.

b) When reformatting code like

   for a in x:
     f(a)
     if something:
       g()
you're liable to make a typo and commit a grave logic error.

Kim_Bruning · a year ago
Of course, on the other hand, you can just as easily misread this example if you don't notice the incorrect formatting.

  for (let a of x) {
    f(a);
  if (something) {
    g();
  }
  }
If you're a programmer who looks primarily at indentation for their syntax cues, it's the parens that can lead you into traps.

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?

jerpint · a year ago
Why would curly braces stop you from making the same logic error?
xigoi · a year ago
Why are you using shitty tools?
bsza · a year ago
Why do I need to be good at indenting when it can be 100% automated assuming the language has braces? I’m a programmer, not a typesetter from 1520.
NotMichaelBay · a year ago
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.
Shorel · a year ago
I am used to the curly brackets, and my keyboard muscle memory is used to the curly brackets.

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.

stefanos82 · a year 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 · a year ago
I like these end clauses but they can get cumbersome in heavily nested control structures. Ruby, I'm looking at you.
jerpint · a year ago
Some editors display permanent indentation lines which help visually resolve the indentation
Chris2048 · a year ago
I 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 · a year ago
why not braces then?
timbit42 · a year ago
They either don't line up vertically, or take extra vertical space.
aspyct · a year ago
What is so wrong about properly indenting your code that you feel it's necessary to add {} to make it better?
cjfd · a year ago
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.
housecarpenter · a year ago
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.
giancarlostoro · a year ago
> when things no longer fit on one line

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.

xigoi · a year ago
Black can usually reformat code pretty well.
gkbrk · a year ago
Being able to copy-paste code with every editor and not ending up with broken code is a real time saver.
andybak · a year ago
Why have I never had a problem copy/pasting Python?

What are y'all doing??

spirit557 · a year ago
So if this became popular you'd have some camps using it and some not. Wouldn't that be ironicly more annoying than the problem it's solving?
lozenge · a year ago
Only if the use of a stupid editor is saving you time.
Netcob · a year ago
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.

happymellon · a year ago
You could always ask Apple.

Braces are explicit, whitespace implicit.

https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-...

JohnKemeny · a year ago
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.
arunix · a year ago
And of course, "Explicit is better than implicit"

https://en.wikipedia.org/wiki/Zen_of_Python#Principles

bernds74 · a year ago
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.
rlpb · a year ago
I don't see why not. Simple visual inspection confirms if it does what you expect, unlike languages that use braces.
qgin · a year ago
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.
throwawa14223 · a year ago
For my ability to read and assess source code significant white space kills me.
datavirtue · a year ago
The "properly" part.
smokel · a year ago
Amazingly, Scala has recently adopted significant whitespace [1], and is moving in the opposite direction.

If you can call 2021 recent, that is.

[1] https://docs.scala-lang.org/scala3/reference/other-new-featu...

nine_k · a year ago
IDK; Haskell normally uses significant whitespace, but also can use braces instead, so you can write any snippet linearly.

Won't fly with Python's "one way to do it" principle though.

sergioisidoro · a year ago
An interesting note about braces is how US-keyboard centric they are. Typing a braces in many keyboard layouts requires 3 keys presses (or AltGr)

Not having braces makes python very easy to teach where the keyboard layouts do not favour those characters accessibility.

bobim · a year ago
Yes, but lists, dicts and comments still requires reaching altgr nevertheless.
sergioisidoro · a year ago
True. But I would say their use is one order of magnitude less than a block delimiter.
finger · a year ago

  if __name__ == "__main__" {
      print_message(10);
  }
This just looks wrong without parenthesis around the conditional statement.

ufo · a year ago
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.
paulcole · a year ago
I’ve got a side project called Parenthon that I’m going to release soon. Let me know if you want in on the beta!
kova12 · a year ago
It does, doesn't it? I wish there was some sort of compat layer which would allow to natively use python libraries in Javascript
ComputerGuru · a year ago
Welcome to rust!
apetrovic · a year ago
Huh? Rust, Go, Swift and probably many more languages does the same.
dvh · a year ago
In pascal you can call function that has no arguments without parentheses: writeln;

if x = 5 then writeln;

Einenlum · a year ago
I first thought this was trolling, but reading some reactions here and there it's probably not.

I love how concise and clean Python looks. I would rather see other languages removing brackets.

aitchnyu · a year ago
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) ```

Kim_Bruning · a year ago
That lib looks very useful in and of itself! Are you thinking of a particular one?
aitchnyu · a year ago
That was pseudocode. There are tons of libraries like https://pypi.org/project/dominate/