Re:Abacist – Calculations with non-decimal units and mixed b...
by nadavwr on Saturday November 30, 2024 @01:34PM
(#42283179)
PHP and JavaScript are dynamic. Here you'll be able to pass distances as feet or meters, but if you try to pass in pounds you'll get a compile time error -- can't do that in dynamic languages :)
[ Parent
| on HN ]
Re:Abacist – Calculations with non-decimal units and mixed b...
by TOGoS on Saturday November 30, 2024 @02:49PM
(#42283587)
So, when I said JavaScript, I really meant TypeScript, and I found its gradual/structural typing system to be the most ergonomic type system I've ever used (if you want nominal types, it's pretty trivial to get there just by adding a compile-time-only tag, like `{ typeName?: "FooType" }`).
In this case, the TypeScript approach might be something like
const distanceInMm : {"mm": Rational} = toMm(distanceInArbitraryUnits);
You can get as specific as you want, without having to wrap/unwrap anything, or even define a new named type. [1]I think I like Scala conceptually--when people talk about it I think "yeah, good idea!"--but every time I've looked at Scala code it struck me as having an excessive amount of boilerplate to wrap/unwrap stuff just to make the type checker happy.
The other bad-tasting thing about Scala is that I wrote a program[2] in it many years ago and then later came back to try to fix some bugs and the language had changed so much that I had to find some old version of it + an old JVM and Dockerize it. Docker's a godsend for this sort of thing, but kind of inconvenient for development.
[1] My notes about this approach in TypeScript: https://www.nuke24.net/plog/32.html