Assignability vs. Data Member Types

/177

  • Tip of the Week #177: Assignability vs. Data Member Types
    https://abseil.io/tips/177

    Originally posted as TotW #177 on April 6, 2020

    By Titus Winters

    Updated 2020-04-06

    Quicklink: abseil.io/tips/177

    When implementing a type, decide on type design first. Prioritize API over implementation details. One common example of this is the tradeoff between assignability of a type vs. qualifiers for data members.

    Deciding how to represent data members

    Imagine you are writing a City class, and discussing how to represent its member variables. You know that it is short-lived, representing the city as a snapshot in time, so things like population, name, and mayor could conceivably be const - we aren’t going to use the same object in a given program for years and years, so we don’t need to account for changes in population, new census results, or elections.

    Should we have members like (...)