Comment

Comment by nucleardog

Any sort of language that allows you to define custom types (e.g., objects) and type-hint parameters allows you to do this. You can accomplish this same thing in PHP even (the type checking is at runtime, but same idea).

Types are not restricted to just a description of how the data is represented in the computer, otherwise we would need nothing but primitives.

When you perform calculations with physical measurements containing units you don't simply throw away all of the type information while performing calculations -- you perform the same operations on the units both as part of the answer and as an essential check that you've done the right thing. You should do the same thing with your data.

See, e.g., https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...

parent nucleardog 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton