Rule A8-4-14 (required, design, non-automated)

Interfaces shall be precisely and strongly typed.

Rationale

Using precise and strong types in interfaces helps using them correctly. A large number of parameters of fundamental type (particularly of arithmetic type) can be an indication of bad interface design as it does not make it obvious what the units are, and there is no way for the compiler to warn when parameters are passed in the wrong order (as the types are the same or implicitly convertible). When several parameters are related, combining the parameters into a separate user-defined type should be considered. Similarly, a type of pointer to void does not provide any type safety and alternatives like a pointer to a common base class or using a (potentially constrained) template parameter should be considered.

Example

// $Id: A8-4-14.cpp 326058 2018-07-16 07:52:31Z christof.meerwald $

#include <cstdint>
#include <chrono>

// Non-compliant: unit of duration not obvious
void Sleep(std::uint32_t duration);

// Compliant: strongly typed
void Sleep(std::chrono::seconds duration);

// Non-compliant: list of related parameters with same type
void SetAlarm(std::uint32_t year, std::uint32_t month, std::uint32_t day,
std::uint32_t hour, std::uint32_t minute, std::uint32_t second);

// Compliant: strongly typed
void SetAlarm(std::chrono::system_clock::time_point const & when);

See also

C++ Core Guidelines [11]: I.4: Make interfaces precisely and strongly typed