8 comments

  • slifin4 hours ago
    This is a case I never really thought about - if the key is missing today you&#x27;ll get nil as the value and since Clojure is a nil punning language it usually does sensible behaviour in your program<p>I know this sounds unreliable but in practise I like a language that defaults to pragmatic code paths so I don&#x27;t have to stay up at night imagining a million code paths<p>This adds a throwing codepath which is quite drastic so I&#x27;m glad people don&#x27;t build this into programs everywhere - I&#x27;d be nice to hear what the team imagine as the use case for this<p>Normally for correctness I&#x27;d like to see specs at the boundaries for programs and different test suites for internal behaviours
    • kevincox2 hours ago
      The problem in my experience is that while nil is a perfectly reasonable default 9&#x2F;10 times that 1&#x2F;10 happens often enough and causes major problems that it is worth taking the extra few seconds to write it explicitly in the code to acknowledge that case and that you have checked that it is fine in the 9&#x2F;10 cases or handle it in the 1&#x2F;10 case.<p>I have seen multiple major production outages in Golang code because people accidentally read a non-existent map key and used the default value. As a funny bonus in one of those cases we were stumped when debugging because this code had tests, but the tests were also reading the default values out of the map and asserting that &quot;&quot; was in fact a valid textproto (it always is!) so silently testing nothing.<p>So even if defaults are useful 9&#x2F;10 times that 1&#x2F;10 is so painful and expensive that it isn&#x27;t worth it in my experience. The time spent responding to, debugging and fixing those outages far, far outweighed the time saved by the convenient default values in the 9&#x2F;10 times.
    • xoxolian2 hours ago
      For me: documentation at the &quot;front door&quot; of an interface, especially in that long moment before you decide to add a spec or Malli schema.
    • jimbokun1 hour ago
      This is really the kind of thing you want to fail at compile time which isn’t real possible in a dynamic language like Clojure.
      • slifin45 minutes ago
        Well it is possible - you can add a user macro that calls into clj-kondo (or anything actually) to check your codebase on compile<p>It just doesn&#x27;t make much sense to do - most modern developers will be running static analysers through LSP or their editor (knowingly or not) continuously on code change so as to see those errors quicker than re-compiling the program
      • xoxolian47 minutes ago
        Unless you use Typed Clojure, which is a library. <a href="https:&#x2F;&#x2F;github.com&#x2F;typedclojure&#x2F;typedclojure" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;typedclojure&#x2F;typedclojure</a><p>I haven&#x27;t used it, so I don&#x27;t know its tradeoffs; but its docs say its types exist at compile time: <a href="https:&#x2F;&#x2F;github.com&#x2F;clojure&#x2F;core.typed&#x2F;wiki&#x2F;User-Guide" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;clojure&#x2F;core.typed&#x2F;wiki&#x2F;User-Guide</a>
  • hk__24 hours ago
    Some explanations from <a href="https:&#x2F;&#x2F;clojure.atlassian.net&#x2F;browse&#x2F;CLJ-2961" rel="nofollow">https:&#x2F;&#x2F;clojure.atlassian.net&#x2F;browse&#x2F;CLJ-2961</a>:<p>&gt; Clojure’s idiomatic use of maps has proven valuable, but missing required keys, misspelled keys, and invalid values can lead to failures that do not connect to the actual source of the problem (e.g. NPEs) making diagnosis difficult. At the same time, Clojure lacks a simple inline mechanism for functions to document and check the keys they require and accept. Existing tools either separate those expectations from the function itself or couple data shape and data provision.
  • moomin3 hours ago
    This is actually great, and I predict that fans of nil-punning will rapidly discover the joys of actually having errors trigger where the error was introduced rather than propagating through the program.<p>Any news on ClojureScript gaining the feature?
    • swannodette3 hours ago
      Working on it :)
      • embedding-shape3 hours ago
        Amazing! What are the most interesting areas for ClojureScript in the future, if you don&#x27;t mind me asking for some casual semi-serious prediction?<p>Thanks for everything you&#x27;ve done for Clojure and ClojureScript, I&#x27;d surely have dropped programming as a whole if I didn&#x27;t discover Clojure and ClojureScript at the time I did.
        • swannodette3 hours ago
          Honestly what&#x27;s mostly at the forefront of my mind is greatly improving the documentation around ClojureScript as well as our fork of Google Closure Library (GCL). At work we&#x27;ve switched to DataStar (a single JS include) and coupled that with ClojureScript&#x2F;GCL - we no longer rely on anything from NPM, to call this a simplification would be a gross understatement. Bundle size is 30K gzipped and we spend no time thinking about our build or JS tooling&#x2F;dependency tomfoolery.<p>So less about ClojureScript specifically, and more generally how I think we&#x27;re well situated for people looking for a way out. The current mainstream practice dead end is bigger than the one that made React (also originally just a script tag include) appealing to me back in 2013. There are of course many ways forward that don&#x27;t involve CLJS, but I think ClojureScript&#x2F;GCL and the new crop of NPM-dep free pure CLJS solutions like Replicant are well situated for folks who can see that accepted practices are not delivering enough value even with AI assistance.
    • fnordsensei3 hours ago
      Well, kind of. This is the kind of problem that you might throw schemas (eg. Malli) at pre 1.13.<p>It’ll be nice to have it at hand in the base language though.
    • akkad333 hours ago
      What is nil-punning?
      • undershirt2 hours ago
        allowing functions to treat nil arguments as empty versions of their expected types
  • ndr4 hours ago
    Is it only me or this sounds a bit counter to clojure philosophy?
    • summarybot3 hours ago
      As 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.<p>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.<p>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.
    • rads4 hours ago
      The 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-zeta2 hours ago
        The maps haven&#x27;t changed at all, this is a feature at destructuring sites.
        • rads2 hours ago
          Sorry if I wasn’t clear, I was referring to the maps that are being destructured.
    • embedding-shape3 hours ago
      Seems additive to me; no breaking changes, and better control and error messages when opting in for it, seems entirely Clojurely to me.
    • erichocean4 hours ago
      It&#x27;s 100% opt-in at the call site and doesn&#x27;t affect existing code, so no?<p>Many people (including myself) already have checked key variants for maps; this mainly extends the syntax to destructuring too.
    • bcrosby953 hours ago
      Howso?
  • pgt55 minutes ago
    This is helpful, because practically many functions in the wild have assert-like checks at the top of the function, e.g.<p>`(if-not key1 (throw (Exception ...))`<p>...and pre-conditions, e.g. `:pre [condition1 condition2]` do not run when `<i>assert</i>` is off.
  • temporallobe3 hours ago
    We just updated one of our projects to 1.12.5, but I might push for 1.13 as this could be very useful, although an alpha version might raise questions.
  • thom2 hours ago
    Ah yes, the missing seventeenth way to validate function parameters.
  • exabrial2 hours ago
    I love the idea of clojure and perfect immutability, but holy crap I cannot grok the syntax. My C-trained brain explodes.
    • barrenko29 minutes ago
      It&#x27;s like a light saber instead of a machine gun. Let the bullets come to you.
    • beders2 hours ago
      It&#x27;ll take a while but now other programming languages look alien to me. Once you&#x27;ve adopted s-expressions it is hard to go back.
    • erichocean2 hours ago
      It took about two weeks for me to be able to read it.<p>Might as well have been Russian.<p>Now it&#x27;s as natural as any other language.
    • wry_discontent1 hour ago
      You get over it really quickly once you start actually using it. I find it basically impossible to read Clojure outside the editor in any meaningful sense.