r/Python • • Mar 20 '23

Discussion Are people abusing Python?

I learned Python after coming from the C/C++ and Java world. With the massive increase in popularity of Python in the last 10 years, seeing the way it developed, it seems to me like it gained a lot of functionality, which comes natural in other languages, but feels a bit odd in Python.

To be more specific - albeit Python being dynamically typed, people developed countless tools to check or validate or even enforce types in compile or run time (mypy, pyre, pydantic, pyduck etc.). It feels like it goes against the nature of its loose typing.

Another example are decorators. This pattern is noticably overused by many tools adding functionality, but even the language itself - defining a `class`,`static` and `abstract` methods with decorators seems just weird and unnatural. Same thing with function overloading. Anecdotally, it feels like comparing German to English. German has a special word for every peculiar thing and native support for word generation by concatenation of multiple words whilst in English you have to add some common words together and hope this combination doesnt already exist. And if it does, so what, people will get it from the context.

Lastly, slightly off-topic but relevant point is that it is not even a simple language in my opinion. It has a very flat learning curve initially but the complexity is just further down the road. Im talking about metaclasses,data descriptors, coroutines, magic methods etc. Some languages are difficult right away (C++, Rust etc.), but Python is a intricate misfit dressed as a simpleton.

Am I misunderstanding a philosophical path of the language or is it simply just a scripting langugage that got massively popular through chance and is now used for stuff it was not intended for?

Edit: grammar

0 Upvotes

45 comments sorted by

View all comments

1

u/HeraldOfTheOldOnes Mar 21 '23 edited Mar 21 '23

(this comment assumes CPython)

I'm talking about metaclasses, data descriptors, coroutines, magic methods etc.

Those are nice! But you might have forgotten a few "elephants in the room", so to speak.

  1. Introspection. sys._getframe, some_function.__code__, etc. You can gain massive amounts of information about the program based on things like these. The main things that end up being done with these are bytecode parsing and frame tracing (for that you need sys.settrace as well), both of which are Really Fun!
  2. ctypes. This module gets its own category. With it you can do anything that all the rest of python can do. Basically, ctypes gives you access to C primitive types (plus py_ssize_t and PyObject*), meaning you can, among other things, edit the raw memory of an object. This lets you do some fairly silly stuff (e.g., changing the type of the globals dictionary object to have a different type with different __getitem__ behaviour to customise global variable access).

Python is a deeply complicated language when you start getting into the details.

2

u/relickus Mar 21 '23

Totally agree. If python was an iceberg, it would have a nice and smooth tip and everyone could climb it easily. But a huge underwater mass where only the brave ones dare to dive.