Hi, I think I need a clarification on when code is executed. I have defined a spec
in namespace A, I defined some data in namespace B and am using s/conform
to see if it adheres to the spec. Then I use some of the values of namespace B in core
. But when I change the spec, I get no errors from the conform
statement. Could you shed some light on when code is executed (this is cljs running on shadow-cljs)?
thinking about it, maybe the code is executed, and just returns invalid
, and I go on from there. I have to see how to throw errors
is there an existing facility to do that with spec
?
Hello, newbie here 🙂. Is anyone here using intellij (with cursive) for clojure dev? I have a question about it. I have ran a repl for my project by right-clicking on project.clj and I can interact with it just fine. Now when I edit files under src/myproj/core/clj (add a function for example), how do I get that function into the repl? I’m unable to find a proper shortcut combination.
Ahh, sorry, I was able to find it in the docs in the end.
also check out #cursive
Nice, thank you.
Hi guys! I’m looking for good references on big projects using a dynamic language like Clojure. Things like refactoring, tests, bugs, etc… I’m starting with Clojure coming from Go and the dynamic thing is kinda of a worry for me.
you will rely first and foremost on your brain, not on tools, so optimize for that (what didibus said)
I also suggest using some schema lib (clojure spec, plumatic schema or malli) to check and document the format of data at module boundaries
A disadvantage of clojure is that the 'shape' of the data is not always clear. In go/java/haskell etc it's easy to find out which fields the data has (just check the class of datatype definiton)
With clojure you can create a mess where everything is 'just maps' but it's hard to figure out what the fields are. Annotating these with schema, spec of malli at critical points helps a lot to prevent this.
It's not as good as static typing, but it mitigates some of the downsides of the dynamic nature of clojure
@diego.bernardes you may want to have a look at the book "Clojure, Applied", I found it very useful when going from having learned Clojure to needing to build something real world https://pragprog.com/titles/vmclojeco/clojure-applied/
It's from 2015, do you feel it is still relevant?
@idanmel apologies for not replying earlier. I dug out my copy and thumbed through, and did not see anything that appears dated. The usefulness will differ from person to person so I'd take a look at the table of contents and see if they are topics that are of use.
Did you re-evaluate namespace A to re-register your changed spec?
I don't recall anything in spec throwing. There are some functions for returning error information however. s/explain
will print to *out*
while s/explain-data
will give you a map with information about the failure, which you could then use to throw an exception, if that is the behaviour you need
@diego.bernardes Although it doesn't catch everything, many people, including me, find it useful to enable a linter in the editor and/or in CI: https://github.com/clj-kondo/clj-kondo (disclosure: I'm the author of this tool) This can find many "silly" bugs without even running the code. That in combination with a good test suite (which you should have anyway) and good QA practices, should help a lot. Clojure also has clojure.spec and several other data validation/conformation libraries that can help at runtime, but will require you to do extra work (write the specs) if you want more robustness.
There is also editor integration like clojure #lsp (for Calva/VSCode, emacs, ...) and CIDER which can help you find references, rename, etc.