Remix.run Logo
strawhatguy 2 hours ago

The alternative is one type, with many functions that can operate on that type.

Like how clojure basically uses maps everywhere and the whole standard library allows you to manipulate them in various ways.

The main problem with the many type approach is several same it worse similar types, all incompatible.

fiddlerwoaroof 2 hours ago | parent | next [-]

Yeah, there's something of a tension between the Perlis quote "It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures" and Parse, don't validate.

The way I've thought about it, though, is that it's possible to design a program well either by encoding your important invariants in your types or in your functions (especially simple functions). In dynamically typed languages like Clojure, my experience is that there's a set of design practices that have a lot of the same effects as "Parse, Don't Validate" without statically enforced types. And, ultimately, it's a question of mindset which style you prefer.

strawhatguy 2 hours ago | parent [-]

There's probably a case for both. Core logic might benefit from hard types deep in the bowels of unchanging engine.

The real world often changes though, and more often than not the code has to adapt, regardless of how elegant are systems are designed.

packetlost 2 hours ago | parent | prev | next [-]

I don't really get why this is getting flagged, I've found this to be true but more of a trade off than a pure benefit. It also is sort of besides the point: you always need to parse inputs from external, usually untrusted, sources.

doublesocket 2 hours ago | parent [-]

Agree with this. Mismatching types are generally an indicator of an underlying issue with the code, not the language itself. These are areas AI can be helpful flagging potential problems.

Rygian 2 hours ago | parent | prev | next [-]

This sounds like the "stringly typed language" mockery of some languages. How is it actually different?

an hour ago | parent [-]
[deleted]
marcosdumay 2 hours ago | parent | prev [-]

There are more than two alternatives, since functions can operate in more than one type.