Better HN
topnewbestaskshowjobs
Log inSign up

randomprog

6 karma · joined Sep 19, 2015 (11y ago) · 1 submissions

Submissions

comment 11y ago · link · parent

> What's the coordinate system? What are the units?

That information can be encoded into the class type, in which case you get compile time checking. I wrote a blog post about this some time ago:

http://www.randomprogramming.com/2014/06/quote-of-the-week-t...

The summary is that we had two different coordinate systems in play and had many bugs caused by passing values in the wrong coordinate system around. By making the different coordinate systems different classes everything became explicit and checked by the compiler. We completely eliminated a whole class of bugs from our program.

The great thing about using an int is that it can be anything (integer). It can be an x coordinate, or the number of eggs or a selection between multiple options.

The bad thing about using an int is that it can be anything, and sooner or later you will pass the number of eggs into a function that really wants an x coordinate.