An Introduction to C++
A Quick Look into C++
C++, developed by Bjarne Stroustrup in the 1980s, is one of the most commonly used programming languages today. To this day, C++ is standardized by the WG21 committee at the International Organization for Standardization (ISO), and they are currently in the process of developing the next standard, C++ 23.
Unlike Python which is an interpreted language, C++ is a compiled language, meaning that a compiler is used to turn C++ code into binary code that computer processors have an easier time interpreting. There are many different compilers that exist and often depends on your computer's processor. In my case, my computer is a Mac so it uses Clang, and there are GNU and Intel compilers for Linux and Windows systems. Although compilation is typically said as though it is one step, there are actually two steps involved in compiling a C++ program: compiling and linking. The first step, compilation, is the process of turning code that we write into machine language. The second step, linking, involves taking the machine code that was compiled and combining them into an executable program or a single library. Because compilers can compile through whole files and programs all at once without the need for an interpreter, C++ has the benefit of being a faster coding language to process.
However, C++ is a little bit less flexible than Python. For example, while types are not that strict with Python and are often alterable, that is not the case with C++. You must declare a type when defining a variable, and that type cannot change.
Syntax
int main(void)
{
std::cout << "Hello world!" << std::end1;
return 0;
}
Visually, we can see that C++ code looks a little different from Python code. First of all, before the name of the function is the type that the function returns, int in this case. In addition, rather than depending on tabs and spacing like Python does, C++ relies on curly brackets for structure. Technically, as long as you have brackets you could write this all out in one line, although not recommended.
int main(void)
{
for(int i = 0; i < 5; i++)
{
std::cout << i;
}
return 0;
}
Just like Python, for loops and while loops exist. Instead of Python's (for i in range(5)) where i is incremented within the for loop, C++ for loops are written as above.
Discussion
Because Python is overall simpler to write and small sections of code can be edited and checked anytime without the need to compile, I'd imagine Python is more often used in projects that involve a lot of prototyping and implementing new features. However, because Python does not have strict type interference like C++ does, it is potentially more prone to error.
C++ seems to be best suited for projects that are close to the hardware, like back end code. Because of the lack of the interpreting step, its speed as well as its use of strict types provide higher performance and reliability necessary for back end development and other projects that need reliable computation.
A potential project could mix both languages by relying on C++ for complex calculations or for creating modules that the Python part of the project can access and use for itself. This way, you can essentially create a reliable library for your Python code to use.
While there are less integration points for the Riemann Sum compared to Monte Carlo, this is only really good for integrals without a lot of dimensions. Monte Carlo is really helpful when trying to solve integrals that are super complex with multiple dimensions because there would be a LOT of points to compute. Therefore, for simpler integrals without many dimensions to consider, Riemann Sum is nice to use, while Monte Carlo is great for estimating higher level integrals.