From a math perspective, programs seem to boil down to calculations, stored values and conditional logic. Beyond different syntax, what makes a language like Python easier to use, or C++ faster?
What does it really mean for one programming language to be easier or faster?
Answers
Think of different ways to express the same mathematical idea. You can expand a sum term by term, or use summation notation. Both describe the same result, but one might be much easier to write, check and change.
Languages provide different abstractions. Python gives you convenient built-in collections and manages memory for you. In C++, you have more choices about how objects are represented and managed, which can be useful but also gives you more to learn and more ways to make mistakes.
So easier often means less work between the idea and a working program, not just fewer brackets.
Reply to this answer
Faster usually means a particular implementation takes less time or uses fewer resources for a particular task. It is not a universal ranking of languages.
For example, a loop over ordinary Python numbers involves operations on Python objects and runtime overhead. C++ can compile a loop over suitable numeric types into machine code with much less overhead. But a Python program using an array library can spend most of its time in optimized compiled code, so the Python syntax alone does not tell you how fast the calculation will be.
Algorithms, data layout, libraries and the amount of data matter too. Compare actual programs on the workload you care about.
4r+velum-cabinet:
And faster to run is different from faster to write. A simulation that takes minutes to code and seconds to run may be preferable to one that saves a second but takes much longer to develop.
Reply to this answer
The language is only part of the package. For calculations, check whether there are good libraries for the arrays, numerical methods and plotting you need. A useful library can save far more effort than a small difference in syntax.
Python is a reasonable starting point for many mathematical tasks for that reason. C++ may be a better fit when you need more control over performance or memory, though it comes with a larger language to learn.
Reply to this answer
Languages also differ in what kinds of mistakes they catch and when. Some check more type information before a program runs. Others allow more flexibility and discover certain errors during execution. Neither approach removes the need to test whether your calculation is actually correct.
Those choices affect how you design and change a large program. The toy examples in beginner tutorials can make languages look much more alike than they feel on a substantial project.
Reply to this answer
Even numeric behavior can differ. Languages offer different numeric types, and the type you choose affects things like precision, range and whether arithmetic can overflow. The way arrays and their elements are stored can also have a big effect on memory use and speed.
Two programs can look like they are doing the same math while making different tradeoffs about representation. That is worth checking before comparing their results or timings.
Reply to this answer
Add your answer
Answers are reviewed before publication.
v.683~drain-harbor:
That helps. So the useful comparison is partly about what details I have to keep track of while expressing the calculation?
7m!thimbleorbit_846:
Exactly. It also includes how easy the resulting code is to read and modify when the calculation gets more complicated.