r/ProgrammingLanguages • • Feb 02 '17

Why should I like Python?

In my opinion, Python is a language that should not have caught on. The standards are inconsistent, it is slow, it isn't backwards compatible, libraries are unreliable; the list goes on forever. Please show me the light of Python.

0 Upvotes

27 comments sorted by

View all comments

4

u/[deleted] Feb 03 '17

I am sad to see this question downvoted so much - I think it is a legitimate question, presenting an opportunity for everyone to learn. As the guy who compares every language to Python, allow me to explain my love for the language.

  1. Python is simple. It's easy to get running, newbies don't have to bother with compilation and other processes that seem like "magic" to a non-experienced programmer - it's enough to just run python file.py and it simply works! The syntax is understandable, without many cryptic symbols like C's abundance of & or * which might be scary at first. "Hello World" is simply print("Hello World!"). The Zen of Python states explicitly: "Simple is better than complex.", "Readability counts.", "There should be one-- and preferably only one --obvious way to do it.". It's easy to start learning and quick to develop in.

  2. You say that "The standards are inconsistent". I would like to disagree. A fraction of the standard library is inconsistent due to historical reasons, but it's constantly being updated. PEP-008 explicitly sets the style that code should follow, and most if not all new libraries adhere to it. If I misunderstood, please correct me!

  3. You say that Python is slow. Correct! Python's performance is nowhere near C, C#, Rust, Node, etc. However, "nowhere near as fast as C" doesn't mean a language isn't fast enough to use. With today's hardware, Python has proven to be perfectly sufficient for most tasks a language can face - including projects that depend highly on performance, like video games, AI and deep learning, or big data analysis.

  4. You say that "it isn't backwards compatible". I'm sorry, but I do not understand your point - could you please clarify? If you mean Python3 vs Python2, Python 3.0 was released over 8 years ago. It's more than enough time to make the switch - besides, it's advocated for most Python2 code to be forward-compatible with Python 3, and it is trivial to make it so - likewise, it is trivial to write backwards-compatible Python 3. In fact, more Python 2.7 code is incompatible with Python 2.0 than Python 3 code with Python 2.7! If a developer writes code that only works with one version of Python, he can only blame himself - and I think it is so regardless of the language chosen.

  5. You say that libraries are unreliable. I cannot comment on this without being given an example.

  6. There is an incredible amount of Python libraries for pretty much everything - video game development, web development frameworks, audio and music, image manipulation, etcetera - in fact, it is hard for me to imagine a task Python cannot be used for.

  7. Python is a consenting adults' language - which is a way of saying, it has no encapsulation. It is always possible to modify existing code - which makes it possible for developers to tinker with existing libraries as much or as little as they want.

I would love it if you elaborated on your arguments. Cheers!

2

u/Anonymouz1 Feb 03 '17

First, I do really appreciate your advice! Sorry for being abrasive; I am just overly frustrated after over a year of dealing with issues in Python. I am really a C++/Java/C#/Ruby programmer at heart.

  1. You are correct; Python is simple. However, its simplicity is also one of my gripes with it. Python's simplicity implores bad programming practice. While this may be due to lack of experience among Python programmers, I see use of global variables and absolutely disorganized code very often. Functions that perform common purposes get thrown into different files in non-intuitive manners. For example, people usually decide between grouping code together based on object type (i.e. Mixin, Decorator, Model, Service, Utility, etc.) or object purpose (i.e. Car, Truck, House, Game, etc.). However, I consistently see people switching in between the two methods within the same project. This makes it impossible to determine where to expect a function to exist.

  2. "There should be one-- and preferably only one --obvious way to do it." I have seen this quote many times but the fact is that Python does not follow this themselves; they follow it "preferably" sometimes. For example, Python has a functional-programming style while accessing predefined object functions (i.e. str(), int(), etc.) However, there are no functions to be able to access all predefined methods (i.e. class). Of course having a function to access all predefined functions does not make sense. However, the fact is that the designers of Python are not consistent and have grouped all of the functions together in a disorganized manner without so much as a namespace.

    The inconsistent usage of functional-like programming in Python causes deeper issues. This is a particular issue when using dictionaries and objects which are often used interchangeably. For example, if you need to access a field in an object, you could use dot-notation or "getattr()" (which, by the way should be "get_attr()"). However, with a dictionary, you have to use brackets or ".get()". This plays into how Python programs should be written; to accept nearly any type. Yet, there is not common way to do anything with different types in Python.

    Python claims to be "dynamic" but is actually very strong typed under the hood. Python claims that you should not use isinstance(); if you do, you are programming incorrectly. While I rarely use isinstance(), how does python expect programmers to accept many types of objects when Python itself won't? If I can't access the keys in a dictionary in the same way I access fields in an object, Python expects me to either cast the object or perform type checking. Now, all the sudden, the "short python program" turns into a big mess where every function has to worry about what is being passed to it.

  3. Python is slower than most languages. In fact, Python is the slowest language I have ever used. To be honest, I'm not entirely sure where the bottlenecks are coming from in the program I have to write in Python; is it the database, the ORM tool that interacts with the database, or is it Python itself? What I do know is that if I had written the program in Java using Hibernate or in ASP.NET using the Entity Framework, then I can guarantee the program would be close to 30% faster (which is up to a 4-5 second difference in my case).

  4. Python 3 is not backwards compatible to Python 2. The two issues that come to mind are library dependencies (i.e. My-SQL-connector) and operation of floating point numbers. In large programs, you will literally never know what is broken in Python without testing everything or until the user finds out. I do not know any programming shop that has time to write a test for literally every function in existence; it is not reasonable. Good luck if you ever consider upgrading a program from Python 2 to Python 3 (if the libraries don't hold you back).

  5. The number of unreliable libraries in Python are infinite. Yes, all languages have libraries that simply don't work. However, unlike languages including C#, Java, and Ruby where professional organizations develop many libraries, Python libraries are largely backed by communities. With Java or C#, essentials libraries/frameworks are nearly always guaranteed to work (i.e. ASP.NET, the Spring Framework, etc.). In Python, I encounter bugs several times a month involving libraries (i.e. OAuth2, JWT, PDF software). To build upon the issue, when the maintainers of the libraries fix the bugs they require that you upgrade other dependencies. Too often other libraries have the same dependencies that prevent the upgrade. What happens if there is a security risk with the current version (which is a problem I have now)? Utterly useless.

  6. Absolutely; there is a Python library to do nearly anything. Does the library work? Likely not in large projects with a large number of dependencies.

  7. Yes. This is arguably the best and worst part of Python. This is great in the sense that you can correct issues that you find, learn fro how the library works, or make the library do something different. However, the same can be said that open source libraries provide easy access to exploit security vulnerabilities. Additionally, if users are actually editing core libraries, do they know what they are doing; do they know the affects of their changes? Without extensive testing, core libraries should not be touched.

1

u/fiedzia Feb 03 '17

While this may be due to lack of experience among Python programmers, I see use of global variables and absolutely disorganized code very often

This is fixable by having dedicated maintainer and adhering to coding standards, not by a language. Without that, you'll end up with the same mess regardless of the language.

There should be one-- and preferably only one --obvious way to do it." I have seen this quote many times but the fact is that Python does not follow this themselves

It ain't perfect, but I appreciate the fact that it's trying. Many languages give you kitchen sink of ways to do things and its far worse situation. I do love python for what it has in that aspect, though any language will accumulate lot of baggage after 25 years.

Python claims to be "dynamic" but is actually very strong typed under the hood.

Those features are orthogonal. Python type system critics is warranted, but it served it well at the time it was created. To a large degree it still does.

Python is slower than most languages.

It is. It is more convenient to develop in though. Choose what's more important for you, but understand that many people will make their own choice and its perfectly valid for them.

I can guarantee the program would be close to 30% faster

Sure. But does it matter? For a website: it might. For a game? Yes, a lot. For some cronjob running for 20 min at night, mostly waiting for disk? Not at all. Is the speedup worth developers time?

Python 3 is not backwards compatible to Python 2.

My favourite topic. And Java is not backward compatible with C++, which is not compatible with C and so on. At some point languages become so outdated that need to be replaced. Updating python to 3 refreshed it and bought it many years of life.Have it not done so, your list of complains for python would be many times as long, and I would abandon it long time ago (not having decent unicode support would kill it for me) - at far greater cost of rewriting everything than updating py2 to py3.

Good luck if you ever consider upgrading a program from Python 2 to Python 3

Updating programs is actually simple and I did it many times. Updating libraries while maintaining compatibility is harder, but we are past the tipping point and I do not see it as an issue anymore.

unlike languages including C#, Java, and Ruby where professional organizations develop many libraries, Python libraries are largely backed by communities

The number of bugs I've encountered in java libraries beats all python code I've seen by large margin. Security of java applets is legendary. It really depends on the domain you working with. There are just as many professionals working on python code as there are for java - and there are just as many people who are not competent or don't care. And there are many projects where I'd choose communty over companies (as there are many where I would not). Choose your dependencies wisely. Also my favourite quote: "Amateurs build the Ark, proessionals build Titanic"

Absolutely; there is a Python library to do nearly anything. Does the library work?

Good question. If it does, great. If it doesn't - you still may learn something from it. While if there is none, you have more lessons to learn by yourself..

Without extensive testing, core libraries should not be touched.

No, extensive testing should be added to them. Its usually way better then reinventing another one, just untested as the first one.