4 ms·
Is it only me or this sounds a bit counter to clojure philosophy?
by ndr 3mo ago
Is it only me or this sounds a bit counter to clojure philosophy?
- erichocean 3mo agoIt's 100% opt-in at the call site and doesn't affect existing code, so no? Many people (including myself) already have checked key variants for maps; this mainly extends the syntax to destructuring too.
- rads 3mo agoThe maps are still open to new keys even if some keys are checked. I think that fits in with how clojure.spec and Malli work already, but in a lighter syntax.
- codemonkey-zeta 3mo agoThe maps haven't changed at all, this is a feature at destructuring sites.
- rads 3mo agoSorry if I wasn’t clear, I was referring to the maps that are being destructured.
- summarybot 3mo agoAs a Clojurist the standard pattern for ensuring keys-are-set before doing-something is not-as-elegant-as-this. Clojure is full of macros that do useful things :) Simplifying oft-used patterns into compact representations is very on-brand. Plus, you need this like, all the time. This will eliminate two whole classes of errors: 1) where keys are supplied a value at an undesired nesting-level. 2) where keys are not-yet-set for some other reason. For the many programmers who have to write in checks and verifications themselves for this, this saves quite a bit of time, removing the interruption from coding and restoring the flow of getting logic-to-symbol.
- embedding-shape 3mo agoSeems additive to me; no breaking changes, and better control and error messages when opting in for it, seems entirely Clojurely to me.
- bcrosby95 3mo agoHowso?
- ajmoon 3mo agoI agree it feels a bit counter to the philosophy of Clojure. It's adding new syntax to the language for map destructuring only (that will need to be implemented in cljs and other runtimes for consistency) and it's a purely runtime check as we don't know the map's keys at compile time. I don't see what new kind of safety it adds that's not achievable with existing solutions such as :pre or doing an assert inline. I feel there are better solutions to this problem that already exist, such as using spec/malli and validating the value properly rather than just checking for presence.
- fogus 3mo agoOne philosophy of Clojure is to facilitate building practical and robust systems. In practice, people do runtime checking of maps using punning, some kind of `nil` check, or a more ponderous `(get m k sentinel)` checking pattern. The new feature obviates the latter as destructuring syntax in the vast majority of cases where the absence of the key throws. It's opt-in, so if Malli/Spec work then you don't need to use this. I will say that we have some other things brewing that compose well with `:keys!` and friends and the 1.13 release is going to DRY a lot of existing and future Clojure code.