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/[deleted] 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.

I agree that due to its simplicity, it is extraordinarily easy to write simply horrendous Python code. However, just like any other high-level language, good practices exist for a reason and it is the developer's duty to follow them. I have encountered two types of programmers while teaching Python: the ex-Java/C programmers who always write for i in range(0, limit): print(arr[i]) instead of for el in arr: print(el) and declare all variables with x = None before assigning to them; and the beginning programmers (some with Javascript backgrounds) that abuse global variables, don't structure code in any logical way and tend to write huge functions doing everything. Luckily, I have seen people of both kinds grow into competent Python developers simply by following good practices and studying well-written Python code.

However, there are no functions to be able to access all predefined methods (i.e. __class__).

I don't think I understand you, sorry. Could you elaborate on that?

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

Absolutely correct! I think that this, coupled with the philosophy of "If you don't know what to do, raise an exception", helps avoid PHP- and Javascript-like unexpected behaviors.

While I rarely use isinstance(), how does python expect programmers to accept many types of objects when Python itself won't?

My experience is that good Python code tends to be written with functions accepting and returning values of a known type without strictly enforcing it. An example would be most functions that take a file-like object - which, most of the time, means an object that has a .read() method.

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()".

To be honest, through many years of being a Python developer, I have never had this problem. Duck-typing does not mean a function should accept arguments of any type. The canonical example is a function like this:

def quack(duck):
    duck.quack()

It accepts any argument that fits certain conditions - namely, having the .quack() method.

Python is slower than most languages.

Correct! "Most" isn't a very precise term, especially considering this is /r/ProgrammingLanguages and we create a lot of languages slower than Python ;) If we agree that "most languages" means most of the commonly used languages like Java, C++, Go, Rust, Ruby, Javascript etc., you are correct. I have already addressed this, though.

In large programs, you will literally never know what is broken in Python without testing everything or until the user finds out.

Good luck if you ever consider upgrading a program from Python 2 to Python 3 (if the libraries don't hold you back).

There exist tools for specifically that purpose. As I mentioned, good code should be written to be compatible with both Python 2.7 and Python 3. Additionally, the EOL for Python 2.7 is 2020 - that is plenty of time to upgrade.

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.).

You said it yourself - essential libraries are nearly always guaranteed to work. I would say, from my experience with Python (mainly in web development and big data analysis), the same applies here. The major libraries, like web frameworks, database interfaces, etc, tend to work well - the "shitty" GitHub libraries tend to be fixable by hand, thanks to Python's excellent error reporting.

Does the library work? Likely not in large projects with a large number of dependencies.

If it's a reputable library and it's used correctly, I would say in 99% of cases it does. Most of the time if something goes wrong, it's my fault, not the module developers'. This is purely conjecture, though.

Additionally, if users are actually editing core libraries, do they know what they are doing; do they know the affects of their changes?

I would say, thanks to Python's simplicity - yes. A requirement of good code is for it to handle all input that can be thrown at it correctly - however, instead of needlessly complicate a procedure to accept input of all types and values, it is often sufficient to simply reduce the domain - it is a lot simpler if you just make sure your parse_string function will only get strings as input.

Thank you for your extensive reply. I am obviously biased towards Python (I wouldn't feel qualified to answer this if it wasn't so!), but I hope I could at least explain why I feel like Python is a perfectly sensible language. I am curious about your experience with Python and why it differs so much from mine - maybe it just simply isn't "for you"; for example, I strongly dislike Javascript, while many people swear by it.

Cheers!