On many forums, discussions between devs and several blogs, I saw a lots of articles in which Python is mentioned as a bad or ugly language; but why is it so?
I find Python awesome: building everything fast, easy to read and to learn the basis, etc.
But whenever I ask to my fellow developers, nobody gives me a constructive answer; so what is your opinion about it?
Happy coding !
Top comments (70)
Now try that in PHP 😂
Seems like programming languages are a lot like religions. And developers can become extremely religious. Whenever I read things like this, X is a bad language, Y is really ugly, I consider it to be a good thing. People only complain about the languages we use. If nobody complains about your language, nobody uses it.
As for the constructive answer, I don't know Python so I can't help you :D
It's like Stroustrup said: “There are only two kinds of languages: the ones people complain about and the ones nobody uses.”
I came upon this quote a few years ago, and this is my absolute favorite in the programming world. Perfection doesn’t exist. We developers make countless arbitrary choices in everything we do, therefore it’s absolutely impossible to please everyone.
Let’s just keep coding!!
Oh Stroustrup. I wrote him an email many years ago. I told Bjarne that a programming language which permits you to obfuscate absolutely anything is not a language. It's gibberish. Funny, I never got a reply :) I really was not trying to be rude. All I wanted to do was to point out that the purpose of language is to create mutually intelligible messages. C++ is a danger to that maxim. In twenty-five years of my involvement in software development, usually within a team, I have found nothing wastes more time and money than bucking convention.
True - the cure for that (like for the real thing) is learning about other languages, seeing your languages problems and realizing that there is no true language and that it's all a big hoax ;)
Ok, here we go (puts on fire-resistant coveralls) ...
For reasons that no one understands, all of the sudden python acquired this
enormous library structure which allowed people to say "I'll make a thing
that does this, that or the other thing" and they found all the stuff that
they wanted, in particular they could make a robot move around.
Python is an extraordinarily successful language, especially for one created as a hobby project named after sketch-comedy with a design philosophy that is a nineteen line poem.
Python got the holy grail (pun intended) early on - a big set of reusable and well-maintained libraries that you can just grab off the shelf and save yourself thousands of lines of code reinventing the wheel. Its better than a great static type system, better than automated testing, better than object-oriented, functional, or any paradigm one can imagine. With a few great libraries that you can actually use, your massive complex project might just reduce to a 50 line script.
I don't claim to know why python is so enormously successful. I really like python, and I could speculate on some of the properties of modules as a basic unit of encapsulation, iteration and other basic protocols, and so on. But at the end of the day I don't fully understand why, and neither does Gerald Sussman.
This lack of understanding is frustrating to the idea of software engineering. I think that much of the field would like to believe that we can enumerate - at least in part - what properties a language should have in order to result in rapidly developed software which is reusable and maintainable by teams of human beings. Python is missing one of the big ideas here, which is a strong static type system. If that is so important, then how is python so successful? How are teams writing python not drowning in uncaught type errors? How are there so many good libraries available?
There are two major differences between software engineering and traditional engineering fields:
First, software engineering is generally not a regulated profession - at all. There are no standard proficiency tests, degree requirements, or even a truly agreed upon curriculum.
Second, there is no basic theory or set of equations to tell you if a given design will result in a software that is successful in the sense that it can be delivered on time and maintained with a reasonable level of effort by a team of humans. Electrical engineers can use Maxwell's Equations and derived formulas to state clearly and definitively if a given design will generally work. Civil engineers have Newtonian Mechanics. Aerospace Engineers can rely on various approximations of the Navier-Stokes Equation. I would argue that software engineering does not have, and may not ever have, some sort of equivalent set of laws to tell you how successful a project will really be. It's fundamentally a harder problem as it involves human behavior.
So python, with its arguably haphazard success, serves as a reminder of the inherent difficulty in determining a working and general theory of what properties are required to make a software development project a success.
TLDR - python lacks many language features considered by many to result in successful software projects, static typing being a major example. While this may make the language unsuitable for some teams of humans, a great many teams of humans have found success using the language and built a huge ecosystem of usable libraries. There is no commonly agreed upon theory of why this has happened. That's kinda frustrating.
Really liked your comment ! I actually have one thing that deeply troubles me with python, from my stubborn must-do-anything(like must prove this theorem kind-of-stuff...) : well, trying to do something really scientific in python without Numpy is slow, and it just seems so nice to actually WRITE those things and see they work then just say: Hi, give me that! But not everyone is into this all I-want-to-prove that the fundamental theorem of calculus actually is real thing :-) . Interested how do you think I'll be able to reconcile with python? maybe try to write python like Rust?(even possible)
Teams of humans, as opposed to... teams of ducks?
Python was the first language I learnt, and the first I could consider myself any kind of expert in. I love that it has clearly stated design goals, and that one of them is being readable. The dynamic typing definitely makes it faster to get stuff going, which I think can be crucial for new programmers -- getting that reward for your coding is so important for it to be enjoyable. Other languages can make it feel a lot harder to even get something simple working.
That said, the more I program in languages with static typing and powerful type systems (like Rust), the more appreciation I have for how many bugs can be completely eliminated by these languages. I hate that in Python there is always a possibility that everything will crash because a variable of the wrong type gets passed into a function, and there's no way to guarantee this won't happen. Good test coverage reduces the likelihood of this kind of bug, but it's frustrating to have to write tests for things that other languages simply do not allow -- it's a lot more work for me, and will never have the same guarantees a compiler can give me.
I think that people can be unkind when comparing programming languages, often simply to make themselves look smarter. Try not to let these people bother you :)
If you want to know more about different type systems, I recommend Destroy All Software's article here :) destroyallsoftware.com/compendium/... It does a nice balanced job of explaining and comparing different approaches, including Python's.
I hear what you're saying about the dynamic (or, weak) typing. But I've always believed that weakly typed languages are a bad choice for beginners -- for exactly the reasons you've been learning to appreciate stronger typing. Weak typing might lead to more instantly gratifying accomplishments in the beginning, but as the beginner's software grows into something more complex, already established bad type-ing habits lead to some of the more difficult to debug errors rooted in the subtleties of weak typing. As you've pointed out, strong typing removes that ambiguity, leading to clearer code. It might be more verbose at times, and also less tricky and impressive. But when it comes to the actual computing that happens down under, there's really no difference. And when someone else takes on the maintenance of that code, the one thing their going to want is straightforward, obvious code. Cool, trick, obfuscated solutions waste time and money.
Like I've been saying in this thread, Python is good for what it's good for. As for pedagogy, especially for those who wish to be industrial software developers, I don't think Python is it. I believe schools who start out with Python do so because it's the in thing right now.
I think it's really interesting to think about what is a good programming language for people to start with. It's something I have conflicted feelings about.
I think you might be right that Python is not a good first-language choice for people who want to be professional software developers. But I also think that software should be open to more people than that.
I think it's difficult to balance the advantages of learning things "right" the first time, and the concern that people might not learn anything at all if the content feels inaccessible. I worry about people picking up bad habits/not ever learning what is going on under the hood of their Python program, but I worry even more about people giving up on learning to program altogether.
Perhaps the answer is better teaching approaches & materials for languages that are considered more difficult to learn. Perhaps our entire approach for teaching programming needs updated so that the chosen language is less of a big deal. I don't know.
I think you may be right that some schools start out with Python because it's trendy, but perhaps there's a reason for that trendiness. It's definitely more accessible than, say, Haskell.
Hi Jason! I think I agree with you that Python is not a good language to start with. But what is your suggestion for a starting language?
Actually I've seen that Oxford starts with Haskell, which I think is pretty unique. I can tell you I mostly see either Python or Java for starting choice! Usually after covering Python and Java there is gonna be some short C/C++ just to ensure everyone is on the same page.
I tried experimenting with Julia(incredibly easy to math your way to a result), Go and Rust and there was something satisfying about those(I'll say how easy it's gonna be Julia-->Go-->Rust or Julia-->Rust-->Go)
Python is good for what it's good for. For the rest, I code an extension in the appropriate language for the task and call it from python :)
Great post!
Python 3.5+ supports type hints, but that's only for your linter (and other static code analyzers) versus not having it compile.
It's a step! =)
And unit tests. Unit tests contribute much more to reliability than type checking.
Atleast treating white space (indent) as a language structure always seems to me odd.
The combination of braces to implement structure while using indentation to visually convey structure seems odd to me. Seems like a violation of the DRY principle.
Python removes that redundancy by using indentation for both, that way visual structure is always consistent with actual structure.
Whereas many other languages are redundant in that respect, which does not respect the DRY principle.
Wait, did I already say that?
How often does wrong type bite you though? Many strongly typed languages allow passing null as any type anyway and I find that a far bigger problem than passing foo when a bar is required.
Programming language hate is often pretty shallow. Python lacks where other languages thrive (like strong typing/compiler) but makes up for it by being simpler to use and read in a lot of cases. It's also widely adopted in many important fields which is a big deal regardless of language bike-shedding.
Some languages also receive a lot of hate from their own community and a lot of that is just venting. People keep chugging along with these tools because they're ultimately useful.
If you find Python awesome, keep up whatever you're doing with it and don't pay much attention to the critics. If you're still curious about the criticisms, try picking up something really different and see if you like those too for different reasons.
Python's simple syntax make it the best scripting language.
SCRIPTING.
Automation, and small things that should just make life more pleasant. Any attempt of using it to something bigger than that, was met with NO redeeming qualities once or ever.
Problems with dependencies; the lack of type hinting (since the bastards broke backwards compatibllity BEFORE they added type-hinting, the single most important feature in Python 3) makes Python an unreliable, bug-prone, confusing piece of mess (again, solved in Python 3 the issue with the type-hinting, but since we have legacy Python 2, people refuse to upgrade).
After EVERY Python project we have ever done, our primary lesson is: do in Java next time.
Python 3 on the other hand, has the potential of actually being scaleable.
I mean, the mess that is pip is still there, but type hinting is, again, the single most important feature of Python if you ask me.
My negative view of the language comes from terrible experience of people using it as the an actual language, for actual projects. It doesn't feel like it was ever intented to - but people know Python and are lazy to learn any statically typed language, which annoyes me to no end.
But if used correctly - Python (Python 3 to be more specific) is an important and useful tool at you disposal.
From my perspective, I'd rather code in a language such as Python instead of a language with an unsound type system. I've got some side projects in Rust and Scala but I don't know if I will ever find a job in these languages.
Examples for languages with an unsound type system?
Java and Typescript.
What's unsound about them?
My only complaint about Java is the nullable reference types, really, and I have no complaints at all with typescript (but to be fair I didn't use it all that much). Why do you dislike them?
Wow, the more I read this site the more I want to take on the Java evangelist role. Haven't come across a single advocate, only hate.
I like Java! I really do. I certainly like it more (god, so much more) than Python
I'm not "hating" on the language, I've just stated my preference of python over it because of its type system.
I remember when I was learning Java that I had to use upcasting (some of the nio apis, etc). Whats the point of a type system if you're upcasting?
@aghost7 you are absolutely right, I have just noticed a general lack of enthusiasm and happened to mention in reply to your comment, which was not hateful. I apologize.
For upcasting do you mean implicit upcasting? We typically do that in order to "program to an interface" which helps facilitate a clear separation between the implementation of a module and how it interacts with other modules (ie loose coupling).
Sorry, I think I meant downcasting. I've had to use this on several occasions when I was writing Java. I think the worst I've encountered in the standard library is casting object to something else.
Hmm, yeah usually you want to avoid downcasting at all costs (most Java devs consider it a code smell). Java is certainly far from perfect but Java 8 and 9 make it muuuuch nicer to work with (especially if you like Scala).
If you're referring to streams I'm afraid that there's still some catching up to do (based on the last time I looked at it) when compared to Rust or Scala.
Streams, Optionals, Futures, Method References, and Lambdas everywhere are all great additions but it definitely lags behind Scala in some ways (never tried Rust).
Bad programs can be written in any language; Python's flexibility means you need to be more disciplined than in a statically typed language like Java. I've worked on Java teams before that would be nightmares if they were using Python.
That said, if your team's testing, craft, and review discipline are solid, Python is just fine for projects large and small. Similarly, overall design and architecture outweigh a language's straight-line efficiency for most classes of projects.
I've been using Python as an actual language on actual projects for years without any nightmares.
"the mess that is pip" - I'd be interested in more details there. Java is no stranger to dependency hell either, particularly in the world of EE.
I do agree that the migration to Python 3 was completely mishandled. I think things are finally getting there (Django 2 refusing to run on 2.x is a huge step) but wow, what a way to drag things out.
You are correct. A lot of bad software is written in any language.
And yes - with great discipline, great software can be written with Python.
But why even try when there's no real benefit? The language is still very slow when compared to any compiled statically typed language.
I called pip a mess but I admit it was uncalled for. Pip is fine.
What I generally dislike is the way Python handles libraries in general - with them being global and all. It creates mess, with one project requiring 1 version of a library and another project another - what do you do?
The libraries are global, and it affects ALL of your projects at once.
Another problem is that should I create a Python project and want to release it on production, I need to NOT ONLY install Python, but pip with every dependency as well, at a global scope.
With Java - I can compile the my project to include the libraries I use. I need only the JRE on production, and I'm golden :D
For the very least - I despise Python on a project level. A lot of things can go horribly wrong, and a great level of discipline is required to make the most out of it.
I work at place where people use Python only because they needed to get things done QUICK.
They didn't have discipline.
And I'm the one that suffers all of their horrible, horrible choices.
So yeah, more often than not I'm more scarred fron the misuse of Python than anything else.
Java + Gradle (or any of the major build tools) = 😍😍😍😍😍
"But why even try when there's no real benefit? The language is still very slow when compared to any compiled statically typed language."
Because straight-line execution performance is, for most applications, far less important than architecture and team productivity. For a web site, caching, CDNs, and concurrent processing will take you much further than your language choice will (within reason: don't write your web site using DOS batch, please). Python is Fast Enough. And when it isn't, it's very good at calling your favorite compiled code for performance sensitive pieces.
Additionally, it can be far more productive than a language like straight Java.
"What I generally dislike is the way Python handles libraries in general - with them being global and all. It creates mess, with one project requiring 1 version of a library and another project another - what do you do?
The libraries are global, and it affects ALL of your projects at once."
You use virtualenv, as it is the tool that was created specifically to address project-specific libraries. Global libraries are a solved problem.
"Another problem is that should I create a Python project and want to release it on production, I need to NOT ONLY install Python, but pip with every dependency as well, at a global scope.
With Java - I can compile the my project to include the libraries I use. I need only the JRE on production, and I'm golden :D"
As above, no, you do not need to install these at global scope. In fact, you can run different versions of Python with different projects in the same scope as well. J2EE can have more of a problem with global system libraries (remember log4j vs. commons logging in Tomcat?) than does Python.
"For the very least - I despise Python on a project level. A lot of things can go horribly wrong, and a great level of discipline is required to make the most out of it."
Great discipline is required with every language to make the most out of it. Python is no different here.
"I work at place where people use Python only because they needed to get things done QUICK."
Yes, that is a very real benefit of Python.
"They didn't have discipline.
And I'm the one that suffers all of their horrible, horrible choices.
So yeah, more often than not I'm more scarred fron the misuse of Python than anything else."
This again is not a Python problem, it's a management and team problem.
Pyenv + pipx + pipenv for all projects.
I learned BASIC, then Fortran, then Pascal, then C. Then I took my first programming language classes and also learned the rudiments of Lisp, ML and Prolog. My first job was mostly coding in C, and Perl. Then I learned Java. Heaven had come down to Earth. Strongly typed, elegantly laid out, (fiercely) object oriented. It was software development in a world built by George Orwell! Ah the peace and serenity of a highly structured life with heavy-handed enforcement ... but it was sort of compiled, sort of not. Development was slow on those old Celeron processors. I put up with it for a long time. And then I saw PHP... sigh. Fast, loose, messy. But development was rapid. PHP 5 came and OO took stronger hold and Symfony came out. As long as I was disciplined I could pretend I was coding in Java and deploy to test systems faster than you can type "git push" (or was that "svn commit"?).
Somewhere in that timeline Python came out and every time I looked at it, I wanted to read the philosophy behind it because it looked like such a step backward. It reminded me of Fortran in a number of ways. And when I read the original Python author's ideas of how and why, I was even more put off. So many changes with no good reason except for, essentially, wanting to not follow the course of history. I like following convention because, when shit just works you save money, time and headaches. It's when it doesn't work, or something is proven to work better, you spend the time and money making the jump.
So why do I use Python? I hate coding in it, but there's no denying that compared to any other scripting language (I've encountered) it just works. It connects to devices and networks and databases with the least hassle. Easier than Java and PHP (and of course Perl) in this regard. It's ugly. It's not easy to absorb another's Python work. But It. Just. Works. That's time and money. That means more time for everything else I was supposed to have gotten done yesterday.
There are mostly 2 things I don't like about 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):
This line is kinda okay actually and the most "normal". By looking at the rest of the snippet we can see thatdef
is used to define a function, it's going to be calledfib
, and it takes a parametern
. (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 assignsa
to0
andb
to1
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:
thea < n
should be inside parentheses but that's more of a pet peeve I guess, so you do you, pythonprint(a, end=' ')
is an alias forprint(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 is0 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:
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.
I see this is a very old post, but I got here from Google and I have a few criticisms of Python that aren't already here.
I come from a Common Lisp background, and I've spent the past year programming in Ruby. This means I will not be complaining about Python's lack of static typing like most other respondents.
Recently I've been pushed into Python development because the rest of my team adopted it because of a single library that is marginally better than what we had in Ruby.
I find Python to be absolutely awful. First of all, it is NOT easy to read. Programs that would be simple in Ruby (and even simpler in Lisp) turn into mangled nests of for loops in the blink of an eye, because in Python absolutely EVERYTHING has to be written out by hand as for loops. Reading Python code is hard work.
Python has list comprehensions, like Haskell, but I've found that unless the expressions in the list comprehension are completely trivial, using them leads to even less-readable code than if you just wrote a for-loop that does a bunch of appends to a list (or lists) you initialize before entering the loop.
In Ruby and Lisp, you can do a lot by combining functions like "map", "reduce", and "select" (or its Lisp equivalent, "remove-if-not"), and the code stays readable, even if the lambdas/blocks being passed to each of them have several lines of code each.
Python has equivalents to map, reduce, and select, but the language only provides these crippled one-line lambdas (also, no closures), so you end up writing hard-to-read nests of for loops instead. Or worse, somebody throws in a generator! Or you can split the code up into 50 separate functions, but that still doesn't give you the readability you would have had for free in Ruby or Lisp.
So far, I haven't gotten deep enough into Python to have to think about what I'd do in a situation where my Ruby/Lisp solution would involve closures stored in data structures. But I have seen what I end up doing to compensate for the lack of symbols: I create empty classes just so I can use the name as a value.
Python is supposedly a "batteries included" language, but every time I Google for a Python equivalent to a Ruby method that I use all the time, the Stack Overflow answer is always "Just write out the implementation inline, bro!" That implementation always includes a for loop or an even less readable list comprehension.
Example: stackoverflow.com/questions/952914...
I haven't written this many for-loops since my BASIC days.
I don't know a line of Python. But I have been using undergraduate students---hundreds of undergraduates--to write research analysis code for me since 2013. Most of them are pretty darn good---I have high standards for entry into my research class.
Most of them have learned Python because that's what our university teaches as a first programming language.
So, you ask, how can I hate Python if I don't know how to write a single line of it?
Because pretty much every python program ever written by any of my students either doesn't work on another machine in the same cluster that's supposed to be configured identically, or stops working on the VERY SAME machine within a few months when some minor version number changes. Really, people. Does it really matter whether I'm using Python 3.6.4 or 3.6.5? REALLY? The third digit in the version number changes, and the code stops working?
I've been told by the local experts, "oh, it's easy to write portable code in Python". They must be using some alien definition of "easy" that's not found in the dictionary, because this is a recurring problem. Every quarter, every time I try to re-run some code that was written more than a few months ago, it fails. Traceback errors, missing library errors...
This is completely unacceptable. I have written code in 1991 that still runs. (In C. And Bourne Shell. And awk, if you must know.) Now I'm not trying to say that C or Bourne Shell or awk or f77 are better....but I'm saying that if students in their 3rd or 4th year of a Computer Science program at a decent university still can't figure out how to write code that lasts longer than a month... there is something seriously wrong.
My only saving grace is that I continue to recruit new undergrads every year, and they are able to "fix" the code.... that quarter. But pretty much guaranteed it'll die again.
This is why I hate Python. In fact, it is rare that I speak of the language without the F-word---usually in ALL CAPS---as a prefix. All my students know I hate Python, but I continue to let them use it because if I want them to do work with me, I have no choice.
Is it easy to learn? Probably. Easy to master? Clearly not. Easy to maintain? HELL NO. (Less politely... give me a f*cking break, no friggin' way.)
That's my 5 years of experience.
End of rant.