Step 65: Prefer Domain-Specific Types to Primitives~

Birat Rai
2 min readMay 22, 2019

--

This is the 65th Step towards gaining the Programming Enlightenment series. If you didn’t learn the 64th Step, read it.

Data Types

What is Primitives?

It is a basic type of data type provided by a programming language. We can create more complicated using these basic types. Examples, int, float, boolean, etc.

What is Domain-Specific Types?

Also known as Abstract Data Types. These are the more complicated data types that are constructed using the primitive data type. The class represents the Domain-Specific types in modern languages. Example; VelocityInKnots, DistanceInNauticalMiles, UserAge, UserSex, etc.

Why use Domain-Specific Type?

  • 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 compiler gives an error for statically typed languages whereas, unit tests will help for the dynamically typed languages.

TL;DR Start exploring domain-specific types for the purpose of developing quality software.

--

--

Birat Rai
Birat Rai

No responses yet