Three Things in C++ that are Improvement over C

I am not a great C++ fan: the language is overly eclectic, and, what is worse, it has an army of zealots unaware of alternative approaches to SW design, like multi-language paradigm.

But, if asked of just three things that make C++ a better base for writing stuff than plain C, I will say: namespaces, exceptions and templates. Not classes/OOO suff, mind you - C already has it in the same proportion, it is just that some zealots are unaware of it (see, e.g., Linux kernel).

  1. Namespaces. As one who is bound to crawl through a pile of symbol name prefixes of C added for the sake of avoiding names collision and pollution, I would gladly have a more structured solution of C++ namespaces. As it is written in the “The Zen of Python”: “Namespaces are one honking great idea - let’s do more of those!”
  2. Exceptions. While not always the best way to handle situations in code, the non-mandatory nature of them in C++ makes them very desirable; it is worse (different) in Java, but, well, yeah. Being able to choose sometimes if (errorcode != 0) {}, sometimes to throw Exception is convenient.
  3. Templates. Essentially a much-much better alternative to plain old macrodefinitions, visible to compilers, debuggers etc. As one who has to regularly drag through a five or so levels of expansions of macroses used to parametrize on very common thing, being unable to see what the heck it is evaluated to in debugger, I am sure that a templatized approach would save a lot of headache. If only the syntax for them would somehow be more compact - I saw cases when a template with specialization description did not fit on two screens, being longer than half a meter in normal-size font!

Written by Grigory Rechistov in Uncategorized on 20.02.2016. Tags: c++, holywars, namespaces, whining,

Copyright © 2020 Grigory Rechistov