Ascii matters

bearophile bearophileHUGS at lycos.com
Thu Aug 23 04:25:08 PDT 2012


Sean Kelly:

> Gotcha.  Despite it being something I'd use regularly, I 
> wouldn't want this in Phobos because it seems like it could 
> cause maintenance problems.  I'd rather explicitly cast to 
> ubyte as a way to flag that I was doing something potentially 
> unsafe.

What's unsafe in what I have presented? The constructor verifies 
every char to be in 7 bits, and then you use the new type safely. 
No casts, and no need to flag something as unsafe.

This usage of types to denote capabilities is quite common in 
functional languages, see articles I've recently linked here as:
http://tomasp.net/blog/type-first-development.aspx

Bye,
bearophile


More information about the Digitalmars-d mailing list