Continuing the series! Feel welcome to dip in and weigh in on a past question.
Let's say I've never used C++ before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.
Continuing the series! Feel welcome to dip in and weigh in on a past question.
Let's say I've never used C++ before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.
For further actions, you may consider blocking this person and/or reporting abuse
Oh, well... May I change the question?
It is at least 20 years since last time I coded in C++. Maybe something changed; nevertheless, let me summarize my memories about it in two short phrases
I still remember the somersault with twist that I had to do to define a friend function of a template class...
It has been a long time, but some of the things that I remembered that I did not like
#include
that physically (rather than logically) embeds the included file. This has as consequences#ifdef INCLUDED
hack.use namespace
in an header file, you pollute the namespace of whoever includes youYeah, quite a lot. I respectfully submit that you learn modern C++ before commenting β unless you, for example, think comments about life in Italy under Mussolini's rule are still valid. Maybe something has changed in Italy since 1943?
Well, it was pretty clear that my remarks were about the old version.
Although I have some difficulties to imagine how many of the defects I remember can be solved in new releases. Usually languages add features with time and drawbacks due to some issues in the original design (in this case, inheritance from C, obscure template syntax, automatic casting, type system C-like, ...) are difficult to solve because of the need of back compatibility.
Anyway, now I am curious and maybe I'll give a look to the new version, although I do not anticipate I will move to it soon.
"You must use the ugly #ifdef INCLUDED hack."
For this you have the non-standard "#pragma once", supported for most of modern compilers.
If you develop / deliver a library, you'd still better use old and nice
#ifndef
.And really modern compilers don't even need that.
I have a love hate relationship with C++.
There's many things I could say about why I hate C++, but that's not what you are asking for.
One of my mentor who taught me C++ during my school days, used to say:
Other than that, It has been 10 years I last wrote C++ during my college days, Few years ago, I was watching a youtube video on C++ and didn't know about
auto
type, and many other functionalities.I am not qualified enough to pitch for C++ but I am subscribed to following channels to keep me updated on the new features of C++ programming languages. So for anyone interested:
Horrible. That's like saying you're a bad builder because you're using machines for building a flat instead of putting bricks on top of each other.
No. He was not saying that. He was saying, you are not bad builder because you are using machines, you are bad builder if you are using machines, without understanding the basic concepts like how to put bricks by hand. Because sometimes, to get something done properly, you need to use your hands.
He was a great teacher. And often used these types of jokes to keep us interested in Maths and programming.
First of all, we were in middle-schools, (5-7 class) in mid-90s in India. He wasn't insulting us or the languages. This joke made us focused on practical stuff, not just whats in syllabus. We wanted to learn about basics of programming instead of just satisfied with examples at back of our books. And our syllabus didn't cover a lot of concepts.
And we conceptually wasn't wrong, Memory management in C++ is relatively easier than C, but the amount of control that C provided meant that your skills can directly impact the quality of resultant code.
That's okay, you should know the basics before you start using more advanced tools.
That's right, but on the other hand, C++ is much more complex language considering it has templates and other advanced constructs compared to C.
It is an old language that is still very popular. This means 2 things:
Best Language for Perfomarce, Low Level Programming, Memory Management, Constraint on Object Oriented Programming and a Good Standard Library with so many function.
Obviously there is a minimum requirement... some years of experience and a good knowledge of the language, in the other cases there are a lot of possibilities to do worse than other languages.
C++ has a rich past and a bright future.
Its past 40 years showed its value when it comes to writing low-level performance-critical code.
Its past 10 years also showed that it's not an old language staying with us for legacy reasons. The industry receives a new version every three years based on the rigorous processes of the standardization committee. These versions brought us things such as smart pointers or concepts that help us write similarly performant but easier to read, easier to write code as before.
The predictable schedules, the new features already in the pipeline and the rich ecosystem guarantee that C++ will stay with us for a long time not only as a must-use but as a want-to-use language.
If you like C#, imagine if the compiler automatically inserted "using" for you. You never needed to remember to write it. C++ does that.
Lots of C++ features are about letting developer hide complexity (almost always from the caller). When used correctly, the higher level ("business logic") code can use instances of types and safely assume that they are doing the right thing. You can then compose those solutions to build up the actual solution that you're trying to do, relying upon each component to do the right thing. (This is not possible in garbage collected languages because you never know when or if the garbage collector will run.)
For a concrete example, imagine that you are writing a program that records your screen while a window is up.
In other languages, you will need to remember to stop the recording, otherwise you will corrupt the file. There may be several ways that the window can close, so you will need to make sure that function is called in every possible control flow.
In C++: Make the handle to the video recorder a field of the window (NOT the memory address of the handle, but the actual handle itself). When the window gets destroyed, it will destroy all fields. If the person who wrote the video recorder made sure to stop any pending recordings when its handle is destroyed, then the compiler will automatically call stop. When the window instance is destroyed, the video recorder has no-where to live, so it is destroyed, and its destruction process safely stops the recording.
The caller didn't need to think about this, even if a (normal) error is encountered.
(Normal error meaning that your program is still in control of execution. It won't help you if the OS forcibly stops your execution, or you encounter a power failure, etc. Basically, if a "finally" would have helped you in another language, then you can rely upon C++ just doing the right thing without the caller needing to remember anything.)
able to write cross platform libraries that you can share almost everywhere - mobile, backend services, various desktop OS's.
IMHO, that is not completely true, to not to say absolutely not true.
With electron, react-native, react, and node, a js library might have further reach.
And what is the relation of that with C++ being "able to write cross platform libraries that you can share almost everywhere...". Each version of each library will need its own different C++ code base, more if they use UI, that is completely different and incompatible between platforms.
I just remember that one company that I worked at had an engine that would compute locations for items, and they wanted to share that engine between desktop apps and mobile apps. There was no UI in the engine. So, they ended up implementing it in a subset of c++ to be able to use the same source code for the engine in those disparate locations. I wasn't directly involved.
I was wondering if they would use js today.
I've never written C++ so I'll be following this thread with excitement!
Hit the comment subscribe button if you haven't! Not everybody knows how that works, but it's great for threads you care about.
Today I Learned. Thanks, Ben!
It's the oldest language in this series by a good margin. In a way, it fits in more places and teaches you more about certain programming fundamentals than more novel languages.
I mainly use C++ for competitive coding or DSA practice. Its huge STL library support is what drives me to explore this language more and more.
You can build IOS, android and desktop (mac, linux, and windows) with one code base and framework. This includes the UI!