r/learnprogramming • u/Happy-GoLucky365 • 4d ago
Why is C++ better than Python?
Hello! I am new to programming. Im in college and we use Python for my classes right now.
I hear people make a lot of jokes about how C++ is more powerful than Python, and should be used instead. But why?
Feel free to give me any tips as well, on things that helped you be a better programmer, or just any insight you may have! Thanks so much
61
Upvotes
152
u/CodeToManagement 4d ago
This is like saying why is a hammer better than a saw. Neither is better or worse depending on what your use case is. They are both tools to get a job done- so pick the right tool for the job
49
u/Solnx 4d ago
C++ is a lower-level language than Python, giving developers more control over memory and the system. When used correctly, this can achieve stronger performance. The downside is greater complexity, more opportunities for bugs, and a steeper learning curve compared to Python when getting started.
They have different use cases, but C++ is better suited for OS, game engine, low latency programs, ect compared to using Python.
11
u/DiabloConQueso 4d ago edited 4d ago
It’s not an either-or choice. You use C++ when appropriate, and you use Python when appropriate. Some things C++ does “better” and some things Python does “better.”
Learn both. Learn as many languages as you can. Don’t pick one. Pick them all. Learn when one is appropriate and learn when another is appropriate.
If you’re learning Python right now, keep at it. Learning C++ isn’t going to help you pass that class. Learn C++ later, in a different class. Or on your own.
You’ll eventually learn the difference between compiled languages and runtime interpreted languages. And other differences. Then you’ll be in a better position to decide what language to use to solve whatever unknown problem or task. There are some things you’ll have many options for, and there are some things where your options are going to be more limited.
You’re probably learning things that aren’t language-specific right now: loops. Conditionals. Functions. Variables. Those things exist in pretty much all languages. The important part right now is getting those fundamentals down pat and Python is a good way to learn them. C++ would be too, but again, that’s not the class you’re taking right now.
27
u/NopileosX2 4d ago
All programming languages which are used are bad and all others are irrelevant. C++ is an overly bloated mess and python has no idea what it even wants to be these days.
Software development is impossible.
11
u/thisismyfavoritename 4d ago
languages are tools. There are tools that are better suited for specific jobs. Python can be a better choice than C++ and vice versa
1
u/Happy-GoLucky365 4d ago
Wow, well this has been some really helpful advice. Thank you to everybody who gave me more insight!
5
u/huuaaang 4d ago
The performance benefits of C++ are real and undeniable, but it's not enough to consider one "better" than the other. Python is good for scripted type things that don't really have to do heavy processing of their own. To have to think about memory management and data types and all that might be unnecessary overhead. Even the ML work people with with Python, which sounds like something C++ would be better suited for, is mainly running compiled code on GPUs. The Python just orchestrating that. C++ wouldn't buy you much.
Python: Faster to write
C++: Faster to execute
5
u/Retsyn 4d ago
You have to chose what the job is before evaluating the tool as "good or bad".
I use both at my work-- When I use Python, I may lament that it can't do hard math or crunch big numbers at high speed, where as the C++ would blast through the big calculations in milliseconds.
When I use C++ I lament that I need digital signatures and compilation to deploy to users, where as the Python ports anywhere and the interpreter just goes.
5
u/pixel293 4d ago
As you get better at programming you will find that the language doesn't matter. You can pick up a language in a weekend. The basics are all the same, they all use math, logic, functions, and sometimes classes. You just need to read a primer on how you declare these things and off you go.
Learning a programming language is not learning to program. You USE it to learn to program, programming is breaking large problems down to smaller steps and thinking logically. When the time comes and the languages you know don't meet your needs, you can pick up a new one quickly as long as you know how to program.
5
u/code29451 3d ago
The people making those jokes don't understand programming languages and are just regurgitating what they read in stupid memes
4
u/_th3oth3rjak3_ 4d ago
Yeah Python is like an automatic sedan with good gas mileage. It’s easy to use, reasonably decent for performance, easy to start up and get going. C++ is like a formula one car. It’s really fast and really dangerous if you don’t know what you’re doing. It’s a complex language with lots of historical baggage. Both are great, but use the right one where it’s needed.
4
u/unlucky_ducky 3d ago
Honestly, people in college classes typically just parrot what they've heard other people saying. Both C++ and Python has their use cases and one is not strictly better than the other.
3
u/Iowa50401 3d ago
Define “better”. It depends on what you want done.
3
u/QuadWingedCrane 4d ago
Google could have been quicker
6
u/AnonymousGamerAcc 4d ago
Idk what people are yapping about in this thread but essentially what they usually mean by c++ is more powerful than python comes down to how the languages work "behind the scenes".
Python is made to be super simple, fast to use, and readable. Because of this, certain things have to be handled in a very "heavy" way, like for example making every variable a "guess" instead of specified. It also routinely runs a so called "garbage collector" in the background, causing spikes in performance, and lastly, python runs on top of another program, and not directly on the machine.
On the other hand, languages like c++ are made to have the program itself be pretty fast, not so much the process. In c++ you give every variable you create a specific type (with some nuance), making it so the CPU knows exactly how to handle the variable instead of guessing. And unlike python, c++ runs more or less directly on the machine, meaning it can take full use of it.
Now this is a kinda short and easy version for an explanation, so if you're more interested you should do some research!
2
u/Altruistic-Toe-5990 4d ago
It comes down to the advanced-ness. It's better than Python, but worse than Python++. Google could've answered this for you
2
u/Dazzling_Music_2411 4d ago
Rather ask your fellow student jokers.
We have no way of understanding their joke.
2
u/zeekar 4d ago
In general, you can't say "programming language X is better than programming language Y". Different languages do different things well, so the most you can say is "X is better than Y for task Z", and even that is a matter of opinion. I mean, PHP and JavaScript are widely considered badly-designed, but that didn't stop them from taking over the whole web. The language you can run most easily tends to be the language you wind up using.
C++ programs will generally run faster than Python programs because C++ is compiled. When you run a Python program, what you're really running is a program called
python- the Python interpreter. That program reads your Python code and carries out the instructions it contains. It's an extra level of indirection between the computer and the code you want to run. C++ (and its parent language C, which Python is written in) has no interpreter; the entire program is translated ahead of time into an executable that the computer can run directly.This results in a tremendous speed advantage. A simple Python do-nothing loop that counts to 100 million takes over 2 seconds to run on my computer; a C++ program (compiled without optimization so that it actually does the counting instead of noticing that the code doesn't do anything useful and just skipping it entirely) does the same job in 120 milliseconds. But maybe for your problem, speed isn't critical, or is sufficiently less critical that the various Python modules that include compiled pieces to speed them up are fast enough.
There are downsides - a Python program can be fed to a Python executable on any kind of computer and it will run; a C++ program must first be compiled separately for each type of computer (not just Linux vs macOS vs Windows, but also x86 vs ARM...).
Another consideration on the "more powerful" claim is that because C++ compiles to a native executable, the program has full access to everything the computer can do. If needed, you can even switch into writing code in assembly, though that will be even less portable as you'll have to rewrite it for each one of the targets, not just recompile.
From Python, you only have access to things that have a Python interface. Which at this point is most things - if the interpreter doesn't come with one bundled, someone has probably made a module you can install with
pip. But with C++ that capability comes out of the box.2
u/Imagine-Dragons-Fan9 4d ago
All coding languages fall within a spectrum between High Level(Very simple for humans like scratch) or low level(Very simple to computers but complicated to humans like assmbly). Since Higher level languages are less similar to computer logic, they have to do a lot of translating, which is less effecient and takes more processing power. Python is esier to learn because it is high level, but C++ is more powerful since it’s more similar to computer logic.
2
u/Embarrassed-Green898 3d ago
it is not.
Different languages have different purpose.
2
u/Classic-Rate-5104 3d ago
Comparing apples and bananas
2
u/OutrageousCrab9224 3d ago
There is no linear world in which one major language is better than another in every way
2
u/SprinklesFresh5693 3d ago
Nothing is better , its just different, and for different purposes.
2
u/tin2426 2d ago
Many people answered the question. But, what I would like to add. Try not to get too caught up in discussions about what is better than what.
At the end of the day, these are tools. You should choose whatever is best for the problem you are trying to solve.
Good luck on your studies!
2
u/Skibidibob4 2d ago
They are completely different languages tho
2
u/Humble_Anxiety_9534 1d ago
has this question been answered enough times! C++ is a fast to run compiled language. python is a fast to write slower to run interpreter language. C++ gives you binaries that you can run on the machine you compiled for python you have to install python where you run it. python is written in C++ mostly. they are both powerful these days. most of the people who make fun of python, need to keep up. facts not opinions please!
2
u/xarop_pa_toss 4d ago
C++ and Python focus on completely different things. They are built almost as opposite to each other as possible.
C++ is a compiled language and it gives you real control over the hardware to a very minute level. This is both very good because you can optimize a lot but also much harder to use for high-level things.
Python is interpreted instead of compiled and the way it works is a lot more abstracted with layers of things you can't see underneath that let you focus on a different set of things. By design it is very modular and you will more often than not find yourself importing all sorts of libraries a.k.a. modules to perform data analysis or whatever python people do.
The languages focus on completely different types of objectives. If I wanted to write a program that needs to fit in a small chip that controls some machine, I probably wouldn't write it in Python because I need to optimize memory a lot. At the same time, if I wanted to analyze some dataset and chart some graphs, I'd probably just import Pandas and Numpy into a Python program and be done with it.
Edit: if you're interested, Google about the time difference of a basic for loop in different languages and why the difference is so big.
2
u/NotACoderPleaseHelp 4d ago
C++ is closer to the silicon, you have far more control and far more responsibility.
Python is what happens if you decide to make pseudocode into a language. It is the language that is closer to us.
Unless it is being implemented in scale, in a performance critical application or touching the hardware directly you are generally just fine with python.
Hell, if you write it in python and need more speed there are options as well, You can toss pypy at it (if it works) You can use one of a number of transpilers that convert the abstract syntax tree from one language to another language.
0
u/vegan_antitheist 4d ago
That question makes as much sens as "Why is a screw driver better than a hammer?"
This is objectively wrong. Both are Turing complete and therefore as powerful as any programming language.
The jokes are probably about how C++ allows you do write much more efficient, optimised and complex code.
C++ prioritizes performance and control. Python prioritizes simplicity and development speed. Python has less boilerplate, no explicit type declarations, automatic memory management, and a simpler syntax. This means less control and because it's higher level you can't optimise as much when you write code for the python virtual machine, while in C++ you can optimise for specific hardware.
What helps is ignoring those who just make these stupid jokes and instead concentrate on actually learning all the concepts, patterns, tools, methodologies, etc. Programming is hard. But for those who like doing it, it's a lot of fun.
1
u/Rythim 4d ago
C++ works out
1
u/atarivcs 4d ago
c++ programs have much faster execution time, maybe that's what they meant by "more powerful".
1
u/beb0 4d ago
It's not it just has more bits and bobs to twiddle and lower level pitfalls
1
u/BranchLatter4294 4d ago
Use the right tool for the job.
1
u/Atmosck 4d ago
C++ is not better (or worse) than python. They are very different languages with very different purposes. It's true that if you write code that does some number crunching in a loop, C++ will be way faster. That's becuase that kind of work isn't what python is for.
C++ is a compiled systems language. It gives you direct control of low-level system stuff like memory allocation, which is both powerful and dangerous. Compiling code can take a while, but that means the compiler can spend all the time it needs to optimize your code.
Python is an interpreted scripting language. With python there are more layers of abstraction between you and the hardware. You lose the low-level control of a systems language, but gain a lot flexibility, safety, and ease of use for it. Interpreted means the code is compiled in real-time while you use it*, which means a faster development workflow with no waiting for the compiler, but also slower code.
As a scripting language, python's job is to be an easy, flexible interface for orchestrating other things. Crucially, it dispatches to compiled extensions written in other languages for performance sensitive things. Much of the python standard library is C under the hood. Python's ecosystem is full of libraries that use extensions written in C, fortran or rust. That slow number crunching loop that's way faster in C++ - the right way to do that in python is to use a library like numpy and it's vectorized functions instead of a python loop, and you'll get similar speeds.
*(The python interpreter really uses a two-stage process with an intermediate representation called bytecode. Typically, the first stage is compiled to bytecode ahead of time - that's what a .whl file is. Then the python virtual machine does the second stage - translating bytecode into machine code - in real time.)
1
u/hasanyoneseenmyshirt 4d ago
it not better or worst. it just means has different uses. If I wanted speed, lets say if I was building a HFT algo, I would use C/C++. if I wanted to prototype a simple program, it would be much easier for me to write a quick and dirty program in python, like if i wanted a simple web scrapper. Most python libraries are written in C/C++ if they are computationally heavy, I think you can do operation on NumPy arrays faster than native Python lists but do not quote me on that, so you get the best of both worlds of easy syntax to low level performance. I bet people think assembly language is better that C++ because it the closest thing to actually writing in machine code.
In the end of the day, it really just matters on what you plan on doing and what tools/langauge you feel most comfortable with.
1
u/Reasonable_Slide6304 4d ago
Python is like you're driving car and can only sit on the driver's seat, you have the pedals and stuff to fiddle with and they do things, but you don't really know what's happening in the engine space.
In C/C++ you open the hood and fiddle with the engine and see what happens there, the downsize is that some of the car controls might be missing and you need to build them yourself, but you have intimate knowledge on how they are connected to the engine and can also improve how they work.
I think in python some functions use C/C++ without the user knowing just to get better performance, performance being memory usage and more efficient use of CPU cycles.
Now a days as computers are really performance you don't really notice the difference with some basic programs, but if you need to make something massive and performance then python is like driving a tractor on a freeway, it moves but people aren't happy about it being there.
Also if you're ever interested in integrated systems where memory and disk space can actually be very limited, using the hardware in the best way possible requires understanding memory usage and the processor architecture.
In python the languages deals with the memory, in C/C++ you're the one handling reserving and freeing it.
1
u/Sad_Quote1522 4d ago
The simplest explanation is Python is slower. We live at a time where this doesn't matter much for hobbyists and many real world applications, but for the few times where it does matter python feels sluggish compared to C++.
On the other hand Python is easier to use. I'm assuming in the workplace AI has pretty much bridged the gap between the difficulty of different languages but if you are coding by hand C++ gives you more control, but therefore more ways to screw up.
1
u/da2Pakaveli 4d ago edited 4d ago
Each one has its use case. C++ for highly demanding systems, such as game engines. Python is convienent for data science related applications (although the libraries are often C/C++ under the hood such as Pytorch) cause you don't need to deal with the "burdens" of C++. The interpreter is great for interactively working with your data without having to recompile the app.
1
u/notactuallyme93 4d ago
A fluid-fueled rocket engine is far more powerful than a four-stroke petrol-engine, but for some reason most people still use the latter in their cars, those pathetic losers! Some even ride a bicycle instead of a car, or indeed a rocket powered missile.
Of course as students just beginning to learn something, you should absolutely use the most powerful thing ever - anything else would just be silly. I mean, you don't start in kindergarten digging in the sand with a shovel and bucket do you, when the much more powerful Liebherr R9800 exists! Every child should drive one of those!
Sarcasm aside - every language is different, C++ has been designed to be extremely close to the hardware, especially suited for applications where every clockcycle counts, and where you, the programmer, wants or needs to be in charge of exactly what happens to your memory, which registers are prefered, what kind of operations the CPU selects, and so on. As close to machine language you can get, without going into assembly. Python is designed to be extremely quick and easy to write applications that handle arbitrary collections of data in various ways, and utilize a lot of different libraries to offload the details from the mind of the programmer.
"Powerful" doesn't mean anything, unless you decide who gets that power to do what. You become more powerful as a programmer in Python, because it lets you write better code. You can be more powerful in C++, because you can access hardware directly. You can write less powerful programs in Python, because they might compile to less efficient code. You can write less powerful programs in C++, because you don't know what you are doing, and have to take care of everything memory and performance-related yourself ... so ...
No school with any amount of self-respect would try to teach C++ as the first programming language, and no student would ever write any software throughout their entire educational career, where the difference between languages would be noticable in the final product.
1
u/Boot_Burner 4d ago
They're entirely different toolkits. One isn't inherently better. C++ might be more challenging to learn but that's because it's a lower level language than python.
1
u/Electronic-Equal-616 4d ago
c++ is mostly considered more powerful because it runs way faster and gives you direct control over memory and hardware. python handles all that in the background, which makes it much slower, but ten times faster to actually write and learn. neither is objectively better, they just have completely different trade-offs.
1
u/Difficult-Tutor7855 4d ago
Firstly, you need to understand that a programming language is created as solution to particular problem(s). So, each programming language have its strength area. New solutions always emerges from inefficiencies of existing solutions. No programming language was created out of boredom or because one language is simply too old. it will interest you to know that most Banks still rely on FORTRAN till this day despite how old FORTRAN is. Different programming languages exists for different purposes. However, C++ is the languages that created most languages today and all modern languages are inspired by C++. and like all other languages, C++ has its limitation as well. This is how you look at programming languages
1
u/peterjohnvernon936 4d ago
Python is easier to learn and easier to use. C++ runs faster but it takes longer to develop a C++ program. If your program is dealing with a lot of data or processing and needs to be fast then use C++ otherwise use Python.
1
u/dlamblin 4d ago
There's actually many different Pythons, and IIRC several different C and C++ systems. So... The default Python releases are CPython, which just kind of illustrates how C is often more broadly available for an architecture and is preferred to bootstrap a lot of other systems in, though, yes, most compiled languages aim to get to the self-hosted state where they build their own source. I had some hope that Grumpy would seriously try to take up Python 3, but I believe it exists to possibly run some of the py 2.7 code inherited in the YouTube acquisition. And ended up not being too successful at that long term. GitHub - google/grumpy: Grumpy is a Python to Go source code transcompiler and runtime. · GitHub
Neither is better. Each language out there, generally, exists for a purpose where it made more sense to have a new language than to twist the other available ones into the purpose. Not that they don't change, grow, then overlap and get blurry here and there. Learn at least beginner level of a few languages, particularly if they're different paradigms, so that at the start of each project you have some idea of whether you're picking the right toolset for this project.
1
u/coder155ml 3d ago
You’ll learn
1
u/Familiar_Kale_7357 3d ago
Because IT won't allow me to install Python on their servers.
But what's really great about Python is I can do a sloppy proof-of-concept in Python and know that nobody's going to tell me to polish it up and ship it, cause we can't ship Python. That's gold.
1
u/Still_Membership2640 3d ago
I wouldn't say C++ is necessarily better than Python. They both have different strengths and use cases. C++ gives you more control over memory and hardware, making it great for performance-critical applications, game engines, embedded systems, and system programming. Python, on the other hand, is much easier to learn, has simpler syntax, and is widely used in AI/ML, automation, data science, and web development.
My advice would be to focus on mastering programming fundamentals first rather than worrying about which language is superior. Learn data structures, algorithms, problem-solving, OOP, and how things work under the hood. Once you understand these concepts, switching between languages becomes much easier.
Python is a great starting point, and learning C++ later can give you a deeper understanding of how computers work. Don't fall into language wars; a good programmer knows how to choose the right tool for the problem!
1
u/xpusostomos 3d ago
They're both terrible, but at least C++ is fast. Python is supposedly good at quickly throwing together a script.
1
u/sswam 3d ago
C++ is not better than Python. C++ is a horrendous mess of a language, Python is relatively well designed. If you want something more performant, try C, Go, or Rust, all of which are better designed than C++.
1
u/k1v1uq 3d ago edited 3d ago
As everyone else has already pointed out, it depends on what you're trying to do.
C++ is definitely better suited for direct memory management.
Suppose you write a password generator. You have to make sure the password is wiped from memory after the program terminates. You also need to ensure the machine doesn't spill that memory to disk (due to memory pressure, i.e., swapping), which could expose the password as well.
Unlimited memory access is what makes C and C++ stand out. Only Assembly gives you more direct access. But the power of C and C++ comes with a price: managing memory ownership by hand does create new security risks.
https://github.com/openssl/openssl/pull/33652
Python OTOH - Go, Java and many other languages - come with memory management built in or impose strict rules around it (Rust).
People choose Python for ease of programming (data engineering, machine learning), and C++ or C for critical code paths.
1
u/Shot_in_the_dark777 3d ago
https://www.youtube.com/watch?v=s7wLYzRJt3s and https://www.youtube.com/watch?v=YnL9vAFphmE have fun!
1
u/cthulhu944 3d ago
In the world of AI programming, I don't think this is the case anymore, but here goes it.
C++ is a very powerful compiled system language. It is compiled and has strong OOP capabilities while still having access/control of lower level, machine level constructs. With that power comes great responsibility. You have to watch what you are doing with memory allocations and some of the higher level operations and data structures are a bit awkward.
Python is a ubiquitous interpreted language. If there is anything like a cpu in it, there is probably a python interpreter for it. It has a robust standard library and is generally easy to learn.
Both are fantastic, powerful languages and the each have their pluses and minuses. If I were developing a real time embeded system, an operating system or a graphics intensive game, I'd probably pick c++. If i were writing just about anything else I'd probably go with python.
The important thing is that you pick the right tool for the job based on the problem you are trying to solve. There isn't an ultimate programming language. Be good at programming, engineering, and computer science. If you manage that, the language will sort itself out.
1
u/_4rcadia 3d ago
TL;DR
It is not. They are for different scenarios. However, as a beginner, starting with Python will be more comfortable.
1
u/qwyss 3d ago
Because americans do not pronounce it funny.
1
u/mredding 3d ago
It's a meaningless claim. It's just not useful. They're both Turing Complete, so by definition one cannot be more powerful than the other, both can implement each other. The theory of computation does not care about reading, writing, or executing programs. It's all the same.
Python is interpreted, so there's a runtime cost. C++ runs on bare metal and doesn't have to pay an intermediate tax of interpretation before operation. Fine. But WHAT IS the cost..?
Python gets about 80% of raw C++ compute speed. This is because 90% of all Python modules are themselves written in Python, 3% are written in C, and 7% are written in C++. And BOY... That last 10 percent represents the foundations of all Python performance. Almost every other module is implemented in terms of that 10% either directly or indirectly. Ultimately what's happening is Python is offloading as much heavy compute and instructions to the C++ modules at a time as possible, so it really minimizes how much overhead is required to orchestrate the modules, and there's a minimum of marshaling data over boundaries.
So they want to flex for 20%? I don't care. I'm principally a C++ engineer myself, I've worked in trading systems, video games, cloud infrastructure, databases, and robots, and python is plenty fast for all of that. That 20% isn't nothing, and sometimes you want that, but to choose C++, you need some other technical requirement that makes it a better fit, or maybe you're working on a mature platform older than Python; you don't just migrate entire code bases on a whim unless you're a Rust engineer.
1
u/Paxtian 3d ago
It's inaccurate to say C++ is more powerful than Python, because both are Turing complete, so anything you can build in one can be built in the other.
That said, C++ gives you much more direct control over what's going on under the hood. So if you need to build something that needs to operate as fast as possible, you'd choose something like C++ or C or Rust.
The downside is, then you as the code author are responsible for handling memory management. Python can take care of that for you. Also, Python has an absolutely massive library of packages, so you can just add them to your package and stitch their functionality together.
But that might lead to bloat if one of those packages depends on 20 other packages to do what it needs to do. So you might prefer to use C/C++ and just implement the specific functionality you need as your own distinct set of packages.
But THEN you need to learn about proper header files and Make and makefiles. So you might say screw it, I'm learning Rust. But THEN you need to learn lifetimes and the borrow checker and async. And that takes a long time and it's a pain.
So then you just learn Java and deal with its cumbersome syntax.
1
u/MasterpieceNovel3619 3d ago
It's much faster (pre-compiles, whereas Python compiles "just-in-time"), has been developed more, and the fact that you have to manage the memory of your variables leads to better understanding and better programming practices.
1
u/AlbertoBigglesworth 2d ago
Why is orange juice better than salt?
1
u/Holiday_Finding_ 2d ago
Compiled languages translate the entire source code into native machine code before execution, resulting in fast execution speeds but platform-dependent binaries and a slower development cycle due to the compile step. Examples include C, C++, Rust, and Go.
Interpreted languages execute source code line-by-line at runtime using an interpreter, offering high portability and rapid development but suffering from slower performance because translation occurs during execution. Examples include Python, JavaScript, and Ruby.
Bytecode represents a hybrid approach where source code is compiled into an intermediate, platform-independent format (bytecode) that runs on a Virtual Machine (VM). The VM typically interprets this bytecode or uses Just-In-Time (JIT) compilation to convert "hot" code paths into native machine code for better performance. Examples include Java (JVM) and C# (.NET CLR).
1
u/Iron_Man652 2d ago
It heavily depends on what you want to do.
1
u/Yarrowleaf 2d ago
Different languages for different things, python is great for back end and scripting and little projects, c++ I use for embedded, don't really like anything else or have needed to for what I like to do. Use whatever you like for the things you like doing
1
u/Medo-2002 2d ago
i think because old than python
1
u/veronique637 1d ago
Try a tiny program in both: make it work in Python, then remake it in C++ and compare what you had to specify. That makes the tradeoff concrete.
1
u/onlyhumaninthehouse 1d ago
In college learn everything. Learn C++ even more because you will not get opportunity to work on it. Learn Python because even kids know it now a days. Learn Rust because that will help humans against AI in future.
1
u/paralepsy 1d ago
as barney starsoup (creator of c++, source: trust me bro) once said: "there are only two types of programming languages; the ones nobody uses, and the ones everybody hates"
1
u/Either-Name-6285 1d ago
Neither is worse or better but as a first year student, C++ made python easier to learn for me
1
u/OldSchoolCSci 1d ago
As many people have written here, "better" depend on your task and context.
However, if the context is "learning programming from the beginning," Python is a good choice because:
I actually had this debate with my son's high school when he lwas taking the intro classes, and they were using Java - which I think is a poor choice for an intro class. His college classes started in Python before moving to C. Intro programming students need to learn the fundamentals without getting bogged down in complex syntax and indirect programming techniques that are often hard for beginners to understand. Once you've learned those things, you can pick up a new language without difficulty. But if you're lost in a "too many rules, too many options" environment, you won't learn the basics well.
1
u/trajtemberg 1d ago
At work we use to prototype in py and deliver in cpp. Nowadays it's all done in Go, even when asm or c is involved.
1
u/Small-Dig-8233 1d ago
just comes down to the access each language gives to u. python keeps things simple by NOT handing u dynamic memory allocation to solve problems related to double freeing, hanging pointers, accessing after freeing kinda errors instead the interpreter does the job for it.
python or really any other interpreted language like JS has this program called a garbage collector and in a nutshell it scans the object tree from the root and what ever is not traced to the root it is freed and now a days its not like this anymore but there are still garbage collector pauses in a program.
C++ is not jst fast but consistently fast AND predictable like a GC pause on python is rare but even a 2ms pause on a physics sim or a kernel can throw things off real quick but in C++ u know EXACTLY when ur freeing memory and how ur freeing memory so everything stays predictable.
now with python around u really dont need C++ for EVERYTHING like prototyping or jst using python as a scaffhold while ur real important code runs in C++ (numpy and pytorch) that is totally fine and its used in machine learning too.
TLDR: the answer is not a clear line that divides python from C++ cleanly saying python is bad and C++ good or vice versa but each has its use case.
1
u/MpVpRb 1d ago
Python is great for quickly creating stuff.
C and C++ run faster, but require more skill to use.
1
u/heisthedarchness 23h ago
"More powerful" does not mean "better" -- and either of these languages could be seen as more powerful than the other depending on context.
Engineering is the discipline of trade-offs, of using the right tool for the job and building a better tool if none that exist have the characteristics you need. We don't have a variety of tools because some are better or worse. We have a variety of tools because we confront a variety of problems.
C++ is better than Python at some things (mostly having to do with efficiency). Python is better than C++ at some things (mostly having to do with safety and portability).
For purposes of learning how programming works, Python is great because it hides a lot of the details of how a computer works. But no one who is serious about the field stops at just one language, just like no carpenter uses only one tool.
1
u/et_theextratestic1e 22h ago
There is no such thing as a programming language that is better than another for every situation.
You're comparing apples to oranges - yes they're both fruit, and that's where similarities stop.
Think of it this way: you can write Python modules in C++, but to do the converse is simply perverse (and very slow). Data scientists like Python because you need to know far less than you do compared to C++. This is normally true when comparing scripted languages to compiled languages (think portability, memory management, etc).
1
u/Wowie-Zowieee 19h ago edited 18h ago
C++ is better than Python in the same way that an airplane is better than a car. Airplanes fly faster than cars, but cars weren’t built to fly in the first place. It all depends on what you need.
C++ was made to be fast and efficient, whereas Python was made specifically to make programming easier. Speed was never the goal for Python.
1
u/bearpaw- 10h ago
Cpp is powerful for being able to do pretty much everything, but it doesn't mean that it is the best tool for every task. Cpp code gets nasty and soon becomes a mine field and you would spend a huge amount of time dealing with landmines. I would prefer Python if I have to focus on algorithm, data, app development. By the way Rust kinda provides pros from the both world, you can use it in a python way (good readability, not as good performance) or Cpp way (performance first)
1
u/BasilKatz 8h ago
Depends what you are doing, I think python is a great general purpose programing language. Lots of people use Java in industry for internal tools or C# and Microsofts .NET framework. I have a friend who programs interfaces for people to interact with large industrial machines.... in UNITY(A Game engine) with C#.
I really love C for programing microcontrollers, It is just a great simple language, but it is by no means the best tool for everything.... it is probably the best tool for very little of what i do, but i like it.
1
u/Fine-Comparison-2949 4d ago
It's not "better" or "worse", and anyone who tells you that really doesn't understand computer science since there are multiple facets to what could be better or worse.
So, C is typically seen as the best for speed. The C compiler assembles the code into machine code, so when you build a C program, it's as raw of a file as you can get in terms of optimization.
Python is "interpreted". You can search this up, but it has it's own Python Virtual Machine, that reads python code (and it's bytecode) and runs it. The virtual machine is somewhat wonky since it's not exactly the same as assembled machine code.
This is also somewhat goofy, because most python code that is dependent on speed, actually wraps C code. The joke about python is it's a C wrapper.
In the end though, most of the speed arguments are silly. For 90% of code, the bottleneck is network speed. Faster code in general does not mean your whole application is fast.
0
u/johlae 4d ago
That's why. C++ can do a lot of things more efficiently than Python, and Python can do a lot of things more efficiently than C++.
It's up to you to figure out when to use what.
0
u/FuggaDucker 4d ago
Python is written in C.
Could have easily been C++.
Think about that.
0
u/flumphit 4d ago edited 4d ago
C++ runs more efficiently than Python, around 100x faster.
Lots of the stuff you might do in Python does all the time-consuming work inside efficient libraries, which are probably written in C++ or C. Often you’ll wind up writing slow Python code to shuffle data between fast libraries, but overall your program spends all its time in the libraries, so it doesn’t matter that your Python is slow.
Python is Turing-complete, meaning you can write any program in it, just like C++. Python is slower, which you don’t usually care about. And Python is loosey-goosey and dwim which makes development faster — until your program gets big enough that you want the compiler rigorously keeping more details straight for you.
0
u/Old_Efficiency2445 4d ago
It;s faster
0
u/geks8 3d ago
Give C a try, that is true programming
-2
u/ninhaomah 4d ago
And OP never replies to any of the posts.
Sorry but this looks like a ragebait post to get human traffic to reddit.
Ask "Why is AI good or bad ? I am very new to AI . Pls help."
And you will get tons of training data.
1
u/MudFrosty1869 1d ago
"My dad could beat up your dad" in programming. Never gets old.