News for hackers. Stuff that matters.
Re:Why Python keeps growing, explained by benrutter on Friday March 03, 2023 @08:14AM (#35009126)
I completely agree - but you say that like it's a bad thing. I work as a developer alongside data scientists, who might have strong knowledge of statistics or machine learning frameworks rather than traditional programming chops.

For the most part they don't need to know about concurrency, memory efficiency etc, because they're using a library where those issues have been abstracted away.

I think that's what makes python ideal - it's interoperability with other languages and library ecosystem means less technical people can produce good, efficient work without having to take on a whole bunch of the footguns that would come from working directly in a language like c++ or Rust.

Re:Why Python keeps growing, explained by roflyear on Friday March 03, 2023 @08:35AM (#35009375)
Most programmers don't actually need to know about that stuff, either. And most programmers who do need to know about that stuff, don't know about it.
Re:Why Python keeps growing, explained by intelVISA on Friday March 03, 2023 @08:51AM (#35009603)
Solving race conditions is QA's problem right? ;)
Re:Why Python keeps growing, explained by oblio on Friday March 03, 2023 @09:57AM (#35010394)
You're so silly. QA? What's QA? Solving race conditions is the customer's problem :-p
Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @08:44AM (#35009524)
But this is a false dichotomy. The space of options isn't C++/Rust or Python. There are languages which attempt to give the best of both worlds, e.g. Julia.

> they're using a library where those issues have been abstracted away.

I work in Python, and while libraries like numpy have certainly abstracted away some of those issues, there's still so much performance left of the table because Python is still Python.

Re:Why Python keeps growing, explained by ofrzeta on Friday March 03, 2023 @08:46AM (#35009547)
I'd say if you do data-intenstive computation with Numpy you are not leaving much on the table due to Python.
Re:Why Python keeps growing, explained by dagw on Friday March 03, 2023 @08:53AM (#35009650)
I've rewritten real world performance critical numpy code in C and easily gotten 2-5x speedup on several occasions, without having to do anything overly clever on the C side (ie no SIMD or multiprocessing C code for example).
Re:Why Python keeps growing, explained by VBprogrammer on Friday March 03, 2023 @09:13AM (#35009870)
Did you rewrite the whole thing or just drop into C for the relevant module(s)? Because the ability to chuck some C into the performance critical sections of your code is another big plus for Python.
Re:Why Python keeps growing, explained by mandevil on Friday March 03, 2023 @09:40AM (#35010171)
But... pretty much any language can interoperate with C, it's calling conventions have become the universal standard. I mean, I still remember at $previousJob when I was deprecating a C library and carefully searched for any mention of the include file... only to discover that a whole lot of Fortran code depended on the thing I was changing, and I had just broken all of it (since Fortran doesn't use include files the same way, my search for "#include <my_library" didn't return any hits, but the function calls were there none-the-less).

Julia, to use the great-great-grand-op's example, seems to also have a reasonably easy C interop (I've never written any Julia, so I'm basing this off skimming the docs, dunno, it might actually be much more of a pain than it looks like here).

Re:Why Python keeps growing, explained by cjalmeida on Friday March 03, 2023 @04:15PM (#35015104)
Calling C from Julia is pretty straightforward

https://docs.julialang.org/en/v1/manual/calling-c-and-fortra...

Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @10:48AM (#35011134)
Even if you do this, you're still paying a penalty whenever you move data Python->C and C->Python.

Plus that you now need to write performant (and safe) C code, which (to me) defeats part of the reason to use Python in the first place.

Re:Why Python keeps growing, explained by pbourke on Friday March 03, 2023 @11:09AM (#35011421)
I’ve done the same but moved from vanilla numpy to numba. The code mostly stayed the same and it took a couple hours vs however long a port to C or Rust would have taken.
Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @04:48PM (#35015500)
For a package whose pitch is "Just apply one of the Numba decorators to your Python function, and Numba does the rest." a few hours of work is a long time.
Re:Why Python keeps growing, explained by slt2021 on Friday March 03, 2023 @02:04PM (#35013664)
2-5x speedup is not a lot, I would say it is not worth it to rewrite from py to C if you don't have an order of magnitude improvement.

Because if you compare the benefit to the cost of rewrite from py to C and cost of maintaining/updating C code and possible C footguns like manual memory safety, etc - then there is no benefit left

Re:Why Python keeps growing, explained by redsaz on Friday March 03, 2023 @02:49PM (#35014166)
It can be worth it. What matters is how much time it saves your users over the course of using the app vs the time it took to develop it. So, if:

#-of-users * total-time-saved-per-user > time-spent-optimizing

Then it's worth it. You can even multiply by cost of user per time unit and cost of developer per time unit, to see how much money was saved.

Even in cases where its the same person on both sides, it can still work out. There's an xkcd comic about it, even.

Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @04:46PM (#35015473)
2-5x IS a lot. It's the speed difference between the current iPhone 14 and an iPhone XS-iPhone 6. That's 4-8 years of hardware improvements.

And the parent was talking about numpy code which is better than stock python, who knows how far back normal python would send you.

Re:Why Python keeps growing, explained by jononomo on Friday March 03, 2023 @05:06PM (#35015695)
I'm in the camp that 2-5x performance improvement is not really worth re-writing Python code in C for.
Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @06:53PM (#35016594)
Guess that'll depend on how much you need the performance and how much code it is.

They're comparing numpy (SIMD plus parallelism) with straightforward C code and getting a 2-5x improvement.

Re:Why Python keeps growing, explained by slt2021 on Friday March 03, 2023 @09:55PM (#35017692)
I highly doubt that numpy can ever be a bottleneck. In typical python app - there are other things like I/O that consume resources and become bottleneck, before you run into numpy limits and justify rewrite in C.
Re:Why Python keeps growing, explained by _aavaa_ on Saturday March 04, 2023 @12:22AM (#35018436)
I haven't personally run into IO bottlenecks so I have no idea how you would speed those up in Python.

But there's two schools of thoughts I've heard from people regarding how to think about these bottlenecks:

1. IO/network is such a bottleneck so it doesn't matter if the rest is not as fast as possible.

2. IO/network is a bottleneck so you have to work extra hard on everything else to make up for it as much as possible.

I tend to fall in the second camp. If you can't work on the data as it's being loaded and have to wait till it's fully loaded, then you need to make sure you process it as quickly as possibly to make up for the time you spend waiting.

Re:Why Python keeps growing, explained by dagw on Saturday March 04, 2023 @05:50AM (#35019956)
In my typical python apps, it's 0.1-20 seconds of IO and pre-processing, followed by 30 seconds to 10 hours of number crunching, followed by 0.1-20 seconds of post processing and IO.
Re:Why Python keeps growing, explained by jononomo on Friday March 03, 2023 @05:05PM (#35015675)
2-5x speedup barely seems worth re-writing something for, unless we're talking calculations that take literally days to complete, or you're working on the kernel of some system that is used by millions of people.
Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @10:45AM (#35011082)
Have gone through the exercise, I know this is false.

Not everything can be pushed into numpy, and you can still be left with lots of loops in python.

Re:Why Python keeps growing, explained by dragonwriter on Friday March 03, 2023 @02:10PM (#35013722)
That's what numba [0] is for (can also help with the NumPy stuff in certain cases.)

[0] https://numba.pydata.org/

Re:Why Python keeps growing, explained by _aavaa_ on Friday March 03, 2023 @04:39PM (#35015394)
Oh, I'm familiar with numba and while it certainly helps, it has plenty of it's own issues. You don't always get a performance gain and you only find this out at the end of a refactoring. Your code can get less readable if you need to transport data in and out of formats that it's compatible with (looking at you List()).

To say nothing of adding yet another long dependancy chain to the language (python 3.11 is still not supported even though work started in Aug of last year).

I do wonder if the effort put into making this slow language fast could have been put to better use, such as improving a language with python's ease of use but which was build from the beginning with performance in mind.

Re:Why Python keeps growing, explained by nindalf on Friday March 03, 2023 @09:45AM (#35010244)
> a whole bunch of the footguns

Could you expand on this in the context of Rust?

Re:Why Python keeps growing, explained by benrutter on Friday March 03, 2023 @10:16AM (#35010676)
Sure thing! Footguns might be the wrong word, and I know as a low level language Rust is insanely safe, but for a high level developer it's type system is gonna mean spending a lot of time in the compiler figuring out type errors, at least initially. That might not be a traditional footgun, but if you're just trying to, I dunno, build a crud api or something, its gonna nuke your development time.

Please don't read this as "rust is difficult and bad", I definitely don't think it is! But its a low level language, and working with it means dealing with complexity that for some tasks just might not be relevant.

Re:Why Python keeps growing, explained by pkolaczk on Friday March 03, 2023 @10:35AM (#35010926)
I find figuring out type errors is usually less work than figuring out the runtime bugs they prevented.
Re:Why Python keeps growing, explained by benrutter on Friday March 03, 2023 @11:12AM (#35011444)
I agree, but for something like the CRUD app example I made bringing in pydantic or something would solve that. Rust's type system is a lot stricter because it's solving problems in a space that doesn't touch a lot of Python developers.
Re:Why Python keeps growing, explained by namaria on Friday March 03, 2023 @03:10PM (#35014403)
In all fairness Rust was never meant for writing database interfaces, more like storage engines.
Re:Why Python keeps growing, explained by li2uR3ce on Friday March 03, 2023 @10:10AM (#35010578)
> without having to take on a whole bunch of the footguns that would come from working directly in a language like c++ or Rust.

Don't forget the footguns of working with developers who do those things. Ask them to do something simple and you get something complex and expensive after months of back and forth about what is wanted. You're likely to a framework for a one off SQL query.

I hear it being said already, "You're using software developers wrong!" Well, maybe software developers shouldn't be so hard to use?

Re:Why Python keeps growing, explained by ryanianian on Friday March 03, 2023 @12:06PM (#35012247)
> maybe software developers shouldn't be so hard to use?

This whole take assumes bad intention on both sides. Nobody's job is easy in this situation. Leadership's job is to set everyone up for success. If things go off the rails and end up with months of back and forth leading to nobody being happy despite good intentions and honest effort, then the problem lies with leadership.

Re:Why Python keeps growing, explained by butterfly771 on Friday March 03, 2023 @11:16AM (#35011502)
In fact, the development of the world is based on constant levels of abstraction, just think of assembly language and computer punch tape programming, those days are not long past.
Re:Why Python keeps growing, explained by bostik on Friday March 03, 2023 @02:00PM (#35013622)
> For the most part they don't need to know about concurrency [...]

In my opinion, this is the part that Go got mostly right. Concurrency is handled by the runtime, and held behind a very thin veil. As a programmer you don't really need to know about it, but it's there when you need to poke at it directly. Exposing channels as a uniform communication mechanism has still enough footguns to be unpleasant, though.

In an ideal world, I should be able to decorate a [python] variable and behind the scenes the runtime would automatically shovel all writes to it through an implicitly created channel. Instead of me as a coder having to think about it. Reads could still go through directly because they are safe.

If I could have Python syntax and stdlib, with Go's net/http and crypto libraries included, and have concurrency handled transparently in Go-style without having to think about it, that would be pretty close to an all-wishes-come-true systems language. Oh, and "go fmt", "go perf" and "go fuzz" as first-class citizens too.

Someone else in this thread brought up the idea of immutable data structures as a default. I wouldn't mind that. Python used to have frozenset (technically it still does but I haven't seen a performance difference for a while), so extending the idea of freeze()/unfreeze() to all data types certainly has appeal.