Practices - Typedefs

Typedefs should be used only where it is absolutely necessary.

Rationale: typedefs seem like a good idea to hide implementation details, but in reality code is programmer's tool and it makes no sense to describe screwdriver as a “red_tool_thingy”.

Avoid typedef in a public interface. Use 'auto' variables to hold return values of functions when those values have difficult type.


Typedefs introduce another level of abstraction to the user of the interface, making it less obvious.

Typedefs introduce another term which needs to be understood

Typedefs need to be looked up, which adds tedium.

Typedefs also give the implementer of the interface a false impression that the typedefed construct can be changed ( after all it has an opaque name ), but since typedefs need to be looked up, they bind just as strongly as their underlying type.

Typedefs may be typedefed, thus squaring the problem.

Typedefs can be used only where the language syntax requires them ( think: BOOST_FOREACH over stl containers ), or when a construct they hide is really complex ( boost::multi_index_container with several containers may grow to several lines for example ).