Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Coding Standard Nazis

Name: Anonymous 2015-02-15 10:59

http://wiki.wesnoth.org/CodingStandards

Do not use #define for constants
#define foo X is not a typesafe approach to define constants. Instead, you can something like the following (in an anonymous namespace) to achieve the same goal in a typesafe fashion.

Do not use C-style casts
The following code,
if(i->second.side() == (size_t)player_number_) {
is considered bad practice in C++ since a C-style cast is overpowered -- if types change around it could end up casting away constness, or performing an implementation-defined data reinterpretation (basically a C-style cast is a compiler-generated combination of static_cast, reinterpret_cast, and const_cast).

Name: Anonymous 2017-01-18 19:23

>>27
C optimizing compilers make you write unintuitive, slow code to be able to use certain machine instructions,
No, they don't. They encourage programmers to write in a straightforward imperative style, rather than either bit-bashing (which GCC does better than most human programmers anyway) or relying on OOP trash (which is what makes idiomatic C++ so slow). Compilers aren't as dumb as you think they are, they can easily recognize when multiple statements can be optimized into a single CPU instruction.

They say ``C is great because it gives you the power of assembly'' but it doesn't. Assembly lets you do something in one instruction. C makes you use a complicated expression or loop. This makes assembly more powerful than C. Why would you use a so-called higher-level language that makes you write more code than assembly language?
C gives you low-level control as well as portability. Anything that isn't guaranteed to be provided in a rudimentary instruction set is implemented as a library function, so your code can run anywhere. On architectures that do support complex instructions, the function is inlined to an single assembly instruction. Memset() does this on x86, for example. C provides additional program structure that isn't available in asm, asm has no notion of block scope for example, nor does it help you keep track of structs - you have to remember that the field you want is the dword at base + 8, rather than just typing somestruct.somefield.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List