DEV Community

Discussion on: Why all this hate about Python?

Collapse
 
nektro profile image
Meghan (she/her)

There are mostly 2 things I don't like about python.

  • It's incompatible with itself. (2 vs 3)
  • It's syntax is confusing and goes against assumptions that other programming languages make, making it super difficult to learn coming or going to anything other than Python.

The second point is my main gripe with the language. So much of it seems to be different just because it can. There's a common phrase discussing learning new languages in that learning a new one becomes easier the more you know. And this is true for natural languages, as well as programming languages. Except python.

Consider the following code from the front page of python.org. I'm going to go over it line by line.

def fib(n):
    a, b = 0, 1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()
fib(1000)
  • def fib(n): This line is kinda okay actually and the most "normal". By looking at the rest of the snippet we can see that def is used to define a function, it's going to be called fib, and it takes a parameter n. (I use JavaScript a lot so I'm not offended by the loose type system, although I do enjoy languages with one.) The : here I'm also a fan of because one thing I do appreciate about python is the tab structure for code blocks. It forces a style guide at the compiler level helping the portability of scripts in a huge way.
  • a, b = 0, 1 I thing this assigns a to 0 and b to 1 but that's honestly a guess. I guess python supports SIMD but I'd much rather these assignments on different lines as the current syntax brings in a lot of unnecessary confusion.
  • while a < n: the a < n should be inside parentheses but that's more of a pet peeve I guess, so you do you, python
  • print(a, end=' ') is an alias for print(a, end='\n') but I did not know that until I had to look it up in the documentation to help a friend.
  • a, b = b, a+b I don't even know where to begin on how much this doesn't make any sense.
  • print() According to python.org, the output of this little script is 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 so this line seems useless. fib(1000) We called a function. Yay!

All this is only the tip of the iceberg when it comes to how much I don't like python's syntax. But that is the clarification I want to make. I don't hate python or anyone who uses it. If it gets your job done and you enjoyed making it, then I'll love python right with you. But, me personally, I never want to write python.

One more note I want to add before I close because it's probably the thing I hate most about the syntax is this:

signal = True
if (signal):
    response = "Hello"
print(response)

In any other language this does not work variables are supposed to have a concept of scope, which python seems to have forgotten about because it just lets you define variables out of thin air.