Hacker News new | ask | show | jobs
by submeta 3207 days ago
Whitespace is no issue with a good editor (Sublime, vim, emacs...).

I dislike the many inconsistencies in Python. You mentioned one. Others: sort vs sorted (destructive vs non destructive). Also: not being able to chain methods because many don't return a value. (Scheme, Elixir or even Ruby are imho much more elegant.)

But all in all Python is a very useful programming language with a rich eco system.

1 comments

The Python design FAQ explains that .append and .sort return None to remind you they are mutation methods. I find this more elegant than Ruby, etc., where many things look like pure functions but aren't.

https://docs.python.org/2/faq/design.html#why-doesn-t-list-s...

I know the reasons why and how mutating methods work in Python.

Nevertheless I find this here much more elegant:

data.sort.tail.first # or this data.append(7).append(3)

More elegant than this:

sorted(data)[1:][0]

data.append(7) # and then

data.append(3)

I love method chaining in Elixir or Javascript. In Python I have to create temp variables here and there to capture / further process intermediate results.

Having said that: Python has it's strengths. I use it more than any other programming language.

I understand the preference and the difficulty created by methods and operators that are essentially statements instead of expressions. However, when making that criticism we should also acknowledge the benefit of requiring or encouraging multiple lines for those actions.

    if (x=42) {}
Has burned many people. Append having a useful return is comparable, though probably not as much of a trap.

> sorted(data)[1:][0]

I don't want to get into the weeds, but shouldn't that just be

    sorted(data)[1]
Or if you like unpacking for clarity

    first, second = sorted(data)[:2]

?