Parse, Don’t Validate
Haxe has a nice mechanism to handle this called "abstract types".  https://haxe.org/manual/types-abstract.htmlThe critical validation step happens when the abstract type is created, not when it is used or passed to other functions...similar to the example in TFA.The added benefit is that you get a type that behaves pretty closely to a class, but adds no typing or runtime memory overhead.  E.g. here's an example for an "unsafe" string : https://gist.github.com/jdonaldson/9a09287e540e7392857fAnother benefit is that you abstract types can define relationships between multiple types in this way, making it possible to perform validation for functions that need to handle "Either"-style types.