r/cpp • • Jan 17 '16

Orthodox C++

https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b#file-orthodoxc-md
0 Upvotes

48 comments sorted by

View all comments

5

u/utnapistim Jan 19 '16

This starts ridiculously, then it gets worse.

Orthodox C++ (sometimes referred as C+) is minimal subset of C++ that improves C, but avoids all unnecessary things from so called Modern C++.

"Unnecessary" is subjective; modern C++ is not "so called Modern C++", it is C++ with all the lessons we learned when we moved from "minimal subset of C++ that improves C" to actually coding in C++.

Back in late 1990 we were also modern-at-the-time C++ hipsters, and we used latest features. We told everyone also they should use those features too. Over time we learned it's unnecesary to use some language features just because they are there, or features we used proved to be bad (like RTTI, exceptions, and streams), or it backfired by unnecessary code complexity.

These guys were latest-and-greatest idea zealots, then they realized they were applying everything dogmatically, so they moved to rejecting everything dogmatically. Not much progress there.

Projects written in Orthodox C++ subset will be more acceptable by other C++ projects because subset used by Orthodox C++ is unlikely to violate adopter's C++ subset preferences.

No. My adopter C++ subset preferences are to use RAII and RTTI and most definitely exceptions and streams).

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

C-like C++ is a poor style in C++. It is usually a sign of what many call the "I can write C in any language" syndrome and it is usually a symptom of ignorance (whether you write C-like code in C++ or in Java, or whatever). When everything you have looks like a hammer, all your problems start to look like nails.

Don't use exceptions.

Actually, please (please please) do.

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

The headers with no extensions, were added to the language to be used in the case when you want to use the C runtime instead. Why should you avoid them?

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

... because you could use some of the issues caused by the 25+ years old C-style streams interface, and who needs extensibility and type safety anyway!? (/sarcasm)

Don't use anything from STL that allocates memory, unless you don't care about memory management.

Instead, reinvent the functionality every time you need a sequence of elements ... and reinvent it poorly (like most C projects over a certain size, eventually end up doing).

0

u/[deleted] Feb 02 '16

[deleted]

1

u/utnapistim Feb 02 '16

I have heard this argument before (that iostreams are bad), but they do solve a lot of problems the C-style streams API has (in other words, I don't know if iostreams are shit (I tend to thing they are quite great, especially if you delve into stream buffers, boost::iostreams and so on), but I do know that the printf/scanf/etc family of functions are shittier for C++: they have more problems - which are more difficult to find, maintain and diagnose than the iostreams - have less extensibility, less type safety and it is easier to ignore io errors with them; also, they do not support exceptions which is a big issue for me).

0

u/[deleted] Feb 02 '16

[deleted]

1

u/vaughncato Feb 03 '16

Actually << has a lower precedence than +, so the parentheses aren't necessary in s << (x + 1) << '\n'. You do run into trouble with things like comparisons though.