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

It's the anti-pattern "Primitive obsession"

https://refactoring.guru/smells/primitive-obsession

Let's say, for example, that we need to handle distances in on our code with different units (meters and inches, for example). I've seen code bases that use integers or floating points for this and it's always confusing and error-prone what is the unit. In fact, you could accidentally use some other values (money) as distances.

Instead, if your programming language allows this, you could define a type Distance and make sure that all the code that handles distances only use this Distance type. Everyone is forced to think about distances when maintaining the code, conversions routines are implemented and instantiated in one place etc.



This is why I like type defs in a language.




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

Search: