Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Is Not A Great Programming Language

Python is not a great programming language

Let me start off by saying what is nice about Python:

  • The philosophy of "one correct way to do things."
  • Easy to learn (at the start).
  • Pretty complete standard libraries.
  • A huge ecosystem of good third-party libraries.
  • Forced indentation. It's a mixed bag, but I've worked with too many junior developers who would never have indented otherwise.
  • The import system makes it easy to trace the filepath for any dependency.
  • """Docstrings"""

Now what's bad. TLDR: it's great for beginners, but then its syntax turns everything into a mess.

  • The syntax for classical inheritance. Half of each Django app is super().__init__(*args, **kwargs). At least you don't have to pass arguments to super anymore.
  • Too many magic __double-underscore__ methods and properties that you have to just memorize.
  • Too many top-level built-in functions that (a) you have to just memorize, and (b) get really ugly. You end up with stuff like list(map(...)). I haven't used so many nested parentheses since my early days in PHP. Guido's explanation makes sense in theory, but is really annoying in practice.
  • Too many other weirdo bits of magic syntax, like [list comprehensions].
  • Django specifically is so full of magic words, and its documentation is so convoluted, that I've basically given up on documentation altogether and just look at the Django source code now.
  • Needing to put dict property names `{'in': 'quotes'}.
  • You have to cast your data back to a list/tuple after using enumerate() and map().
  • Different syntaxes for lists and tuples.
  • foo['bar'] returns a KeyError, so you have to do foo.get('bar')... or in some cases getattr(foo, 'bar', None), but not in others because getattr and .get are different things.
  • You can't just tack on flags to /regular_expressions/ig.
  • All the goofy string literals: f' ', u' ', r' ', etc.
  • Pipfile does not work that well.

I didn't really like Ruby until I started writing Python.

(Disclaimer: a big part of my frustration comes from having a JavaScript background. I know JavaScript is a "bad" language, so I was really excited to learn a "good" one... only to be disappointed in Python for many of the same general reasons JS is "bad.")

@calebpower

This comment has been minimized.

Copy link

calebpower commented Oct 12, 2019

A couple of others:

  • Better Ask Forgiveness Than Permission is a terrible philosophy to default to, and should only be used when reasonably sure that its necessary (as opposed to Look Before You Leap)
  • White space as syntax is reminiscent of RPGLE on AS/400; developers should learn how to write great code, not be forced into a style
  • Tendencies of developers to use it for absolutely everything is sad, but a good measure of how well-rounded a developer is

(Edit) I think points 1 and 3 are my "issues with many of the Python community" rather than "issues with the language" though.

@cmlburnett

This comment has been minimized.

Copy link

cmlburnett commented Oct 12, 2019

What you don't like about Python seems to me to come from not understanding its underlying data model. I would recommend James Powell's 2017 PyData talk on becoming a Python expert (https://youtu.be/cKPlPJyQrt4).

  • The double underscore "magic" methods are all driven by this model.
  • Generators (and your "need" to cast returns from enumerate() and map()) are driven by this model. (PS, you absolutely do not need to convert the generators into lists as they will quack and walk like a duck when you need them to.)
  • Look at 'bar' in foo and 'bar' not in foo style syntax if you need to test if a key is in a dict or not and to do so without throwing KeyError's.
  • There's also dictionary comprehensions. Comprehensions have their place and can make code more concise and cleaner. Here's a double dict & list comprehension that would, equivalently, require 5 lines and 3 temp variables.

"""Converts "a=10,b=20" into {'a': 10, 'b': 20} dictionary"""
{k:int(v) for k,v in [_.split('=') for _ in "a=10,b=20".split(',')]}

  • Oddly, your use of "{'in': 'quotes'}" is, in fact, a dictionary comprehension... It is magic syntax, just like "[list comprehensions]" that you complain about. Same thing. The irony is interesting.
  • You realize that keys of dictionaries don't have to be strings (can be anything hashable)? You have to put quotes there because you want the key to be 'in' rather than throw a SyntaxError because in is Python syntax. What would you want foo['bar'] to result if foo had no 'bar' in it? Return None? What if foo had a key in it 'bar' and that its value was None? Now you've confused two very different results (this sounds like JavaScript). If you wan this, then do foo.get('bar', None) and you're happy. The behavior is defined.
  • There's a vast difference between a dictionary key and an object attribute. dict.get() and getattr() should not remotely be confused. See above comments about the data model.

I think your grievances with Python will dissolve with better understanding of Python itself. Expose yourself to Python beyond Django...

@patmoore

This comment has been minimized.

Copy link

patmoore commented Oct 12, 2019

Indentation as a way to indicate blocks.

Copy and pasting code is a thing.

Copy and paste this code:

if foo:
x = y+foo
if x > 4:
foo =3

Was the original block:

if foo:
    x = y+foo
if x > 4:
    foo =3

OR?

if foo:
    x = y+foo
    if x > 4:
       foo =3

What happens if the editor 'helpfully' fixes things to one of those 2 choices? and it picks the wrong formatting. A big enough block of code, enough of a hurry and it will not be caught.

Refactoring: moving a block of code to a new method... on and on - a common operation now becomes a err-prone operation.

Keep in mind that the editor being used is not necessarily a IDE. It could be a word document that is being used to write a thesis. Every other language has { } or equivalent that allows the reader to correct bad formatting. Even bash(!) has if/fi and do/done delimiters, to allow recovery from a bad reformatting.

Someone in the python community needs to step up and have a path forward to allow for block boundaries to be marked without relying on white space

@jeffehobbs

This comment has been minimized.

Copy link

jeffehobbs commented Oct 12, 2019

This reads like a list of complaints about Django.

@edwardbeckett

This comment has been minimized.

Copy link

edwardbeckett commented Oct 13, 2019

I stopped learning Py as soon as I realized white space was part of the syntax.

@hecvd

This comment has been minimized.

Copy link

hecvd commented Oct 13, 2019

You can use tabs if you prefer, Ed.

@XVicarious

This comment has been minimized.

Copy link

XVicarious commented Oct 13, 2019

Try mathialo/bython.

@karnikamit

This comment has been minimized.

Copy link

karnikamit commented Oct 13, 2019

"I think your grievances with Python will dissolve with better understanding of Python itself. Expose yourself to Python beyond Django..."
+1

@girng

This comment has been minimized.

Copy link

girng commented Oct 13, 2019

Lol, I love how this is flagged on HN 🤣

@1oglop1

This comment has been minimized.

Copy link

1oglop1 commented Oct 13, 2019

but then its syntax turns everything into a mess

Now look at JavaScript where deprecation does not exist and you can define a function in 4 or more styles and each does something else.

@leoburgy

This comment has been minimized.

Copy link

leoburgy commented Oct 14, 2019

If you prefer not to use "superfluous" quotation marks in dictionary keys, you can also use the syntax dict(foo="bar").

@Aimage

This comment has been minimized.

Copy link

Aimage commented Oct 14, 2019

It's true that you have to remember too many variable in python. But look at this on JavaScript
x === undefined

VM4312:1 Uncaught ReferenceError: x is not defined
at :1:1

Finally what does mean undefined ?

@roniemartinez

This comment has been minimized.

Copy link

roniemartinez commented Oct 14, 2019

This is more like complaints because you have very different expectations. I've been into Perl, C++, Java, Javascript and it is only Python that made me stay longer (Senior Specialist). Of course I still do Javascript for client-side coz we have no other better choice for that.

@lxbarbosa

This comment has been minimized.

Copy link

lxbarbosa commented Oct 14, 2019

Nested parens is a good thing. Always! :D

@imneonizer

This comment has been minimized.

Copy link

imneonizer commented Oct 15, 2019

Seriously would you really like to have {{{{{}}}}}} these kinda confusing opening and closing..... Hell only for these reasons i quit java and c++, if you learned a bit about python then you know how to efficiently use white spaces, you just need a good editor unless you know how indentation works i can even write that into notepads.
Talking about list comprehension
Whats wrong in writing
foo = [x for x in numbers if numbers < 10]
Learn some basics bro, django is confusing i can understand use flask its much easier get a taste of it before complaining about it.

@ZuluPro

This comment has been minimized.

Copy link

ZuluPro commented Oct 15, 2019

Don' feed the troll ...

@glenfant

This comment has been minimized.

Copy link

glenfant commented Oct 15, 2019

I only agree with the last point (about pipfiles that are obscure to me too).
Seriously, the other points are either trolls or jokes, or mean you only learned the surface of Python (confusing attributes and dict keys, etc...)

@greypanda

This comment has been minimized.

Copy link

greypanda commented Oct 15, 2019

So you prefer requirements.txt over Pipfile? I was so happy to see pipenv that I had a book-burning.

@ghsolo1

This comment has been minimized.

Copy link

ghsolo1 commented Oct 16, 2019

This is a Click bite title. Here is my opinionated view of Python ;-)
Python is "the simple and the most powerful language" humans have invented in terms of Features and community behind it on the planet despite of not being the key language driving the internet. To complain about Python, one has to be either Guido or must be a decade user of Python. Though Python started as a one man's mind now it is the mind of humanity.

@rubik

This comment has been minimized.

Copy link

rubik commented Oct 16, 2019

Before complaining first learn Python to a minimal level. You clearly come from Javascript and it seems you have just skimmed the language. All the negative points you listed don't make any sense, except for the packaging one. That's still a bit messy on Python.

@RagAlMuffin

This comment has been minimized.

Copy link

RagAlMuffin commented Oct 16, 2019

Argh !! I was deceived, I thought it was an elaborate discussion on the limitations of Python. Instead, it is a list of complaints without any further explanation... I have been learning Python for more than ten years now and it is the only programming language I've remained with. So I was hoping this discussion would implicate different languages (C, C++, Perl, Ruby, Julia, Java, JS, etc..) with people confronting their view about an ideal programming language. As for me, I believe Python is the greatest language for all-rounders. I like how it is accessible yet allows to go far in possibilities. I believe the space/tab indent forces you to make the code readable just by peeking on it. I love how the comprehensions makes it both efficient and readable and I really like the f strings ! Of course, I would not recommend Python as a first choice if you want to design an OS, or if you are programming a CFD code or an android application but in the end, it's a great day-to-day language for many things.

@Aimage

This comment has been minimized.

Copy link

Aimage commented Oct 16, 2019

So we end up comparing languages to Python. Every languages is a tool and every tool has its own pros and cons.
As main pros for python I can say simplicity, readbility and cover many filed (web, desktop, embeded with micropython, ...)
As cons I can say performance compared to C or C++.
I don't think all you mention before are limations of python, they are python nature and how it does stuff. You have to deal with them if you want to build something with python.
It's like we want to live in china and need to speak chinese but we don't like their alphabet cause their is no latin character.

@juanfal

This comment has been minimized.

Copy link

juanfal commented Oct 16, 2019

Python has been my last language to learn. The hype about Python comes from the spaces other languages have left. Particularly Java and its verbose, inconsistency, old style and rigid syntax and strict OOP for everything. Ruby, being a much beautiful, consistent, and natural language has the absurd drawback of not being European or American and its support written in Japanese. That made its development (libraries included) much slower.

Last version of Python is concerned about := (as if it were something revolutionary!) but leaves its many absurdities without any perspective of solution.

@Antu7

This comment has been minimized.

Copy link

Antu7 commented Oct 19, 2019

Exactly Python is not a great programming language for trolling

@kissgyorgy

This comment has been minimized.

Copy link

kissgyorgy commented Oct 19, 2019

Half of this list is just simply stupid, half of it is nothing to do with Python itself (but the Python ecosystem), you don't know the difference between a dict and an object, so I suggest you don't use Python at all and don't write stupid things about it.

@greypanda

This comment has been minimized.

Copy link

greypanda commented Oct 19, 2019

You cannot get by today as a one-trick pony. If you do any embedded devices, you will need C/C++ ( Although MicroPython is promising. ). Javascript for browsers. ( I hate it, but love browser based apps. ) PHP to repair bad web apps that you don't want to re-write. ( I hate it, but wrote a lot of apps when it was the only thing around. ) Python to string it all together. ( Love, hate. ) Java is so convoluted I won't even touch it anymore; I had to learn Java to keep my job. Perl is just a memory, but I still see some diehards.

I consider myself fairly fluent in all of these languages but I use the ones that get the job done. I'm just experimenting with Rust and Go, but every language has the good and the bad. Just enjoy the challenge.

@abbyrjones72

This comment has been minimized.

Copy link

abbyrjones72 commented Oct 19, 2019

Languages are what you make with them, not the languages themselves.

@greypanda

This comment has been minimized.

Copy link

greypanda commented Oct 19, 2019

Languages are what you make with them, not the languages themselves.

Exactly. You can't expect to be a decent French speaker with one class in high-school French.

@Murithijoshua

This comment has been minimized.

Copy link

Murithijoshua commented Oct 20, 2019

well each language has its up and downs.We are deep diving into Agile software development,Instagram lies on Python backbones @abbyjones72 i second you.

@Endzel

This comment has been minimized.

Copy link

Endzel commented Oct 20, 2019

In my honest opinion, Python is just pushing the boundaries of abstraction for programming languages to the highest level. Readability comes at the cost of efficiency, where sometimes it does not matter enough. And in general, making things simpler is a really honest objective.

Of course it has downsides and you pretty much summed up a lot of them! Now, the ball is on our roof to work for the future developments in order to avoid this kind of mistakes as much as possible.

@nasoma

This comment has been minimized.

Copy link

nasoma commented Oct 21, 2019

Yet another example of a Javascript guy who wants Python to be Javascript.

@jakesyl

This comment has been minimized.

Copy link

jakesyl commented Oct 21, 2019

global interpreter lock is hell

@jreniel

This comment has been minimized.

Copy link

jreniel commented Oct 22, 2019

global interpreter lock is hell

I second this. The GIL and the implicit memory management are the two main things I'd vote to improve in Python, and ironically, neither is mentioned here. Other than this, I don't think some of the complaints listed here make much sense. It doesn't seem like the author really understand Python.

@sirjasongo

This comment has been minimized.

Copy link

sirjasongo commented Oct 22, 2019

PHP is still the best and straightforward way for web programming. I wished PHP was able to develop its statistical libraries and routines so that it will be easier to do inferential statistics, machine learning, etc. Python and R are very unexpressive when it comes to syntax. They just sound less natural like Pascal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.