Hacker News new | ask | show | jobs
by goku12 358 days ago
I also found the conditional syntax (with the condition in the middle) a bit awkward compared to Rust's or even C's. But there is certainly a common operation. And this is the syntax chosen by the Python language designers.

I'm curious. Why do you think it is bad? What are the possible issues that this style can cause?

1 comments

I think I only started to really hate it when I had to deal with some Python code where people decided to nest them and made a really hard to read mess where they should have used just a normal if-else chain. A Rust style if-expression would be better IMO, but it was Python code.

On a more basic level, I just don't see any good reason to put the condition in the middle.

Lisp: `(if <cond> <then> <else>)` Haskell: `if <cond> then <then> else <else>` Rust: `if <cond> { <then> } else { <else> }`

All the above read fine and normal. In the python version the order of execution is different then the left-to-right reading order.

It's not like it's a fatal flaw for a language to do it like Python. But it is just silly IMO. My POV is that I actually really like if-expressions, but hate the condition-in-the-middle syntax, so I tend to avoid it unless it's really short. When code changes slightly and becomes longer I'd rather not have to always double take if this now should change to an if-statment or to an expression etc.

> I think I only started to really hate it when I had to deal with some Python code where people decided to nest them and made a really hard to read mess where they should have used just a normal if-else chain.

Oof! I can see how that can get really messy really fast. Though I wonder how much of it is the language's fault as it is the programmer's. I used to tell my students to avoid trying to be too clever with the source code. Source is meant for humans to read. Leave the cleverness to the interpreter.

> On a more basic level, I just don't see any good reason to put the condition in the middle.

Thinking about it again, I think I understand why the language designers chose that order. They were trying to make it make it more readable by following the structure of the English language. "<Buy a steak> if <the butchers are open>. Otherwise <get some salmon>".

The problem here is that programmers are more accustomed to the natural and somewhat obvious order that every other programming language follows. They also wouldn't have expected some people to abuse it by nesting it.