logoalt Hacker News

rfgplktoday at 4:18 PM1 replyview on HN

This is gonna be a long critique, I'll try to keep it concise.

> C-like C++ is good start, if code doesn’t require more complexity don’t add unnecessary C++ complexities.

C is almost obsolete nowadays. Not to mention that C++ is effectively a strict superset of C (nearly 99% of the C standard is in C++) and the few features that aren't are included as compiler extensions (VLA, restrict keyword, nested functions). There are a handful of C features that aren't in C++, and for very good reason (most of them suck). When was the last time you ran into a C library that a pure C++ compiler couldn't compile? Only if someone decided to spam the new keyword all over the codebase (or something similar).

> In general case code should be readable to anyone who is familiar with C language.

Most C++ already is? Even very template heavy C++.

> Don’t do this, the end of “design rationale” in Orthodox C++ should be immedately after “Quite simple, and it is usable. EOF”.

A lot of the methods in that document are necessary to make C++ shine, especially template metaprogramming.

> Don’t use exceptions.

Optional but irrelevant.

> Don’t use RTTI.

.. Why? Reimplementing RTTI in C will give you almost the same overhead.

> Don’t use C++ runtime wrapper for C runtime includes (<cstdio>, <cmath>, etc.), use C runtime instead (<stdio.h>, <math.h>, etc.)

.. Why? Those wrappers all include the "raw C runtime" under the hood (literally they do #include <stdio.h|xx>. Near 0 compiletime overhead?

> Don’t use stream (<iostream>, <stringstream>, etc.), use printf style functions instead.

This is a design decision.

> Don’t use metaprogramming excessively for academic masturbation. Use it in moderation, only where necessary, and where it reduces code complexity.

There are many programs that are _impossible_ to write in a finite time without metaprogramming. How will you (with zero runtime overhead) dispatch a function with a variable arity of random types to a handler that requires exactly that type of function? Arbitrarily? In C++ it's possible, in C it isn't.


Replies

AnimalMuppettoday at 4:59 PM

> > Don’t do this, the end of “design rationale” in Orthodox C++ should be immedately after “Quite simple, and it is usable. EOF”.

> A lot of the methods in that document are necessary to make C++ shine, especially template metaprogramming.

So? Is your goal to make C++ shine, or is it to produce useful, understandable code? My goal is good code, not being a showoff.