97 Things Every Programmer Should Know

(Chris Devlin) #1

Collective Wisdom from the Experts 131


Developers in less demanding domains might also benefit from applying
more domain-specific typing, where they might otherwise continue to use
the primitive data types offered by the language and its libraries, such as
strings and floats. In Java, C++, Python, and other modern languages, the
abstract data type is known as class. Using classes such as Velocity_In_Knots
and Distance_In_Nautical_Miles adds a lot of value with respect to code quality:



  • The code becomes more readable, as it expresses concepts of a domain,
    not just Float or String.

  • The code becomes more testable, as the code encapsulates behavior that
    is easily testable.

  • The code facilitates reuse across applications and systems.


The approach is equally valid for users of both statically and dynamically
typed languages. The only difference is that developers using statically typed
languages get some help from the compiler, while those embracing dynami-
cally typed languages are more likely to rely on their unit tests. The style of
checking may be different, but the motivation and style of expression is not.


The moral is to start exploring domain-specific types for the purpose of
developing quality software.

Free download pdf