This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-27
Channels
- # aleph (10)
- # beginners (139)
- # cider (47)
- # clara (19)
- # cljs-dev (2)
- # cljsjs (9)
- # clojure (94)
- # clojure-berlin (1)
- # clojure-dev (23)
- # clojure-greece (5)
- # clojure-italy (5)
- # clojure-nl (14)
- # clojure-uk (36)
- # clojurescript (85)
- # cursive (2)
- # datomic (56)
- # emacs (3)
- # events (1)
- # fulcro (33)
- # garden (3)
- # graphql (6)
- # hoplon (53)
- # jobs (1)
- # leiningen (4)
- # mount (46)
- # nrepl (7)
- # off-topic (8)
- # om (3)
- # other-languages (4)
- # pedestal (7)
- # portkey (7)
- # re-frame (1)
- # reagent (16)
- # remote-jobs (3)
- # ring-swagger (2)
- # shadow-cljs (16)
- # slack-help (2)
- # tools-deps (2)
- # yada (1)
@hiredman @shayanjm also this great talk on generative testing https://youtu.be/iYu_TrQJ8iU
hi i'm seeing an error i can't make sense of. I get this error even when I revert back to old commits that were definitely working, remove the target directory, remove .m2 directory, and rebuild from scratch. i'm very confused. how could this error happen with code that used to work? any guidance would be greatly appreciated.
java.lang.IllegalArgumentException: No implementation of method: :query* of protocol: #'reflection.util/IDataSource found for class: reflection.component.datomic.DatomicDataSource
Garden doesn`t compile :after correct. If i wanna a word in a :content option, then Garden insert the word without ''
And another question How can I append native css files to a result compiled garden file?
Are there known problems with sort
and vec
? It seems to make a difference whether I use (vec (sort ...))
or (into [] (sort ...))
- the second returns the desired result
Is it safe to say that stest/instrument
is not really a replacement for mocks via with-redefs
?
Can you give a specific example? Some quick examples work for me:
(def v [5 7 1 3])
(sort v) -> (1 3 5 7)
(vec (sort v)) -> [1 3 5 7]
(into [] (sort [5 7 1 3])) -> [1 3 5 7]
@gvCan you give a specific example? Some quick examples work for me:
(def v [5 7 1 3])
(sort v) -> (1 3 5 7)
(vec (sort v)) -> [1 3 5 7]
(into [] (sort [5 7 1 3])) -> [1 3 5 7]
What's a good way of using try catch within a loop to break program execution on a function that fails within the loop?
(loop (try ... (recur ...) (catch ...))) doesn't seem right
So how could I handle this?
The idea is for the program to explode and notify on any failure, but if I don't catch the error in the loop I'll get the exception but not the stoppage
that works
thanks!
Can one use clojure.spec for verifying an input json file yielding meaningful error messages? this is meant for a command-line tool that takes an input json file that is converted to edn
@matan do you mean verifying that the json is well formed and providing meaningful error messages in the case that it is not? the usual case people seem to be worried about is whether well-formed json has a particular structure. you can definitely use it for the latter case
@lee.justin.m thanks. I'm trying to come up with a pattern that will have some elegance.. will see what I come up with
Is it fair to say stest/instrument
mocks should really only be used with generative testing and not standard unit tests?
@lee.justin.m as a curiosity, I have found a json schema validation library a more natural solution to the scneario
Those libraries sport error messages that are almost humane, while covering the entire range of errors that your json schema implies. (I have derived for this a schema from a sample valid json of mine, through those online pages that make this derivation).
@matan i don’t think anyone is elated with the current status of error reporting in spec. the expound
library is a big help. phrase
looks cool too. I’m pretty sure spec is going to be way more expressive than json schema, but that probably means that json schema can produce higher quality diagnostics. i think there are just tradeoffs
There's some debate on my team/company over a house style practice of including examples in the code with a function's definition. e.g.
(defn x [y z] ... )
#_(x "foo2321312" "bar134324")
It looks a little messy but it has utility. It's not something you would replace with a test, because they are often example values within the context of a stateful system (database, etc). They aren't tests, they are a memory of recent usage in the context of interactive, stateful, repl-driven development. And it's also convenient to have the example next to the function. But ugh it looks sloppy, and sloppy code breeds more sloppy code.
I'm thinking something like
(defn ^{:doc "the doc string"
:usage ["foo11121212" "wee23322"]}
x [y z] ...)
And then editor tooling to support in-line execution with example usage. It would be pretty easy/quick, though I'm wondering if someone else has addressed this problem (better?) already.@rplevy I have used the #_
syle of comments for what I call my REPL Experiments in my own projects. However, instead of in-lining this experimental code after each function, I have a separate section at the bottom of the file which is clearly separated from the production code
These REPL experiments show the story of how the code had been developed, showing design choices that did and didn't work, with some text comments for context.
because you are developing and you see the sort of thing it is, and then you replace it and execute the code
go for it then. i've been burnt by comments that lied to me in the past. i'd drop it in a test and assert something so you have to keep it up to date and it won't lie. but if you get benefit from it go for it
my usual workflow is:
1. write fn
2. write commented examples next to it as I iterate to test things
3. finish writing fn
4. put those commented examples in a deftest
somewhere
If it's something that people would refer to as documentation, then I put them in a docstring
We're often dealing with state here, so it's typically not something that would go in a deftest in a way that would be easily repeated by the next person, e.g, in a deftest I would mock the stateful aspects, but the usage for an example is to actually involve the mounted state.
then I usually put them in a docstring so that they appear in people's editors without having to go to the definition site
they'll also appear in generated docs if you decided to go that route at some point
my suggested solution above is similar to a docstring but unlike a docstring it's not difficult to eval inline. At least in cider I'm pretty sure eval-last-sexp won't work inside a string
don't believe so. You could put it in a comment
form. the insert and eval commands have gotten better. they are comment aware
but also unlike a docstring it won't show up in my UI when I'm inside the form / hovering over it
Well that depends on how you integrate the use of this metadata into your editor tooling
I’d be afraid that it would litter up the code. If it works for your team then it works, however I wouldn’t deemphasize good docstrings that describe what goes in and what comes out.
for what it is worth, i do this for state manipulation functions that have sort of complicated data types. i totally love it. i put one or two examples in a comment block. it’s just easier for me to read but drift is what i worry about. i would like to have a little concise test instead of a comment.
the reason i do it is because i always end up searching for a use of the function in the code anyway
@danielglauser (I mean the commented out example style, which does lead to litter increasing)
I think the first place I saw this style of including usage examples in the code it was in some of Rich Hickey's code in core or contrib. I thought it was sloppy in that case as well.
I think it definitely has value and it's underrated as a practice, however one of the reasons people don't like it that it is a "broken window" in appearance that leads to further commented-out junk
slopmatic
Broken windows was the first thing that came to mind. 🙂
@rplevy I’m sure some of our colleagues would likely disapprove but I favor consistency over “correctness” and tend to go with a house style, then try and convince other folks that there is a better way. Which it sounds like, is exactly what you are doing. 🙂
anyone know of a great article about datomic that provides examples by analogy? eg. “heres a typical many-to-many relationship in SQL, here’s how you might model that idiomatically in datomic”, “here’s a foreign key contstraint in SQL…” etc.
@noisesmith I googled for a library called slopmatic, searched github, before realizing you were coining a portmanteau of sloppy and pragmatic 😂
the datomic docs seem okay. But coming in new, it’s tough to draw the line of “this is a constraint it’s safe to implement in client clojure code” vs “this is something that should be enforced at the schema level”
That helps a lot! If you don’t mind, I have one specific question that will provide a lot of context for me: since writes are always serialized, is it accurate to say that as long as constraint logic is in place, concurrency issues due to write are not possible? Or does datomic retry transactions on conflict, kind of like clojure ref transactions?
It’s not possible to have “concurrent” writes since the Transactor does one at a time. If a transaction function throws an exception, the whole transaction will get rejected and it’s on you to decide what to do about that
Wow that seems… a lot easier. The main exceptions the docs mention seem caused by badly structured or uniqueness-violating datoms. None of the traditional concurrency concerns like dirty-read, nonrepeatable-read, or phantom-read.
Thank you for clearing all that up for me. It seemed too good to be true, so I needed it spelled out. ha
You do have the possibility of dirty reads, in that you could do a query in your client to check against some constraint - “I need to make sure there are any widgets left in the inventory before selling one to this user” - and there could be an in-flight transaction where another user is buying the last widget. So you’d want a transaction function that checks that there’s at least 1 widget left as part of that transaction
Oh right, definitely. I should have prefixed what I said with “Within a transaction…“. So as long as I’m checking constraints within a transaction, state will not change before the transaction is committed. That’s differs (in a great way) from typical SQL-style RDBMSs where you have to actually consider which transaction isolation mode you’re operating in.
Postgres, for example, has SELECT * FOR UPDATE, where it takes a write-lock on the selected rows for the remainder of the transaction, to guarantee no other transactions mutate that data during your trans. No need to emulate that with datomic, it sounds like.
Awesome, thanks again!
Is there a way to make a deps.edn
alias depend on another alias?
Fair enough. 🙂
Does :main-opts
do weird spliting on spaces? I can't seem to pass an inline edn to -co
in it.
currently broken, sorry. if you have spaces in edn (not in embedded strings), you can use ,
instead (since it’s also whitespace)
I'm just glad that the horrible "Koenig name lookup" in C++ got named after Andrew instead of me (I suggested it as a joke and he realized it would actually solve the problem and turned it into a concrete proposal!).
Just Bing/Google c++ koenig lookup
It's literally famous in C++ circles. Pretty sure it's even called that in books 🙂
As for my contribution, I suspect I'd have to dig back into the full working group minutes for whatever session it was (I was on the ANSI C++ Committee for eight years, and secretary for three) 🙂
I'll almost certainly be at Conj (as usual 🙂 )
Oh, I hadn't thought about that. Technically my edn would work without the space anyways. I just stuck it in a file to keep it pretty. I just wanted to make sure someone was aware. 🙂
Thanks