Skip to content

Learn the basics of Assembly and Inline Asm

Posted on:July 20, 2023 at 11:22 AM

Why some people like C, but despise C++? That is a very good question. As I am part of this category, I can explain why this phenomenom happens.

While C and C++ are almost identical to the basic stuff, C++ adds layers of complexity to it. First, you have classes, which are the core difference between C and C++. They are similar to structs, but have more features than them. And these features can make someone confused, they might ask “how does polymorphism work?” or “what are virtual constructors?“. Operator overloading is a whole new concept to C++, that makes the language more flexible. For example, instead of having

complex c1, c2;
cout << c1.add(c2);

you can basicly do

complex c1, c2;
cout << c1 + c2;

Even in the first example there is operator overloading. The operator << is very important for sending data to output.

If you make a function in C that divides two numbers and want it to work for ints, longs and doubles, you would need to copy and modify the same function but with different params or use a Generic. Here is where you learn about templates. They look a bit strange, but if have worked with vector or just any container, you may be familiar with it.

If you have reached thiss step, you probably didn’t have any major problems with it, maybe here and there, but nothing truly hateable. Now, continuing with C++ versions, there are additions to the language every time, which often adds complexity instead of solving it. For example, a piece of c++ code might look like this:

for (std::map<std::string, double>::iterator it = studentGrades.begin(); it != studentGrades.end(); ++it) {
        std::cout << it->first << ": " << it->second << std::endl;
    }

If you are familiar with the knowledge this is easy, but iterators look strange at the first view.

std::transform(numbers.begin(), numbers.end(), numbers.begin(), [](int num) {
        return num * num;
    });

Here you may wonder, what is the syntax that starts from [](int num), but this is called a lambda function, which many don’t use or even know about.

auto squaredEvens = numbers | std::views::filter([](int num) { return num % 2 == 0; })
                                | std::views::transform([](int num) { return num * num; });

Here the things look even more strange. What the bar symbolizes, it is a pipe operator, an “or” gate or what?

And now you know the harsh truth about c++. you can ignore this and use just a part of its features, because nobody is required to use them all. Sometimes is better to use a simpler structure for efficency and for readability.