beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
william 2021-01-09T11:05:34.200400Z

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)?

william 2021-01-09T11:06:48.200600Z

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

william 2021-01-09T11:07:42.200800Z

is there an existing facility to do that with spec?

Piotr Brzeziński 2021-01-09T13:18:00.202900Z

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.

Piotr Brzeziński 2021-01-09T13:22:11.203200Z

Ahh, sorry, I was able to find it in the docs in the end.

👍 3
pavlosmelissinos 2021-01-09T13:46:50.203600Z

also check out #cursive

Piotr Brzeziński 2021-01-09T13:47:09.203800Z

Nice, thank you.

Diego Bernardes 2021-01-09T19:10:58.242300Z

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.

clyfe 2021-01-10T09:19:05.271600Z

you will rely first and foremost on your brain, not on tools, so optimize for that (what didibus said)

2021-01-11T11:41:43.428200Z

I also suggest using some schema lib (clojure spec, plumatic schema or malli) to check and document the format of data at module boundaries

2021-01-11T11:44:00.428400Z

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)

2021-01-11T11:45:26.428600Z

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.

2021-01-11T11:46:21.428800Z

It's not as good as static typing, but it mitigates some of the downsides of the dynamic nature of clojure

robertfw 2021-01-09T19:30:24.248300Z

@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/

👍 1
Idan Melamed 2021-01-10T08:05:14.269500Z

It's from 2015, do you feel it is still relevant?

robertfw 2021-01-20T03:12:57.255400Z

@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.

👍 1
robertfw 2021-01-09T19:31:14.248700Z

Did you re-evaluate namespace A to re-register your changed spec?

robertfw 2021-01-09T19:34:27.251100Z

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

borkdude 2021-01-09T22:36:26.265400Z

@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.

borkdude 2021-01-09T22:41:12.267100Z

There is also editor integration like clojure #lsp (for Calva/VSCode, emacs, ...) and CIDER which can help you find references, rename, etc.

👍 1