The authoritative guide for High Quality C++! (Warning: These are all jokes.)

Replying to @OmerFarukDinder
(Just in case someone missed the point: @AffectiveCpp is a humorous account, everything we post is spectacularly wrong.)
4
2
44
Affective C++ retweeted
On x86, the stack grows “down” towards lower addresses. However, this is only true in the northern hemisphere due to the Coriolis effect. In Australia, the stack grows up actually. That’s because they are all looking at their monitors upside down to avoid falling off the planet.
41
361
2,357
Item 80: A typical source of error is (transitively) including the same header file in many compilation units. This is an ODR violation. Instead, make a separate copy of that header file for each source file. #cplusplus #cpp #affectivecpp
2
2
52
Don't do this manually of course, use something like CMake's target_odr_header(<target> ORIGINAL_HEADER_FILE_NAME NUMBER_OF_COPIES)
1
19
Item 79: Choosing the right data structure is critical. Is memset too slow? Consider memunordered_set instead, to avoid the red-black tree in favor of hashing. See also memmap for key/value, mempriority_queue, memstack, etc. (thanks @jfbastien) #cplusplus #cpp #affectivecpp
5
6
57
Item 78: With multiply wrapped objects, such as unique_ptr to optional, if you want to access a member of wrapped object, use the long arrow operator. Instead of v.get()->value().member, do v--->member. @ivan_cukic explains: cukic.co/2017/07/12/the-long… #cplusplus #cpp #affectivecpp
2
3
37
Affective C++ retweeted
Replying to @david_m_stone
But `unsigned const int` is not the same as `const unsigned int` nor `unsigned int const`. For east-const builds unsigned const int makes the high bit read-only. For west-const builds it makes everything *except* the high bit read-only. We rejected central due to the ambiguity.
2
1
26
Item 77: The difference between char and wchar_t is that char is for narrow characters, and wchar_t is for wide characters. Store letters like i and j in a char, and letters like m and w in a wchar_t. (Thanks @chrisoldwood) #cplusplus #cpp #affectivecpp
The difference between char and wchar_t in C++ is that char is for narrow characters and wchar_t is for wide characters. So you’d store letters like i, l, and t in a char but M and W in a wchar_t…
6
62
Affective C++ retweeted
Replying to @ciura_victor
Pro-tip: Commas are quicker to parse than semi-colons because there are less pixels in the character. @AffectiveCpp
2
26
Affective C++ retweeted
Replying to @AffectiveCpp
@AffectiveCpp this is how the professionals structure projects.
Top tip: name your directories well: put all of your template metaprogramming code in a directory called "tmp". Preferably /tmp.

ALT John Cena Reaction GIF by WWE

1
1
8
Affective C++ retweeted
programming protip! when you see x >= 0, that's a handy shortcut for x = x > 0
24
65
883
Item 76: Can't remember all the different casts? Replace them all by the more powerful unicorn_cast: template <typename T, typename U> T unicorn_cast(U&& u) { void* addr = &u; return *static_cast<T*>(addr); } (Thanks @bjorn_fahller) #cplusplus #cpp #affectivecpp
2
2
31
Item 75: For owning pointers, use `int *variable` (star next to the variable you own), and for non-owning pointers use `int* variable` (star away from the variable) (Thanks @olafurw) #cplusplus #cpp #affectivecpp
int* variable; For non owning pointers, since the * is far away from your variable (which you own) int *variable; Then for owning pointers. @AffectiveCpp (ps. don't do this, use smart pointers)
4
3
32
Item 74: std::vector<bool> is widely regarded as a bad idea. Instead, prefer using std::basic_string<bool>, which both behaves as an actual container, avoids proxy objects, and gives you a small vector optimization for free! (Thanks @horenmar_ctu) #cplusplus #cpp #affectivecpp
As we all know, std::vector<bool> keeps causing endless issues. But did you know you can use std::basic_string<bool> instead, avoiding the terrible proxy objects? You even get a small vector optimization for free. 😈
1
10
84
Item 73: If you experience seemingly random crashes and bugs in your software, simply ship it with -O0 to reduce the failure rate. (Thanks @Cor3ntin) #cplusplus #cpp #affectivecpp
1
4
32
Affective C++ retweeted
The other advantage is that it forces you to keep the number of local variables down to a manageable 26 or less.
1
1
14
Item 72: Stick to using single letter identifiers only, this avoids almost all naming disputes. (Thanks @bjorn_fahller) #cplusplus #cpp #affectivecpp
1
1
18
See also Item 1 :
Item 1: Keep your variable names short to save memory. If <=4 characters, they even fit in a register, no slow memory reads! #cplusplus #cpp #affectivecpp
7