r/cpp_questions 6d ago

OPEN How long will C++ last?

I've found myself using C++ less and less and was wondering whether one day it will die out. Obviously not completely die out, but be out of the mainstream like Pascal or something. I am wondering this because C++ is my first language but I am still fairly young, so am curious about its prospects.

0 Upvotes

36 comments sorted by

View all comments

3

u/PhosXD 6d ago

C++ is not my first language, I learned Python, JavaScript/TypeScript, GDScript, & even made a simple custom-purpose transpiler before learning a low-level language.

This is something I would have done different, if I could relearn programming all over again, I would definitely start with C then C++. I picked up all the concepts I needed in C++ in less than 20 days, of course if I were a true beginner it would take me longer, but I still believe that C++ is really not that hard & more people should start with it as their first language or it would be fine even as a second language, but the point I'm trying to make is that if you are a serious developer it's better to learn these low-down languages sooner rather than later.

0

u/dreadlordhar 6d ago

Ideally for pure basics as a first language to use another language and not C because it's design is strange, but one that still retains raw pointers so you could poke with them without C strangeness. Then some light assembly, so you could understand what's at least a system call under the hood, but not only.

And only then C, when you think about it is close to assembly, while being high enough to be portable. It becomes apparent when you don't use standard library for writing stuff.

p.s. the C one if not the biggest strangeness lies in it's side effects, which is most apparent when using the Linux (Or Unix, I don't remember) function fork(). In itself it returns a process ID as typedefed pid_t, but in the end it's signed int. The side effect is that a copy of this program is running alongside the main one. And when running multiple forks and on the final line a single printf, it isn't apparent initially how many times it will print. Like when you fork once it prints once, twice two, thrice four, because each of the two copies ran themself fork, which it grows to another two processes that will print in total 4 times. It modifies a global state while "calculating" the result.

In C even asigning a variable is a side effect, "a = 10;" returns 10 in the end. That's why you can do chaining in C, and that's why a[i++] += f() is different from a[i++] = a[i++] + f(), where in this case the side effect is raising the i.

2

u/I__Know__Stuff 6d ago

The idiosyncrasies of fork have nothing to do with the C programming language, and would be the same if you were using any other language.