| Ada does a great job in this regard. Using some examples in the article: >> For example, say that you want to represent the number of books ordered. Instead of using an integer for this, define a class called Quantity. It contains an integer, but also ensures that the value is always between 1 and 240 The Ada code to implement this is: type Quantity is new Integer range 1 .. 240; >> instead of just using a string, define a class called UserName. It contains a string holding the user name, but also enforces all the domain rules for a valid user name. This can include minimum and maximum lengths, allowed characters etc. The Ada code to implement this is: with Ada.Strings.Bounded;
package UserName is new Ada.Strings.Bounded.Generic_Bounded_Length (Max => UserName_Max_Length); Dynamic predicates or even a string subtype could be used to further refine the UserName definition depending on exactly what restrictions are needed. While it's not perfect, Ada does make it pretty easy to specify constraints on data types and will complain loudly when the constraints are violated. |