News for hackers. Stuff that matters.
Re:The type system is a programmer's best friend by mhaberl on Saturday November 05, 2022 @09:24AM (#33481233)
> You can have your name change as well, or your calendar can change

What do you mean by that?

Having a type for "country of origin" would mean that the type gives you limits on what values it can hold (any country known to ever exist) so you can not say something like:

Country c = "Foo"

because Foo is not a country.

I can't imagine having a type for a persons name that holds checks anything but perhaps a strings length, certainly not a list of all possible names.

The calendar example I don't get. We already have "date" types in almost all languages so that "works", although it can be used as example of how hard is to implement some types.

-----

So I say: >> This approach works good in some cases, but not always

And you say: > Does that mean we stringly type everything?

Come on now. "Not always" does not mean "Never"

Re:The type system is a programmer's best friend by masklinn on Saturday November 05, 2022 @09:31AM (#33481285)
> I can't imagine having a type for a persons name that holds checks anything but perhaps a strings length, certainly not a list of all possible names.

As always, that is very domain-specific: there are lots of countries with naming laws, some of which do have lists of legal names.

Re:The type system is a programmer's best friend by blep_ on Saturday November 05, 2022 @01:50PM (#33483791)
Legitimate question: what do they do about immigration into those countries from countries without such laws?
Re:The type system is a programmer's best friend by masklinn on Saturday November 05, 2022 @02:45PM (#33484368)
Likely nothing: usually they’re laws which applies to parents / birth certificates.

I guess it’s possible that an immigrant trying to get naturalised would have to adopt a “legal” name for the country, but I’m not aware of any country where that’s a rule, aside from the Zairianisation movement of Mobutu.

Re:The type system is a programmer's best friend by Ygg2 on Saturday November 05, 2022 @12:44PM (#33483120)
> What do you mean by that?

I assumed the point was old name wasn't tracked and should be.

> Having a type for "country of origin" would mean that the type gives you limits on what values it can hold

No one said your type has to be completely set in stone and contain every valid value in advance.

Have a trusted store of country name and valid until date. So defunct country can't be added.

Re:The type system is a programmer's best friend by mostlylurks on Saturday November 05, 2022 @03:41PM (#33484854)
Restricting the space of possible values is only one of the possible advantages of declaring a dedicated type for something. Even if it is not possible to restrict the space of possible values (e.g. with names, which can't realistically be restricted to any smaller subset than all possible strings), there are other advantages to having a dedicated type, such as preventing the user of the type from putting a value of that type into somewhere it doesn't belong, which is a very realistic scenario in stringly typed codebases, especially where there are similar but different sets of values, all stringly typed.