DEV Community

Discussion on: Pitch me on C++

Collapse
 
pinotattari profile image
Riccardo Bernardini

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

  • C++: an OOP giant with clay feet inherited from C
  • C++: the power, the simplicity, the elegance and the safety of an hand grenade without pin.

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

  • C-style #include that physically (rather than logically) embeds the included file. This has as consequences
    • You must use the ugly #ifdef INCLUDED hack.
    • If you use a use namespace in an header file, you pollute the namespace of whoever includes you
  • Template syntax too compact and obscure. Friends of class templates.
  • Automatic template expansion. At the time it looked like something cool, but with time I grew suspicious of compilers that try to be too smart. I prefer to write one line more to be sure to avoid obscure bugs.
  • Syntax a bit stricter than C, but not enough. Type system quite weak with automatic casting, still better than the "convert everything to everything else" of JS or PHP, but still too permissive for my tastes.
Collapse
 
pauljlucas profile image
Paul J. Lucas

t is at least 20 years since last time I coded in C++. Maybe something changed ...

Yeah, 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?

Collapse
 
pinotattari profile image
Riccardo Bernardini

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.

Collapse
 
rfog profile image
rf og

"You must use the ugly #ifdef INCLUDED hack."

For this you have the non-standard "#pragma once", supported for most of modern compilers.

Collapse
 
pauljlucas profile image
Paul J. Lucas

And really modern compilers don't even need that.

Collapse
 
aregtech profile image
Artak Avetyan

If you develop / deliver a library, you'd still better use old and nice #ifndef.