this post was submitted on 26 Feb 2024
8 points (62.5% liked)

Unpopular Opinion

6317 readers
5 users here now

Welcome to the Unpopular Opinion community!


How voting works:

Vote the opposite of the norm.


If you agree that the opinion is unpopular give it an arrow up. If it's something that's widely accepted, give it an arrow down.



Guidelines:

Tag your post, if possible (not required)


  • If your post is a "General" unpopular opinion, start the subject with [GENERAL].
  • If it is a Lemmy-specific unpopular opinion, start it with [LEMMY].


Rules:

1. NO POLITICS


Politics is everywhere. Let's make this about [general] and [lemmy] - specific topics, and keep politics out of it.


2. Be civil.


Disagreements happen, but that doesn’t provide the right to personally attack others. No racism/sexism/bigotry. Please also refrain from gatekeeping others' opinions.


3. No bots, spam or self-promotion.


Only approved bots, which follow the guidelines for bots set by the instance, are allowed.


4. Shitposts and memes are allowed but...


Only until they prove to be a problem. They can and will be removed at moderator discretion.


5. No trolling.


This shouldn't need an explanation. If your post or comment is made just to get a rise with no real value, it will be removed. You do this too often, you will get a vacation to touch grass, away from this community for 1 or more days. Repeat offenses will result in a perma-ban.



Instance-wide rules always apply. https://legal.lemmy.world/tos/

founded 1 year ago
MODERATORS
 

Python is the most popular programming language and beloved by many. However I can't understand why (this is still the case in 2024).

Here are my main gripes with it:

  • It is slow, performance intensive tasks have to be offloaded to other languages, which makes it complicated to analyse. Moreover I wonder how many kwH could have been saved if programms were written in more performant languages. (and there are better alternatives out there)
  • The missing type system makes it easy to make errors, and the missing compiler makes it hard to catch them
  • It has no linear algebra built in, so you always have to convert things to numpy arrays, which is quite annoying
  • Managing virtual environments and pip packages feels overly complicated

I guess much comes down to personal, but I just can't understand the love for python.

all 20 comments
sorted by: hot top controversial new old
[–] Bougie_Birdie@lemmy.blahaj.zone 5 points 8 months ago (1 children)

I'm a software developer who primarily uses Python in my day job. I'm a strong believer that every tool, especially in software, has pros and cons baked into it.

It seems that many of your issues with the language come down to it being an interpreted language, as opposed to a compiled language. Interpreted languages are definitely slower than compiled languages at runtime, but something to consider is also development time. In my experience, a high level scripting language with dynamic typing like Python is easy and fast to write. I spend more time actively writing code than running it, so development speed definitely has appeal to me.

As to if performance-critical operations need to be written in other languages, I have a little experience with Cython, and I'd say that you're right - it is more complicated to analyze. However, and I don't remember where I picked this up, but I'm a strong believer that premature optimization is the root of unreadability in software. Programmers often believe that a portion of their program is going to be slow and then attempt to optimize it without ever having profiled to see if it's actually that slow.

Python does have a couple of tools to speed things along for common issues. For instance, list/dictionary comprehension saves on looping time, and using generators can help you control memory usage. Neither truly gives you thee speed of a compiled language, but these are noticeable improvements you can make.

Regarding the missing type system, there is built in type-hinting you can use which makes your code more closely resemble a statically typed language while still having the flexibility of dynamic typing. The type hinting is optional, which means that in most tutorials or when people are starting out, type hints will probably be absent. However, for enterprise grade software you can take the time to configure a linter to enforce type hints, and I would say it does make your code cleaner and easier to reason around.

As far as managing virtual environments, I think you're right on the money there. When I was learning, I found the process confusing, but it becomes more familiar over time. I've definitely polluted my global python installation with dependencies that break other projects, and it can be pretty gross trying to sort out the issues.

Okay, now here's something that I think is pretty interesting: every one of your main gripes are issues that people also have with Javascript. And that makes sense, there are parallels. They're both interpreted, dynamically typed languages which people try to use for every problem under the sun. I'd hazard that your issue is that you're more aligned with compiled, statically typed languages, and there's nothing wrong with that.

I think that one of the things that Python and Javascript both have going for them is the ubiquity that they're used. You can find a pip/npm package for any situation. People start learning one or the other because they hear it's a good language to get started in, and because you can solve every problem with it, you don't have to learn another language if you don't want to. That does mean that people are trying to solve every problem with one tool, and that has problems, but I guess we've decided that the pros outweigh the cons.

Moreover I wonder how many kwH could have been saved if programms were written in more performant languages. (and there are better alternatives out there)

I just want to say this is an interesting point, and there has been some study into Green Coding and it does definitely seem like we could use our resources more efficiently. However, the insidious side of coding for business is that the demands of business seems to be focused on delivering products quickly at any cost. Even though the science suggests that green coding has positive climate benefits and reduces operating costs, these benefits are intangible to executives and therefore ignored.

When I was in school, we learned about Moore's Law which essentially says that computers get faster all the time. In fact, computation speeds tended to increase exponentially, and that has implications on how we write code. Forty years ago, you'd be worried about not using more than eight characters for a variable name because of the implication that has for system memory. Now we don't worry about those problems, which means that we import more libraries, use more memory, and are less careful about squeezing every last bit of performance out of our machines. It sort of leads to this paradox where we have faster computers, so we write slower programs, which necessitate faster computers.

Does that mean our code nowadays is a lower quality? I suppose that depends on how you measure quality. For me, readability and maintainability are the most important tenets of writing good code. However, I can't deny that performance and system usage are important requirements. But optimization often comes at the expense of readability or maintenance (see your concern about using outside languages for performance intensive tasks), so you have to be judicious about how you apply it.

Finally, I think the ultimate reason that people like using Python is that it's simple to get started, and there are already libraries / solutions to common problems which are easy to find at a cursory search. Basically, the tool is popular because it's already popular, so people keep building more tools for it. And sure, there can be better tools that are under development which might one day supersede Python. But for now, the library support in Python is awesome, so there's little incentive to switch and lose features.

[–] scharf_2x40@lemmy.world 2 points 8 months ago* (last edited 8 months ago)

I found this, which dives deeper into the impact of inefficient software.

https://eco.kde.org/handbook/#look-to-the-software

[–] NegativeLookBehind@lemmy.world 4 points 8 months ago (2 children)

What do you suggest as alternatives?

[–] scharf_2x40@lemmy.world 2 points 8 months ago (1 children)

I mean others don't seem to have the same problem with Python as me, so if it is right for them, I can't really complain, but I would use the following languages for the following tasks

Scientific Computing (my main area): I prefer Julia, it is faster, feels more intuitive and feels like a modern python for scientific computing

Web: there are many great frameworks out there, i am intrigued by phoenix for elixir

Game Developement: Nobody use python in games to distribute for anything heavy I hope, but for scripting I would use Lua

Learning: Python is often the first language, that people learn, and I guess that also explains it's widespread use to some degree. I would teach something less high-level like C as a first language, although I think writing "high-level code" also has a learning curve to it.

Scripting: Fine, I guess python is great for small scripts, although one could also use Ruby

[–] morrowind@lemmy.ml 1 points 8 months ago

lua imo is better for both learning and scripting, primarily due to being a very simple language

[–] TheOneCurly@lemm.ee 2 points 8 months ago (1 children)

I'm not a huge python fan but I'm pretty confused about point 3. What alternative languages have decent linear algebra support built in?

[–] scharf_2x40@lemmy.world 5 points 8 months ago (1 children)

Julia, R, Matlab, Mathematica and Fortran.

[–] ptz@dubvee.org 5 points 8 months ago (2 children)

Sounds like you're just using the wrong tool for the job, then.

It's like you're trying to drive a screw in with a hammer.

[–] scharf_2x40@lemmy.world 2 points 8 months ago (1 children)

No I mean, Python is definitely the most used language in scientific computing, but yeah, I would use something else if I could.

[–] XTL@sopuli.xyz 1 points 8 months ago* (last edited 8 months ago) (1 children)

Why would it be better or important in any way to have that be a "language feature" instead of a library?

If it can be a library, it's obviously not something that needs to be a part of the language. Most uses have absolutely no need for linear algebra. Why drag on useless baggage and bloat?

[–] scharf_2x40@lemmy.world 2 points 8 months ago

Yeah that point was not entirely accurate. What I meant was, that a np.array and a list don't work together. Coming from julia and matlab it just does not make sense to me, why I can't use a function written for a list for a np.array even if they basically represent the exaxt same thing.

Julia for example hast linalg as a module but functions work on lists with no problem.

[–] remotelove@lemmy.ca 2 points 8 months ago* (last edited 8 months ago)

Not only can you sometimes drive a normal wood screw with a hammer, they also make hammer drive screws. And nails that screw....

Also, every tool is also a hammer.

(Sorry. I had to pick a little bit of fun at that analogy.)

[–] CaptainBasculin@lemmy.ml 2 points 8 months ago

Programming languages are typically chosen based on what is needed. All of them have some features and lack some of them per their nature.

If I'm working on a small script that needs to interact with various different objects and doesn't need to be optimised; I'll use Python to write it.

[–] toasteecup@lemmy.world 1 points 8 months ago (1 children)
[–] scharf_2x40@lemmy.world 2 points 8 months ago (1 children)

Yeah, ofc every language must have a type system, the problem is, that this is not enforced. I.e 3 == '3' throws no error, when working with dataframes for example this can be a pain in the ass. But yeah, I don't say that nobody should use Python (although the title is a bit dramatic) I just think that there are better alternatives out there.

[–] toasteecup@lemmy.world 2 points 8 months ago (2 children)

It's not enforced because python like a number of other languages isn't a strictly typed language. That decision was made by the creator of python and has been continued to this day, it wasn't a part of their vision for python.

I would suggest you consider using a different language since you obviously don't care for python based on that complaints you've used that mirror complaints from every other person who "just doesn't see the use of python".

Protip: I'm willing to bet that if your code is slow, it needs some refactoring. That or you could consider compiling your python into C code.

[–] scharf_2x40@lemmy.world 2 points 8 months ago

Python is strongly typed, but dynamically checked. Working with other languages I just found, that the type errors in python are the hardest to catch and to debug, but maybe I am just more used to othet languages

I see it's use as language to write small scripts, I just don't see much use besides that.

Here is a article talking about the speed of compiled python vs Julia. I don't see why it is better to go to all these extra steps just to end up with something slower. https://www.matecdev.com/posts/julia-python-numba-cython.html

[–] scharf_2x40@lemmy.world 2 points 8 months ago (1 children)

But I took your advice to heart and installed a Linter

[–] toasteecup@lemmy.world 1 points 8 months ago* (last edited 8 months ago)

I'd recommend a code formatter as well, it won't improve code execution but it greatly improves readability which is a massive plus to me. I love black personally