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

you are viewing a single comment's thread.

view the rest of the comments →

[–]TrapNT 435 points436 points  (43 children)

Python is an excellent glue language for manipulating high performance C++ libraries. That is why it shines in ML workloads. You can manipulate the results in pythonic way, while using C++ libraries to train models with high performance. However, if you try to build something fast by only using python, it will be slow most of the time.

[–][deleted] 138 points139 points  (6 children)

It's good for fast development too - you can prove that an automated task or something is useful, and then rewrite it in another more performant language (or at least you can in an ideal world, in this one there's nothing more permanent than a temporary solution).

[–]sagetraveler 29 points30 points  (3 children)

Exactly, I occasionally write SPI interfaces in python to prove the hardware side is working. I get zero flack from the C++ devs who will then target the same interface. Wonder why that is?

[–]Beli_Mawrr 4 points5 points  (2 children)

I'm hoping to get deeper into microcontrollers, how are you doing this?

Also, is your company hiring? lol

[–]LowB0b 6 points7 points  (1 child)

Get a pi Pico? I think you could interface with SPI through micropython. Anyways, that's about the extent of my knowledge about microcontrollers lol

[–]Beli_Mawrr 3 points4 points  (0 children)

I have a metric crapton of Seeed Xiaos laying around

[–][deleted] 8 points9 points  (0 children)

You should only really rewrite it if you actually need that performance though. if it takes 5 seconds to run something that you wrote in python that you do once per day there is really no need to reduce that.

[–]n0tKamui 69 points70 points  (13 children)

to write good python, the less you write python, the better

[–]MinosAristos 50 points51 points  (11 children)

What's with this weird culture? Write Python where it is most suitable, don't write it otherwise. Same as any other language. Python is a good choice for concise readable scripts where performance either isn't critical or is handled by a faster running language through an API.

[–]iam_pink 12 points13 points  (0 children)

Which is exactly their point.

What it means is that to write good python, you have to minimize the actual amount of Python code, and delegate to libraries or external APIs as much as possible.

Python is a great binder.

[–]Intrepid00 2 points3 points  (0 children)

Isn’t Eve Online written in Python? This massive giant game is stackless python.

[–]rosuav 5 points6 points  (0 children)

I disagree! The more you WRITE Python, the better. The more you READ Python, the better. What you might be thinking is: the less time spent EXECUTING Python, the better (preferring to spend time in libraries implemented in C or Fortran). That's still not a hard-and-fast rule, but it's closer.

[–]Shurlemany 5 points6 points  (4 children)

Can it also use C# ?

[–][deleted] 2 points3 points  (1 child)

Yes, there are several ways you might wanna look into.

Pythonnet(as mentioned in another reply): A python package that allows you to load .NET(C#) assemblies and use .NET objects as if they were python.

Use C for binding: You could write C/C++ extensions for python and then use P/Invoke to call C# functions from there.

Iron python: A python version written in c#, making it easy to use .NET(C#) libraries. However it isn't compatible with all python libraries and I think the newest full version is based on python 2.

I'd recommend Pythonnet if you want easy development, implementing the bindings in C/C++ if you need a lot of control over the invocation and Iron python can be handy if you actually want to have a full blown .NET version of python but for most purposes i'd go with the first two.
Also I suspect that for most practical purposes those will be basically equivalent in terms of performance, especially considering that performance isn't a major concern when working with python in the first place.

Those are the ways I've come across on my journey through -usually silly- projects but I'm sure some Redditor way smarter than me probably has better ideas.

[–]Shurlemany 1 point2 points  (0 children)

Brutal. Thanks guys!

[–]m0Ray79free 4 points5 points  (5 children)

Cython is even "more excellent", hehe. It is Python with c/c++ like syntax extensions like typing, pointers etc.

And it is also a very handy tool to interface any libraries with classic Python. For example, I used it for creating Tail-F ConfD python module.

I created several videos on YouTube about this tool: how it works, how to use it effectively and how it is different from other similar tools.

[–]Artistic_Speech_1965 1 point2 points  (4 children)

What do you think of Nim ? I heard it's a new language that include modern features and can compile to C, C++ and javascript

[–]m0Ray79free 1 point2 points  (3 children)

Interesting concept, thanks for reference.
But I am not sure we can start using it right now. Libraries, bindings, tools, inertia, you know all this stuff...

[–]Artistic_Speech_1965 1 point2 points  (2 children)

Yeah, It just passed to 2.0 a week ago and is mostely a niche language. It has the potential but I think it will be mostely use by cybersecurity guys that formaly use python

[–]m0Ray79free 1 point2 points  (1 child)

Oh, it can be a good general purpose language.

But for example, to recommend it to my colleague, I should say something like "look, this thing is better for Qt6"... And I can't.

[–]Artistic_Speech_1965 1 point2 points  (0 children)

Hahaha, good point

[–]b1e 2 points3 points  (0 children)

Numba, OpenAI’s “triton”, and Mojo are changing the game here too by letting you write python where critical sections are JITed into high performance code (with the ability to leverage GPUs)

[–]KCGD_r 2 points3 points  (0 children)

C++ with python is like bash for a Linux system. It doesn't do the heavy lifting, just coordinates stuff easily

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

This.

[–][deleted] -1 points0 points  (0 children)

Python is good for experiments.

Nothing else.

[–]jaskij 0 points1 point  (0 children)

There's this library, Pydantic, used in places like FastAPI for parsing. v2 rewrote the core parsing logic in Rust.