Fork me on GitHub
#beginners
<
2017-11-01
>
Lucas Barbosa01:11:45

Is it too expensive to specify an :identifier function that maps keywords in snake_case to kebab-case in clojure.jdbc queries?

seancorfield02:11:56

@lvbarbosa Define "too expensive"... I would say "Do the right thing" and see how it performs. Only if it isn't fast enough should you make compromises on "the right thing".

Lucas Barbosa02:11:06

@seancorfield not sure, maybe too much for aesthetic purposes.. I love kebab case and it hurts to see keywords using snake case xD

seancorfield02:11:07

(the default :identifiers function is clojure.string/lower-case by the way -- so there's already a lot of string processing going on if you don't override it!)

Lucas Barbosa02:11:30

got it, so it’s ok to do that conversion

Lucas Barbosa02:11:53

I might get the answer by looking at the code, but I will ask it

seancorfield02:11:09

Sure it's OK to do whatever conversion you want.

Lucas Barbosa02:11:09

is the mapping done for each record or only once for the entire result-set?

seancorfield02:11:29

It depends on whether you ask for arrays or maps.

seancorfield02:11:28

Actually, that's a bit of a misleading answer. It constructs the "column names" once. For a sequence of maps, it zipmaps the column names and the column values for each record.

seancorfield02:11:43

So the case conversion etc is done once per result set.

seancorfield02:11:03

(but there's still the map construction being done for each record)

seancorfield02:11:43

Seriously tho', "do the right thing" and if you think your program is "too slow" then profile it. If you're already interacting with a SQL database, I doubt a bit of string manipulation is going to be your bottleneck!

seancorfield02:11:01

Otherwise it's just premature optimization.

Lucas Barbosa02:11:11

thanks @seancorfield, and btw, nice work on clojure.java.jdbc! I am reading the “Clojure Programming” book by Emerick et. al. and there are references to the library (as you probably already know). The book is a bit outdated on that, since the library has evolved, but the official docs are helping me a lot

seancorfield02:11:39

Even the community docs are bit outdated -- no documentation on reducible-query yet, for example.

noisesmith13:11:06

is there a chance wrap-upload middleware got put onto the same handler twice?

noisesmith13:11:37

eg. you use wrap-defaults which includes wrap-upload, and then also add wrap-upload explicitly

alice03:11:34

Using compojure, just have the one route and nothing fancy happening

yonatanel13:11:08

When you find yourself propagating context args down a call chain (e.g runtime dependencies, cached values that are accumulated along the way etc.) , do you use a single context map? Would you pass it as the first arg to each function or as the last?

noisesmith13:11:05

yes, a single map, as the first arg always

yonatanel13:11:43

@noisesmith Do you also return a context map from these functions, perhaps accumulating data and passing it along with threading macro?

noisesmith13:11:57

no, I don't return the context map from functions that use it - I can see how that pattern could be useful, but it also makes the context map a full fledged arbitrary state argument

pj18:11:30

Hey! I'm reading the about page for clojure.spec (https://clojure.org/about/spec) and came upon this paragraph (after showing how a spec for a Map is written)

pj18:11:38

> One of the most visible differences between spec and other systems is that there is no place in that map spec for specifying the values e.g. ::x can take. It is the (enforced) opinion of spec that the specification of values associated with a namespaced keyword, like :my.ns/k, should be registered under that keyword itself, and applied in any map in which that keyword appears. There are a number of advantages to this:

pj18:11:07

and I was wondering what exactly is meant by "specification of values associated with a namespaced keyword should be registered under that keyword itself"

ghadi18:11:58

If you give the keyword global meaning in your program, you can register that meaning once and rely upon it

ghadi18:11:34

This necessitates having the keyword be namespaced

pj18:11:19

ah I read a bit further where spec/def is shown

ghadi18:11:29

one consequence is that maps specs don't have to be so redundant in describing their attribute <-> value bindings

pj18:11:31

so that's used to clarify the specification for a key value on the namespace?

ghadi18:11:37

yeah, you just say the attribute

pj18:11:37

and not on the spec of the map

ghadi18:11:16

"This is a map that requires a :foo.bar/baz and a :quux/bar" <- a sufficient map spec

pj18:11:07

cool, makes sense considering the dynamism of clojure

pj18:11:08

thanks!

athomasoriginal20:11:09

RE: JS Interop Question I have a global JS array

// index.js
var players = ["James", "Karen"]
What is best practice for adding something to the end of the players array in CLJS?

phronmophobic20:11:22

not sure if it’s the best way, but you can use something like (.push js/players "Alexandra")

vivus-ignis21:11:00

hi. i'm trying to use the official java elasticsearch client, and it fails on a client creation with an error message i cannot understand this snippet (RestClient/builder (HttpHost. "localhost" 9200)) results in this error message ClassCastException org.apache.http.HttpHost cannot be cast to [Lorg.apache.http.HttpHost; wikimodels-preserver.core/eval12167 (form-init2602301893053636779.clj:83) what should [Lorg.apache... mean? ‎ why [L ?

vivus-ignis21:11:48

thanks in advance

phronmophobic21:11:15

the [L prefix if for java arrays

phronmophobic21:11:37

so it’s looking for a java array of type org.apache.http.HttpHost in this example

vivus-ignis21:11:17

so varargs from java should be represented as a vector in clojure right

phronmophobic21:11:35

i’m not sure if you can use a vector

phronmophobic21:11:41

i think it has to be a java array

vivus-ignis21:11:53

vector didnt work

phronmophobic21:11:54

(RestClient/builder (to-array [(HttpHost. "localhost" 9200)]))

vivus-ignis21:11:32

ok let me try. thanks a lot for an idea @smith.adriane

phronmophobic21:11:16

or if that doesn’t work, (RestClient/builder (into-array org.apache.http.HttpHost [(HttpHost. "localhost" 9200)]))

vivus-ignis21:11:57

that first one didn't work with

[Ljava.lang.Object; cannot be cast to [Lorg.apache.http.HttpHost

phronmophobic21:11:23

ok, you may need to use into-array with the type instead

phronmophobic21:11:25

sorry about that

vivus-ignis22:11:21

that one worked. now i have another question please

vivus-ignis22:11:34

why org.apache.http.HttpHost there?

vivus-ignis22:11:08

why this full name (or how is that called properly)? i mean i've imported HttpHost

phronmophobic22:11:24

that was me just copy and pasting

phronmophobic22:11:57

HttpHost is fine

noisesmith22:11:05

if you have, you can just use HttpHost - import only changes the rules for lookup, so as long as it looks up the right thing you can always use the briefer form

noisesmith22:11:35

also, you can use classes without import- the vm auto-loads on usage, import just makes it more terse

noisesmith22:11:13

this only works with classes though, not namespaces (which are a clojure thing and need require etc.)

vivus-ignis22:11:38

right, makes sense