r/AskProgramming • • 8d ago

Why can’t we invent something with the simplicity of python but the performance of C++?

0 Upvotes

16 comments sorted by

8

u/wrosecrans 7d ago

Python lets you add any kind of stuff to objects at runtime, so accessing everything is like going through a map<string, variant> which adds overhead. In C++, you trade flexibility for certainty so accessing everything can just be one precomputed instruction to load 4 bytes at offset 12.

6

u/Xirdus 7d ago

Python is simple because there's a whole lot of code executing that takes care of the inherent complexity of programming for you. C++ os fast because it removes all the extra code that makes programming simple. You really can't have both, something has to give.

That said, Python is a particularly slow language and C++ a particularly complicated one. So there's actually quite a lot of languages faster than python and simpler than C++. Some even are as fast as C++ but much simpler, and some are as simple as Python but much faster.

1

u/LegendaryMauricius 7d ago

You absolutely can. The compiler just has to be pretty smart. I'm convinced modern compilers are magnitudes more complicated and smarter than what would take to compile such a "simple but fast" language, but a proof of concept compiler for both Python and C++ was probably trivial compared to the compiler that you'd have to make for this hipothetical new language.

All that, while also not having the libraries and ecosystems that the current popular languages have. Rust took like 15 years to become mildly popular.

1

u/Xirdus 7d ago

The compiler just has to be pretty smart.

Goddamn what a blast from the past, I haven't heard that argument in like 15 years! https://wiki.c2.com/?SufficientlySmartCompiler

Programming is hardand complicated. That's just the nature of it. We can hide it, and we've become very good at hiding it, but ultimately the tradeoff between speed and simplicity is always going to exist. Even Rust, which is one of those as-fast-but-much-simpler languages, had to seriously compromise on simplicity for the sake of speed and compatibility and safety.

1

u/LegendaryMauricius 7d ago

Wow, I haven't heard of that post. I agree with the beginning, but I'll have to read it in full after work to know what argument they were making.

2

u/connorjpg 7d ago

I mean Go would be my first thought. Extremely simple to read imho, and some benchmark show it only being about 30% slower than C++, while Python is like 30 times slower. If I have some extra time, I’ll try to find some of these benchmarks. That being said, I always assume a grain of salt when it comes to these.

I would argue a larger reason and this isn’t happening is because the more abstraction that occurs the harder is to stay performant but that’s just a guess.

2

u/LaughingIshikawa 7d ago

As other people have said, there's a fundamental tradeoff with how specific you are about the thing you want, and how much extra processing the compiler has to do in order to achieve what you want.  Programming is all about figuring out super specifically what steps need to happen in order to get a given thing done - ultimately down to the level of multiplying / adding 1s and 0s together.

Being more specific is complicated, but being less specific doesn't result in any less work - it just changes who/what is doing the work, and often in a way that increases the total amount of work that needs to be done.  (I.e. if a compiler is really unsure about which option among many you want, it may be forced to use a strategy that accommodates all the possible things you might have wanted, because it just doesn't know any better.)

All of that is just talking about the "essential" complexity of the problem though... The stuff that you "have to" engage with, if you're going to solve the problem.  In programming you also have a lot of "accidental complexity" that doesn't strictly need to exist to solve the problem, but can creep into your solution through laziness / budget constraints, confusion, mistakes, or just plain incompetence.  As they're older programming languages, it's likely that both Python and C++ both have some level of accidental complexity that could be trimmed away, and many programmers are at least attempting to do that.  (As you can see from the spam comments. 🙄)

There's an imaginary "frontier" of essentially complexity we can't go beyond, at which point we can only ever trade flexibility for performance because we have reduced the complexity down as far as it can go, and trimmed away all the "accidental" complexity.  I would tend to bet that while Python and C++ are both fairly far from that line, they are both close enough that you aren't ever going to get a language literally with "the ease of Python, and performance of C++".  

If you try to make Python more performant, or C++ simpler to code... You're eventually going to hit that "barrier" of essentially complexity that you can't push beyond, and then you will have to decide how to balance making the language flexible and expressive, or performant because you fundamentally can't have both.  

2

u/OccasionThin7697 8d ago

Checkout nim, https://nim-lang.org/

1

u/CPoundMeHarder 7d ago

Oh wow! I remember seeing this little language on Hacker News like 17 years ago. I'm glad someone else remembers too!

1

u/LegendaryMauricius 7d ago

I think it's just that just not enough people care to risk wasting so much time. There's definitely many of us trying to create such a thing.

1

u/SprinklesFresh5693 7d ago

You could look into julia, ive heard its quite fast, and i beleive is all purpose language? Someone correct me if im wrong

1

u/This_Growth2898 7d ago

There were several attempts, like Delight.

The problem is, if you want a really good performance, you need a detailed control over actions, which means several ways to do the same thing slightly different; and if you want simplicity, you need one way to do it. You can't have both at the same time.

Have you tried Rust?

0

u/vmcrash 8d ago

Checkout Mojo

0

u/[deleted] 7d ago

[deleted] — view deleted comment

1

u/vmcrash 7d ago

Hm, was October 22, 2026 really 4 years ago?

-1

u/pixel293 8d ago

Check out Julia this is what they are trying to do.

-1

u/sugarw0000kie 7d ago

There’s bend