4 ms·
I expect it's referring to the newtype pattern; you don't want to accidentally add inches to cm, so if you have to handle both of them a lot, you make a single
by dwattttt 2mo ago
I expect it's referring to the newtype pattern; you don't want to accidentally add inches to cm, so if you have to handle both of them a lot, you make a single field struct Inches and one for Cm.
For containers, you can do this to make it a type error to index the container with anything other than the newtype you made.
In some languages you can replace/implement the indexing operation a[i] with your new type, so the code looks the same as usual, but gets the benefit of preventing the wrong 'integer' from being used.