3 ms·
> Other parts are quite simple and well worth picking up, e.g. liberal use of typedefs honest question, why do you think liberal use of typedefs is a good habi
by lentil_soup 6y ago
> Other parts are quite simple and well worth picking up, e.g. liberal use of typedefs
honest question, why do you think liberal use of typedefs is a good habit to pick up?
- mehrdadn 6y agoLots of reasons. It's just something I've learned based on experience. They're essentially free abstractions that confine a source of truth (the type of a variable) to a single location. They codify the abstractions as well. They make it easier to understand the semantic purpose of each type and can make meaningful distinctions when concrete types are the same (e.g. std::vector<size_t> is quite unilluminating compared to, say, 'NameIndices' and 'ValueIndices'). They make it very easy to change types down the road (as the concrete type is now declared in a single location). They give you control over the type inference procedure. And they give you the majority of the benefits of 'auto' without the same pitfalls. That said, I'm not suggesting you use them indiscriminately. 'this_type' and 'value_type' are often useful; 'difference_type' and 'size_type' generally won't gain you anything...