Re:Software Entropy
by cetra3 on Wednesday June 24, 2020 @11:53PM
(#23636739)
I've found rust really helps out with this, enforcing some strict rules around types.
I had to implement a `Lowercase` type which is just a string that can only be lowercase (for case insensitive searches). After implementing standard traits like `Into` and `Deref`, it just acted as a standard string. That way I could guarantee at compile time that things are lowercase, but still have the flexibility of strings.
Another common idiom I have seen is to compose finite state machines using enums. You can only create a particular state from another state etc..
I had to implement a `Lowercase` type which is just a string that can only be lowercase (for case insensitive searches). After implementing standard traits like `Into` and `Deref`, it just acted as a standard string. That way I could guarantee at compile time that things are lowercase, but still have the flexibility of strings.
Another common idiom I have seen is to compose finite state machines using enums. You can only create a particular state from another state etc..