9 ms·
Clojure 1.11 planning
- xtreak29 7y agoClojure had kept the core lean and simple and has grown through the years with libraries for features like spec. It makes the language as a whole stable with features developed and tested like spec being a library in alpha.
- roenxi 7y agoI enjoy Clojure and spec is very interesting; but it remains uncertain if I have any problems that spec will solve. I'm not really that interested in the generative testing aspect since I write mostly amateur code. So I can't figure out if it is more like a debugger for targeted location of difficult bugs or more like compiler error messages where it becomes a pervasive part of the workflow. There is obviously something to this spec if it warrants a v2. It just isn't obvious whether it solves my problems, library maintainer problems or professional problems. It is very different to the immutable-everywhere design where a Clojure beginner is forced in to understanding it to even try trivial experiments.
- mping 7y agoOne use case is API input validation.
- dancek 7y agoSpec is great for validation. For example, we have a HTTP API built using https://github.com/metosin/reitit https://github.com/metosin/reitit where we have specs for each endpoint. We have a coercion middleware that checks each request (and optionally response) conforms to a spec (and coerces things like integer ids from path to the correct type). And there's a swagger handler that automatically generates a full documentation of the API just from the route tree and specs, including samples of input and output for all routes. Similarly you can do HTML form validation, etc. We even use honeysql with nice helper functions that ensure that data-changing SQL queries are of the expected form. Say, you want to update just one row, you have a helper function that checks the honeysql data has a where clause with a unique column and only then runs the query. Someone should maybe blog about that sometime. What I've found, though, is that trying to use spec like type checking is usually not a great idea. I expect better from static analysis / compile-time checking, with clj-kondo being the most promising tool atm.
- Scarbutt 7y agoI remember spec being pitch for something you only use at dev time and turn off in production because it makes your runtime very very slow, what has change? Seems users are using it for everything now.
- nickik 7y agoNo. It was always designed to be configurable so you can keep on the API endpoints, but deactivate them internally.
- dancek 7y agoWe don't have instrumentation in production, ie. we spec much more at dev time. But for things you'd validate anyway spec is a good match and probably about as performant as hand-written validation. The only strange use of spec I mentioned is validating db queries. For us updates and deletes are rare enough that perf doesn't matter.
- fulafel 7y agoI bet you are thinking of https://clojure.org/guides/spec#_instrumentation_and_testing https://clojure.org/guides/spec#_instrumentation_and_testing - it was always just one use of spec among many.
- seancorfield 7y agoSpec has numerous uses. We use it heavily in production for data validation/conformance: https://corfield.org/blog/2019/09/13/using-spec/ https://corfield.org/blog/2019/09/13/using-spec/
- dkersten 7y agoI have a somewhat off-topic question I've been wondering about... How do you pronounce "reitit"? I've been considering giving a talk on it at my local clojure group, so I should probably learn how to actually say the word!
- wry_discontent 7y ago
- CurrentB 7y agoYou won't necessarily have to use it directly to reap benefits from it. API authors can use it to provide you with excellent error messages which pinpoint the exact location something is wrong
- kimi 7y agoWe use it extensively as a kind of "incremental typing" - that is, I can assert that what goes in to a function has a given shape and what goes out complies as well. Even in production, the overhead is quite low (think 5% in our use case).
- juskrey 7y agoMy daily usage: - input and message streams validation. - data generation for testing. - spec is the best data structures documentation! - sequential data structures parsing and transform More magic, but based on everything mentioned: dev-time macro input and destructuring sanitizing and error report.
- dustingetz 7y agoThe dream for me is to model things like HTML5 specification as data instead of English
- vnorilo 7y agoI use it often as a giant sanity assert that guards my application state in dev mode. In lieu of static types. Helps me catch dumb type errors early at the site of mutation.
- _bxg1 7y agoI see it mainly as an answer to static types. Clojure (like most Lisps) places emphasis on dynamic types, for some valid reasons (https://lispcast.com/clojure-and-types/ https://lispcast.com/clojure-and-types/). But there are certain undeniable benefits of static typing that you miss out on: documentation, and IDE hints. Spec, the way I see it, is a way to reclaim some of those benefits without giving up the dynamic paradigm. It also has some advantages over static type systems; most notably you can describe any arbitrary assertion, which makes it more expressive than regular types. You can also check things at runtime, which can be useful for validating foreign inputs that aren't available at build time. Personally I'm still a static-types person, but I get it. And if I used Clojure regularly, I'd be all over Spec.
- Scarbutt 7y agoBut there are certain undeniable benefits of static typing that you miss out on: documentation, and IDE hints. And performance.
- logistark 7y agoCool, cool. When is full compatibility with Java 8 be available? I mean Java 8 SAMs, Java 8's Stream, Optional and CompletableFuture...
- badsavage 7y agoClojure is a different language. Being "fully compatible" with (more similar to) Java was never a goal.
- pjmlp 7y agoThis is why guest languages tend to fade away, as the platform evolves and the platform system languages adopt the features that made those guest languages appear in first place.
- dancek 7y agoThat is true for guest languages designed to overcome specific issues in a given language (think CoffeeScript vs. JavaScript in 2012 and then in 2019). But I don't think it really applies to Java vs. Clojure, which both pretty much force a specific (different) programming paradigms and have completely different design.
- StreamBright 7y agoTrue but you need to access the libraries in Java. That is a little bit hard in some cases.
- yogthos 7y agoI find that I tend to do very little interop nowadays, and it predominantly happens at the edges with things like database drivers, and so on.
- StreamBright 7y ago
- badsavage 7y agoSpec is very useful, but please implement it without macros. Metosin did a great job to make it more usable, but we still struggle because specs could only exist in Namespaces. We want to use spec as EDN with pure functions. (+ recursive specs would be awesome)
- Borkdude 7y agoFor schemas as EDN you might want to take a look at malli: https://github.com/metosin/malli https://github.com/metosin/malli
- badsavage 7y agoI didn't know malli, thank you Borkdude!
- puredanger 7y agoSpec 2 can be used without touching any macros if desired and has a lot more programmatic options.
- badsavage 7y agoAwesome!
- thelazydogsback 7y agoI'd love to see more focus on non-JVM impls other than JS -- .Net Core 3.x specifically. (ClojureCLR is pretty much dead, right?)
- puredanger 7y agoClojureCLR is up to date with the Clojure on JVM, so not dead at all.
- rcarmo 7y agoIt gets regular commits, but I've found it impossible to use practically, somewhat to my regret (I have plenty of use for a LISP that can do .NET interop).
- robto 7y agoYou might want to check out Arcadia[0], a Clojure library for Unity game development. It's all done with ClojureCLR and it's pretty cool. Not saying you want to do game development, but they've definitely got a working product and you can see how they've set up their project. They just got a round of funding this year, and they've got several good talks posted on their homepage about the quirks of working on .NET. [0]https://github.com/arcadia-unity/Arcadia https://github.com/arcadia-unity/Arcadia
- rcarmo 7y agoI did, but it was a bit stale a year or so ago (as in it wouldn't even work with the Unity build at the time). Which is too bad, since one of my kids is doing Unity micro-games and I would like to have alternatives...
- bananaoomarang 7y agoDevelopment has picked up again AFAIK, saw one of the developers give a short demo/talk on it recently and it seems neat. Godot is a decent OSS alternative to Unity, but no Clojure/Lisp so far as I know :(
- _bxg1 7y ago> Spec 2 has been kind of stalled out as Rich is thinking through some of the work we were doing on how to rework function specs and the use case of automating form/map versions of the specs. It's fascinating to watch a major enterprise language with a Steve Jobs figure at the top, who maintains a firm grip on the wheel, keeping it on track with his clear vision even as its community grows in scale, to the point where he alone would be a bottleneck in its design process. I mean it's clearly working out - as it worked out for Jobs - it's just highly unusual.