News for hackers. Stuff that matters.
Re:Typing Is Hard by jbluepolarbear on Wednesday February 17, 2021 @01:41AM (#26163433)
Typescript taught me that I actually don’t care about types and all I care about is the shape of data. In most cases I think of types/interfaces in Typescript as strict data definitions. A function takes in a collection of data; as long as the data matches the shape I expect, don’t care what the data represents.
Re:Typing Is Hard by adwn on Wednesday February 17, 2021 @03:12AM (#26163919)
> Typescript taught me that I actually don’t care about types and all I care about is the shape of data.

Seconding leafario2 here, that's exactly what types do: They give guarantees about the shape of data.

Maybe what you meant was you don't care whether an object is of type Customer or Supplier, as long as it has an element/field named address. That's called "structural typing" (as opposed to "nominal typing").

Few static type systems have structural typing, probably because in practice, you actually do care whether the object is a Customer or a Supplier, even if their fields have the same names. Rust, for example, is nominally typed, but you can define a trait "HasAddress" with a trait function "fn address(&self) -> &str" and implement it for Customer and Supplier, to simulate structural typing where you need it.

Re:Typing Is Hard by jbluepolarbear on Friday February 19, 2021 @01:33AM (#26190379)
I don’t know if I do care that customer is or isn’t a supplier. I have been using Nominal type systems in C++ and C# for a long time and I’ve started drifting into an architecture style that leverages interfaces as my types which I just learned is structural typing. I really liked the concept in Golang and then I really started using it in TypeScript and got hooked. It makes so many programming problems easier to implement, maintain, and understand. I now mix and match nominal and structural types in my projects, using them where they best fit.
Re:Typing Is Hard by seanmcdirmid on Wednesday February 17, 2021 @03:28AM (#26164041)
What you use the word “type” for is a nominal type and your shapes are structural types. The utility and different trade offs between nominal and structural types were explored a lot back in the 90s.
Re:Typing Is Hard by eevilspock on Wednesday February 17, 2021 @05:00AM (#26164701)
Nominal types are on Typescript's roadmap: https://github.com/Microsoft/TypeScript/wiki/Roadmap

Side note: An Introduction to Nominal TypeScript: What are nominal types and why should I use them? : https://medium.com/better-programming/nominal-typescript-eee...

Re:Typing Is Hard by jbluepolarbear on Friday February 19, 2021 @12:58AM (#26190215)
This is awesome.
Re:Typing Is Hard by jbluepolarbear on Friday February 19, 2021 @01:13AM (#26190285)
Thanks, I don’t think I learned the about these concepts in college; granted, I dropped out because I am ADHD to the max. I usually adopt or adapt what I observe in others code, my old code, or idea from other fields entirely. I like to adapt and improve techniques I see and fit them best into my projects.
Re:Typing Is Hard by Sharlin on Wednesday February 17, 2021 @03:39AM (#26164123)
Everything old is new again.
Re:Typing Is Hard by leafario2 on Wednesday February 17, 2021 @02:12AM (#26163602)
That's exactly what types are for dude