Prefer Domain-Specific Types to Primitive Types

From WikiContent

(Difference between revisions)
Jump to: navigation, search
(New page: One of the main features provided by object oriented languages are abstract data types and strong typing. Still many developers uses the primitive data types offered by the language such a...)
Line 3: Line 3:
As an example, ADA developers can write code that looks like this:
As an example, ADA developers can write code that looks like this:
<code>
<code>
-
subtype Velocity_In_Nots is Float range 0..500;
+
subtype Velocity_In_Nots is Float range 0..500;<cr>
subtype Velocity_In_Km is Float range 0..300;
subtype Velocity_In_Km is Float range 0..300;
V1:= Velocity_In_Knots;
V1:= Velocity_In_Knots;

Revision as of 20:10, 21 November 2008

One of the main features provided by object oriented languages are abstract data types and strong typing. Still many developers uses the primitive data types offered by the language such as String. Wrapping complex data structures as String's are simple as the object method basically can take any data, but its also an unsafe style of programming, where the developer avoids delegating appropriate quality control to the compiler.

As an example, ADA developers can write code that looks like this: subtype Velocity_In_Nots is Float range 0..500;<cr> subtype Velocity_In_Km is Float range 0..300; V1:= Velocity_In_Knots; V2:= Velocity_In_Km; V3:= Float;

With these types defined the statement V3:=V1+V2; will be cached by the compiler.


By Einar Landre


This work is licensed under a Creative Commons Attribution 3

Back to 97 Things Every Programmer Should Know home page

Personal tools