Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Using basic types for domain concepts is called 'primitive obsession'. It's been considered code smell for at least 25 years. So this would be... not being primitive obsessed. It isn't anything driven development.

Different people draw the line in different places for this. I've never tried writing code that takes every domain concept, no matter how small, and made a type out of it. It's always been on my bucket list though to see how it works out. I just never had the time or in-the-moment inclination to go that far.



I think often times it's enough to have enums for known ints, for example and have some parameter checking for ranges when known.

Some languages like C++ made a contracts concept where you could make these checks more formal.

As some people indicated the auto casting in many languages could make the implementation of these primitive based types complicated and fragile and provide more nuisance than it provides value.


Yep! I recently started playing with Ada and they make tightly specifying your types based upon primitives pretty easy. You also have some control over auto conversion based upon the specifics of how you declare them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: