Live data from Hacker News

The type system is a programmer's best friend

dusted.codes

1–10 of 467 posts

Re: The type system is a programmer's best friend

#3
I once attended a meeting where a Professor from a University somewhere in Chicago gave a brilliant demonstration of using a similar type system for dealing with values in Electrical Engineering. It made quite sure you couldn't do things like add volts and amps.

[Edit] it also handled things like parallel resistances, etc.

It was in C++ if I recall correctly.

This is a great idea, that I've haven't had cause to use yet.

Re: The type system is a programmer's best friend

#7
>A string value is not a great type to convey a user's email address or their country of origin.

So we have a type for "country of origin". And then some country that you have in the records splits up into 2 countries, what do you do then? Do you keep a list of all countries that ever existed and keep it up to date?

This approach works good in some cases, but not always

Re: The type system is a programmer's best friend

#8

> ... to prevent silly mistakes like multiplying $100 with £20 Honest question, what should multiplying $100 with $20 give?

Programmers will have immediate answers for you -- stated confidently as if to imply there is a spec somewhere when in fact no spec exists and the programmer you're talking to is peddling their own bullshit as gold.

Re: The type system is a programmer's best friend

#10
post #7

>A string value is not a great type to convey a user's email address or their country of origin. So we have a type for "country of origin". And then some country that you have in the records splits up into 2 countries, what do you do then? Do you keep a list of all countries that ever existed and keep it up to date? This approach works good in some cases, but not always

That's an unrelated problem, that's outside the scope of model presented. Remember the physicists adage: All models are wrong, some are useful.

You can have your name change as well, or your calendar can change, or etc.

Does that mean we stringly type everything? No. You model changes either via a separate field(s) or some kind of change table.

Post reply on HN