One trick to make readable C++ code is to simply pretend you are coding in C, at all times, and then pull in a feature here and there (very rarely) from C++. So your code looks basically like some kind of semi-advanced plain C. This is called using a small subset of C++ which no one actually does, but should.
Again, as I said in an article elsewhere, this is basically (kind of) what Scintella/Scite has done - it's simplified C++ code. But you could take it even one step further than that and not even use the amount of features that Scite/Scintella uses from C++.
Another example is all the MSDN documentation jokingly say "C++ example", when referencing code. But it should say "C example" often, as rarely do the examples actually look like C++. When you read the so called C++ example code snippets, it's not really C++ but basically plain C code, with maybe a few features once in a while from C++, but often not. Why are they educating people using non C++, in their C++ examples (after all, documentation of API's is all about educating the users of the api, the programmers). Why aren't the examples littered with advanced C++ techniques? Joke Answer: no one needs C++ advanced features, Microsoft itself didn't, because microsoft writes all their C++ code in plain C, or something that looks strangely like plain C but they call it C++, even though it isn't.
Example of how to write clean C++ code (good jokes for the taking):
- write in Plain C but use C++ strings when you don't want to fuck up your screen
with pointer to char allocations... avoid all C++ features except strings
- write a new language called "C with strings". Call it "GoLang" or "PHP3" but be
warned that this programming language name is already taken
- if you ever use objects in C++, pretend they are C functions with a prefix.. don't
use any of the OOP features except for the prefix itself, i.e. just use methods of
objects, but no other features in OOP. No one does this, but should.
Scite/Scintella comes really close here, but I have not inspected it enough.
- The MSDN documentation that uses interfaces is riddled with this basic style of C++
code that looks like C with methods (not C++), but they call it C++ anyway.
Interfaces are basically structs with methods, and sometimes the samples just use
interfaces to call methods and use no other features of OOP other than calling the
method - readable, easy, simple - kind of like C code that does not use advanced C
features or tricks.
Well, thanks, and Fuck C++, and more importantly, Fuck You.
|