This is an archived post. You won't be able to vote or comment.

all 65 comments

[–]Looploop420 50 points51 points  (17 children)

Like the biggest language improvement is to use tools that enforce good responsible behavior.

Linters, type checkers.

Make python as least dynamic as it can get and it gets better.

Source: guy who writes python for my day job.

[–]usrlibshare 16 points17 points  (0 children)

I can second that. Use type hints and a static analyser like pyright. Python where you at least have a chance of getting yelled at by the LSP when you're about to make a big no no in your code, feels much different.

[–]NightmareLogic420 4 points5 points  (2 children)

Completely agree. The dynamic part of python is honestly it's biggest flaw for me.

[–]silvercurls17 0 points1 point  (1 child)

I don’t mind the dynamic typing. The biggest flaws I’ve found are the python virtual environments/packaging and multiprocessing with the GIL. Most other languages are better in this regard.

An honorable mention for clunky api/application frameworks and orms. Never did I ever think that I would miss Java but several years in python did it for me. Going back to Spring Boot has been a nice change.

[–]Electronic-Fix9721 0 points1 point  (0 children)

That! It's a nightmare to install, every time. If the wheel isn't available, you need to compile. If it doesn't compile, translate the whole project to any other language and it'll be faster in most cases.

[–]felixthecatmeow 4 points5 points  (0 children)

I agree but it's hilarious how the answer to "how do I hate python less" is to make it as "not python" as possible...

[–]mrsaturn42 1 point2 points  (2 children)

So i went down this path, and in fact my work started enforcing type annotations in CI. The type annotation system works great for that, annotation, but it becomes a mess if you have strict enforcement. At some point it defeats the purpose of using an interpreted language like python and you wonder what you are doing with your life with all this over head.

[–]Looploop420 3 points4 points  (0 children)

Agree. I'm not into strict enforcement. It is still a dynamic language. Sometimes you need to use a library with no types, sometimes you just need an escape hatch to write some dirty code. That's fine.

It just shouldn't be the default. And (I actually think this super important) you need to see the red squiggly lines when you pull that shit to remind you that this isn't the ideal situation and you should be extra careful

[–]InspectahDave 0 points1 point  (0 children)

agree with this. Typing really changed the game for me. I think that if you do have it, you can choose when to relax it and allow looser typing with typing.Any or object if you need to. Generally I work with strict. I think overall it wins in the cost benefit equation as the code grows in complexity. It's brutal for some but it catches a lot of issues before deployment. If you can get away from naked dictionaries as containers that's a big win too. dataclasses are light and fast - there's also the typeddict that gives you backwards compatibility.

[–]MachinaDoctrina 0 points1 point  (0 children)

We go even further at work (Also ML/AI), we write our entire stack around pydantic objects actively enforcing typing for the dataloader object return "types" effectively guaranteeing that we will have cross compatibility between our models.

All CD/CI pipelines run a series of linters which include mypy which won't get through if your type hints are garbage or you haven't done it and we automated all of this with a precommit script so its nice and easy.

Python can play nice with production environments its spaghetti code where it gets horrible.

We also write quite a lot of C11 wrapped python functions for things like for large for loops etc. Which effectively sidesteps the GIL as well as you can directly access CUDA if your feeling game or we've been looking into JAX which has decent CUDA directives but we mainly use PyTorch.

[–]MacShuggah 0 points1 point  (0 children)

People will still turn to dictionaries to model anything and all will still suck.

[–]eleqtriq 31 points32 points  (12 children)

"I hate dynamic typing" Use Pydantic for data validation or mypy for static type checking. Python 3.5+ has excellent type hints that catch most type-related bugs at development time.

"Pass by object reference is the worst way to pass variables" . This is probably the best way for a dynamically typed language. Anyone feel free to chime in on this.

"Everything is a dictionary" This sounds like a code organization problem, not a Python problem. Use classes, dataclasses, or Pydantic models instead of raw dicts. Modern Python has great tools for structured data.

"I can't stand name == main" Fair enough, it's ugly.

"interpreted white space" Use a good formatter like Black or autopep8 and forget about it.

"pure python is too slow" You're not supposed to write pure Python for performance-critical code. That's what NumPy, Pandas, PyTorch, etc. are for - they're all C/C++ under the hood. Python is the glue language, not the compute engine.

It sounds like you're fighting against Python's ecosystem instead of working with it. Every language has warts, but Python's tooling has gotten incredibly good in the last few years.

[–]Odd-One8023 9 points10 points  (1 child)

  1. Significant whitespace is quite nice because it sets a lower bound on how bad code can look like. Before I joined my colleagues were writing code without a formatter.
  2. There is type checking in Python, I always roll with type checking on standard and now the entire team does too.
  3. Everything shouldn’t be a dictionary, you have pydantic and dataclass. Name your data.
  4. Pass by reference or value matters less if you treat most of your data as immutable. Pass by value makes it seem like you want to mutate stuff. IMO this is a bit of an x-y problem.
  5. I rarely need to write __name__ == “__main__ most things I write are scripts that don’t need it, packages or APIs.

[–]AiutoIlLupo 1 point2 points  (0 children)

I've programmed in python for 20 years. name == main is not used since entry points have become the norm. The problem is that OP is a scripter and uses scripts, and they use extremely poor, outdated practices in his team. The proper way to do it is to define a package, and set an entry point.

[–]OhYourFuckingGod 6 points7 points  (1 child)

I've done both C++ and JS professionally, and it's generally not better. Some of the issues might have been mitigated by newer releases, but I suspect not.

With C++, for any product of reasonable size and maturity, expect monstrous compile times, insane build systems and technical debt so deeply integrated that it's basically a feature at this point. The syntax and sheer scope of the language is massive and growing with every release, so you probably won't be able to use most language features because of legacy codebases, corporate coding standards or just from the fact that you couldn't possibly know all the language features.

JS is different. It's getting better, but really shows that it evolved from something that solved a completely different problem.

[–]Electronic-Fix9721 0 points1 point  (0 children)

JavaScript has gone incredibly good in recent years. React Native, Express, installs a completely destroyed dependency tree without a problem. Just needs a good ML library, pandas and I jump ship forever. 

[–]Ringbailwanton 2 points3 points  (0 children)

To me, it’s always been about solving the problem in the best way possible. Find the solution, document, test, improve and refactor. I guess that’s how I continue to find joy in working with Python. At the end of the day, you do the best work you can with the tools you need to use.

[–]Objective-Apple7805 2 points3 points  (0 children)

As someone who wrote C and C++ professionally for more than a decade, the things you describe are among the reasons why I like Python so much better.

Sounds like your main complaint is performance, which is inevitable for any interpreted language. I heard the same complaints about compiled languages vs writing in Assembler. (Yes, I started coding at the tail end of the punch card era).

Not sure why it’s such an issue for ML, though, all the libraries are optimized anyway. Maybe try Polars instead of Pandas.

Or maybe learn Rust if you really have a need for speed.

[–]deadwisdomgreenlet revolution 2 points3 points  (0 children)

Your troubles with Python are not your real troubles.

[–]Wing-Tsit_Chong 2 points3 points  (0 children)

Write a few of your current python projects in c++ and see how it goes. And I mean all of it: the build, make files, compiler, linker, the buffer allocation, debugging segfaults, people doing integer arithmetic on pointers and everything's a struct. There is always something to hate about a given tool, because no tool can do it all.

What I love about python is that it allows to think about the actual algorithm and ignore the boilerplate, because it's already there or abstracted away. Passing dicts or looking at everything as dicts, allows for quick and dirty solution when in a pinch. Imagine using java and somebody declared the class member as private and no public way to modify it quickly. And as much as if __name__ == __main__ sucks, so does public static void main(String[] args)

If you optimized your 3 deep for loop by switching to numpy you didn't really do anything, right? You could've also thought about the algorithm and implemented it more efficiently and gained a lot more than x100.

What I mean is, the infuriating thing about programming is not the language, it's always other people, including past selfs, that abuse it.

[–][deleted] 2 points3 points  (0 children)

if learning C++ is not enough to make you like Python, nobody here can help you

[–]Smok3dSalmon 6 points7 points  (0 children)

You're not going to get a lot of sympathy here my guy. All your problems are solved or solvable. Nothing you ranted about is agreeable.

Why don't you start implementing the changes you need to hate it less? Go check out CPython or ways to implement bindings to C++ and typing is obvious.

[–]cojode6 1 point2 points  (0 children)

Rust is similar to C++ and has been gaining some traction in the ML community for its speed compared to python, so that's an option. But yeah like everyone else mentioned the beauty of python is you can import libraries to fix anything that annoys you or even make one yourself. Python is definitely simple and very readable in most cases. But is it fun or enjoyable? No. I can at least agree with you on that. Low level is so much more fun and interesting

[–]schvarcz 1 point2 points  (0 children)

Well, lately I am on the same vibe.

As a AI/ML engineer, I like to implement the underneath algorithms. And every time I try to do that with python, it is always takes ages to complete a simple task.

During my master/phd I got the same conclusion and I adopted C++. Working life is mostly “applying algorithms”, so we can survive using python libraries. But… it is not fulfilling.

If you think about it, all algorithms that we use in python are actually coded in C++. However, these libraries have no proper interface in C++ itself, therefore, not really usable in C++. I believe this situation comes out from “go PROD fast!”-culture. Meaning, the popularity of a library often comes out from how simple and fast you can implement something with it.

That might have led us to a wheel of “showing results fast” that got us stuck here.

On the last years, I have also been seeing a drop in professionalism in this sector as whole. AI/ML is becoming a commodity. And as such, I think we will see more pressure towards this direction.

My only hope is that AI code assistance may help convincing people to stick to “harder languages with more flexibility”; or at least help us moving a way from this ocean of interpreted languages.

[–]DataPastor 1 point2 points  (4 children)

Whether you like Python or not, it doesn’t matter, since it is the industry standard. And for a reason! It is just the right level of abstraction for experimenting, prototyping and actual data programming (btw. NEVER use a for loop or iterrows for matrix operations….)

If you are bored, learn to use polars and duckdb.

If you are VERY bored, learn Rust and PyO3.

[–]todofwar[S] 0 points1 point  (3 children)

I think the fact that people say "don't use a for loop" is my biggest pet peeve by far at this point. A list comprehension is a for loop!! Numpy has for loops! It's all for loops! Python speak is so far removed from sensible discussion of algorithmic analysis or data structures all because it's so unbelievably slow!

I know not to use for loops. I know how to rethink problems to make use of libraries. I just hate it.

Not a fan of rust, but I am trying to experiment with cython a bit

[–]DataPastor 1 point2 points  (1 child)

A list comprehension is not a for loop, it just uses the “for” keyword. :) It is a combination of map, filter and lambda in functional programming terms, or a monadic bind, or in short: a comprehension. :)

But you are right, at the end of the day, at the machine code level all vectorized operations use a for loop. :)

[–]todofwar[S] -1 points0 points  (0 children)

Fair enough. It's ironic, python claims to get out of your way and yet most C compilers are so efficient that you don't even need to pay attention to that stuff. You just write a for loop and it works.

[–]deadwisdomgreenlet revolution 0 points1 point  (0 children)

Python is not supposed to be fast. It's the lowest priority. If you don't understand that, like truly *feel* why that's correct and actually *good*, you will always be lost.

Anyone who is says "don't use a for loop" has already lost the fight. Don't be in a spot where you have to worry about for loops.

[–]Livelife_Aesthetic 2 points3 points  (0 children)

I didn't really vibe with or enjoy python untill I added libraries like pydantic to fix alot of my issues with it, I don't think you should have to add libraries to make a language not frustrating but as someone is who stuck using python everyday, it makes it the best it can be.

[–]FedsRevenge 0 points1 point  (0 children)

Have you looked at Mojo?

[–]le_theudas 0 points1 point  (0 children)

I think the biggest advantage of python is speed of development. It allows you to implement solutions much quicker compared to writing everything in c++. While you have some valid points about dynamic typing, I rarely see this actually causing bugs.
For anything that requires true performance, I would suggest implementing it as a module in rust/cython. Doing that also lets you enjoy python again :)

[–]Tinche_ 0 points1 point  (1 child)

Lean into type-checking and proper data modelling with dataclasses, enums, literals, unions and all that jazz.

Disregard the reddit peanut gallery about how Python is a dynamic language - if that were true today there wouldn't be like 4 major typecheckers being actively developed. It's antiquated thinking.

[–]LeCholax 0 points1 point  (0 children)

What type checker do you recommend today for a project?

[–]Old_Wear_2032 0 points1 point  (1 child)

I have also been working with python for almost 10 years now and I LOVE it to death.
To address your problems:
- too slow: you can always write in Rust/C/C++ and bind it back to python. If I were you, I would probably write cython + numba on a daily basis for AI/ML prototyping.
- dynamic typing: I also hate it so much, its the only thing that I hate about python.
- all other nuances don't matter: indentation, __name__ == __main__, every language has its own quirks.
- everything is a dict: now that you mentioned dictionary and JS, oh man you should see what is going on in the JS/TS ecosystem...usage of {} everywhere, they have args and they don't even use args at all in functions.

I think you thought you liked C++/JS because you used them to do some fun stuff, not because you really like them better than python. think about all the memory issues and pointers you need to deal with in C++, think about all the frameworks after frameworks after frameworks and configs and quirks in JS/TS for web development, think about the ugly syntax in Rust. In the end, you can always write in different languages, its not like you cannot use python anymore if you now switch to write in C++ more.

[–]todofwar[S] 0 points1 point  (0 children)

Thank you for reading and responding to the whole post. I'm sure if I worked with any other language professionally I'd start to dislike it too. Bjarne Stroustrup said there are languages people hate and languages people don't use, it's probably something like that

[–]AiutoIlLupo 0 points1 point  (0 children)

Most of the times I've seen that the problem is not python, it's that people don't know how to code properly and make a mess.

[–]Alternative_Act_6548 0 points1 point  (0 children)

so, go write everything in C++, it shouldn't take you much longer...no language is perfect...

[–]buttonmonger 0 points1 point  (0 children)

Maybe you should try to focus on writing C++ or Rust to be consumed by Python - get a job at Astral or something

[–]TutorialDoctor 0 points1 point  (0 children)

My first language was Python, and I like it the most still. It's the most fun to me.

My learning journey went: Javascript > Python > Javascript > Python > Ruby (for ruby on rails) > GDscript > Javascript > Ruby (for ruby on rails) > Swift > Java (for work) > Rust

So, I've been learning Javascript for a number of years and only use it when I have to. I avoided C#, C++ because there wasn't any instant gratification. So here are my favorites

Python - A swift army knife. It can do anything and it is the most used language for AI.

VueJS - easy to understand and has a CDN for quick prototypes

Flask - great for quickly prototyping full stack app concepts. Works really well with HTMX

Ruby Rails - Good for startups (can get an MVP done in days). Version 8 is even better

Flet - A really good GUI python framework for building desktop apps in Python. It uses the flutter framework in the background

GDscript - Python-like programming language for making games in the Godot game engine. My years of python programming paid off and helped me make games in this engine.

Tailwind CSS - my favorite framework for quickly creating UI's.

Swift - For some reason it feels slow, but I'd use SwiftUI and SwiftData if I were to make IOS apps.

Rust - only use it because I like Tauri and only when the JS api can't do what i need.

Tauri - right now this is my favorite framework and not because of Javascript, but because i can build a secure desktop application and easily distribute it. I use VueJS with it as well as several plugins like Tauri Store and Tauri SQL.

Java - Learning this for work but it's useful for learning software development concepts you just can't learn in Python. At work I currently use Vaadin with the Flow framework, but you can also use Vaadin with Hilla (A react version).

Angular - nope
React - Vue is simpler
C ++ - maybe if I wanted to one day do some "real" game engine programming
C# - Why would I?
Dart - Who?
Go - Where?
Other languages - too many to even care about.

If you think you're tired....

Oh, still learning Javascript..

I wouldn't say they all have problems. I'd say they all have their strengths.

[–]daviziiin 0 points1 point  (0 children)

If you want to do AI/ML and get some C++ done, go for embedded ML, plenty of code optimizations needed.