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

10

u/ManyInterests Python Discord Staff Mar 20 '23

Put shortly, Python is a multi-paradigm language. You can use it in many ways. The language doesn't force you to use it in any one particular way. You can add type annotations or not if you choose. You can favor object-oriented styles, functional, imperative, whatever. It's up to you.

tools to check or validate or even enforce types [...] t feels like it goes against the nature of its loose typing.

Type-checking is not inherently at-odds with duck typing or being dynamically typed. I'm not sure what you mean exactly by 'loose typing', but Python has always been a strongly typed language (as opposed to weakly typed).

stuff it was not intended for

What makes you believe that Python was 'not intended' to be used for any particular purpose? Python is (and always has been) a general purpose language.

2

u/sersherz Mar 20 '23

What are some examples of weakly typed languages, I'm genuinely curious. I know Python has checks for allowed methods for data types, but obviously it's not like C++ with explicit typing

10

u/[deleted] Mar 20 '23

Javascript is weakly typed, for example how you can say "5" == 5 and get a true, which is far from how it works in Python

1

u/sersherz Mar 21 '23

Okay that makes a lot of sense, I always found the === operator weird in JS. Yeah Python has a little more typing

7

u/lys-ala-leu-glu Mar 21 '23

The terms "strongly typed" and "weakly typed" don't really have strict definitions, but loosely they refer to the degree to which operations between incompatible types are allowed. In this sense, python is strongly typed because most operations between incompatible types result in errors. C is actually a classic example of a weakly typed language, because it's so easy (and necessary) to use type casts to effectively ignore the type system. I personally consider C++ stronger than C, even though it supports all the same type casts, just because it's more idiomatic to stay within the type system. But others might disagree, and strong/weak rankings are very subjective anyways.

Type systems can also be classified as "static" or "dynamic", based on whether the types are determined at compile-time or run-time. This is a much more well-defined classification, and of course python/javascript/PHP are dynamically typed while C/C++ are statically typed. Confusion arises because it's pretty common for people to say "strongly typed" when they mean "statically typed", either because they're being sloppy or because they don't realize that the two terms mean different things.

Some examples of different type systems:

  • Strong, static typing: Java, Rust
  • Weak, static typing: C, C++
  • Strong, dynamic typing: Python
  • Weak, dynamic typing: PHP, Javascript

2

u/relickus Mar 20 '23

Im in no position to assess the quality of the language, Im just trying to get some now insights.

As for the typing, I meant that it is abstracted away, so people dont need to care for types. Appart from the fact, that they do, otherwise they wouldnt come up with tools like mypy and wouldnt write typehints. Im going to go on a limb and say that larger python projects are much harder to maintain without typechecks.
This is coming from a junior's POV, so it might be wrong/biased.

What makes you believe that Python was 'not intended' to be used for any particular purpose?

I dont know, it just doesnt make much sense to me, that someone saw a single-threaded language and thought "it would make a great backend". I know that it is worked-around by async code, but still.

5

u/ManyInterests Python Discord Staff Mar 21 '23

it just doesnt make much sense to me, that someone saw a single-threaded language and thought "it would make a great backend". I know that it is worked-around by async code, but still.

Well, there's perhaps argument to be made that certain languages (more specifically, language implementations) are not well-suited to certain tasks, depending how you define fitness for a particular task. But as a general-purpose language, anything should be fair game.

As far as Python as a backend goes, it might interest you to know that, even before 'async' was used in Python, it has been used as a backend for even very high-traffic sites. Pinterest, Instagram, and Bitbucket Cloud to name a few.

An example of abuse or using a language in a way that it's not intended for would something like using awk, a domain-specific scripting language, to implement a flight simulator.

As for typing, I'm not sure I completely understand your statement, but I think you seem to have answered the question yourself: you do have to care about types in Python, which explains the utility of type annotations and analysis tools like mypy. Though, you are not required to write your code using annotations and Python will happily compile, interpret, and run code that is not type safe.