Fork me on GitHub
#clojure-uk
<
2020-03-10
>
dharrigan08:03:52

Good Morning!

guy08:03:26

Morning!

Samuel09:03:04

morning y'all

Wes Hall10:03:51

Wes' stupid question of the day (might make this a thing...): Is there any sensible way to compile a snippet of clojurescript in a clojure file in a fairly lightweight way? Context is that I am creating a ring handler that loads the "graphiql" front end. Mostly this is done by script tags that pull resources off of a CDN but there is a little bit of embedded JS required to tell it how to fetch, what URL to hit, what headers to set etc and then to render the react component into a div. Right now, I have all this as JS inside a string in a [:script ...] which works, but is fairly sucky. It would be fairly nice to convert it to cljs expressions and compile it on the fly (with some caching potentially). My intuition is that cljs compilation is a little too heavy and sophisticated to do this kind of thing on the fly, but I thought I might get opinions before I pull this stuff out as JS to some kind of template file and just pull it in as JS.

acron10:03:29

This is a pertinent problem for me. We recently moved some interactive elements over to JS because as soon as you use CLJS you're obliged to take a relatively large amount of boilerplate required in order to execute it.

acron10:03:03

We haven't found an alternative tool that fits nicely into the environment. Would love to hear about other people's experiences in delivering 'lightweight' JS via CLJS or another LISP.

Wes Hall11:03:49

Thanks @U06HHF230. Yeah did look here as well as at some functions and internals like cljs.build.api but definitely got a feeling that I might have been messing around with things I probably shouldn't be. I might play with it at some point but I think for now, something like selmer templates to generate dynamic JS is probably where I will go.

rickmoynihan11:03:31

yeah probably not worth doing anything too fancy for such small snippets

dharrigan15:03:37

Why do I love Clojure? One of the reasons is I can pull down a library (carmine, for redis stuff), do a quick PoC on the repl, get immediate feedback, and know its going to work when I write Real(tm) code 🙂

acron15:03:45

lein try ?

dharrigan15:03:59

I'm a deps cli guy 🙂

acron15:03:16

not sure if there's an equivilent

dharrigan15:03:38

There is 🙂

dharrigan16:03:18

It's called add-lib

seancorfield16:03:26

At work, I run an "everything" REPL (with all our dev/test dependencies for our whole monorepo) and with the add-lib branch of t.d.a. and that way I can easily add new libs and try them out, without REPL restarts or any interruption to my edit/eval workflow.

seancorfield16:03:19

Unfortunately, the latest version of add-lib can't be used directly from GitHub because it includes Java code and now there needs to be a "build" step. I d/l'd it and built it locally so I can depend on that for dev, for now.

seancorfield16:03:41

Eventually, add-lib will likely be added to Clojure itself (in some form, yet TBD).

dharrigan16:03:24

One day 🙂

dharrigan15:03:20

No Ceremony, no scaffolding, just me, the repl, the library and the server 🙂

💯 8
Wes Hall15:03:00

Anybody else slightly lament the underutilisation of :pre and :post conditions? I don't really use them, mostly because almost nobody else does, and I think nobody else really does mostly because they can be turned off. I can't help but feel that were this not the case, they would be much more widespread and would probably reduce confusing errors.

💯 4
mccraigmccraig16:03:23

doesn't spec-ing or schema-ing fns provide a more structured alternative ?

Wes Hall16:03:38

@U0524B4UW In some senses it's worse because you have to explicitly enable fdef with instrumentation. Ultimately, if you want validation that validates, and always validates, it needs to go in the function body.

weavejester16:03:40

I like preconditions, but I often find myself replacing them with more descriptive exceptions.

👍 8
seancorfield16:03:47

I think Spec's fdef, instrument, and check are "better" as an overall framework for dev/test than pre/post-conditions. If we have stuff we want to check/validate in production, we tend to write it in the code directly (although we also use assert in some places -- and we don't turn those off in production).

seancorfield16:03:53

(I've railed against assert in the past because it could be turned off in production -- if I want to validate & "abort", I'm going to want that in production to avoid potentially corrupt data by letting stuff continue!)

mccraigmccraig16:03:08

we have some function schemas with ^:always-validate metadata in judicious places which works quite nicely

dominicm19:03:18

Interesting. I like assert because I can turn it off in production! Guard rails for development, speed in production. The exception in production should be rare, and will point directly at my code.

seancorfield19:03:42

@U09LZR36F I'm more concerned about the situation where the assert would have triggered if it were enabled but without it the code just "does the wrong thing" (rather than blows up).

dominicm19:03:34

Makes sense.