At Twitter/X, someone posted a Python puzzle:
L = [1, 2, 3, 4]
for i in L[::-1]:
…print(i, end=’ ')
This’ll output:
4 3 2 1
This could’ve been done more intuitively like this:
L = [1, 2, 3, 4]
for i in reversed(L):
…print(i, end=’ ')
But I guess the one who posted it was trying to make things difficult/complicated since it was a ‘puzzle.’ Still some of the comments on the post were giving the impression that it was a teaching moment, that they were going to actually use this code in their projects. This worried me ‘cuz it forgets this: “Python generally has one way of doing things” refers to a core philosophy of the language, articulated in the Zen of Python, which states: “There should be one—and preferably only one—obvious way to do it”.
So I commented a reply to the puzzle: “One of the things that attracted me to Python was the philosophy that there should only be one way of doing things. Lately, people have been introducing multiple ways of doing things which is making Python less intuitive, overly complicated. Like L[::-1] instead of reversed(L).”
Someone replied: “Bro chill. It’s good to have options.”
I replied: “When you’re debugging a complex project w/ many programmers working on it, code that does the same thing but written in a myriad of ‘options’ makes for hard-to-read code & a nightmare to debug.”
What do you think? Are Python devs forgetting what makes Python great and successful compared to other programming languages?
One of the reasons PHP became unpopular is that so many PHP frameworks (Laravel, Symfony, CakePHP, etc.) appeared and they were adopted by different companies so PHP devs had to master a new framework if they changed jobs. Something similar is happening to Python’s web dev: Python devs now have to master Django, Flask, FastAPI depending on their client. And if you don’t use one framework for months, you’ll lose your mastery of it. If more frameworks come up, the same problem PHP programmers face will descend on Python devs (and it’s already occurring). I wish the Python Development Foundation would address this to avoid the mess PHP devs face.