Fork me on GitHub
#beginners
<
2016-08-08
>
yonatanel08:08:30

@leo.ribeiro: I suggest using the real DB in tests if they must include CRUD operations. Not doing so always gave me trouble.

donaldball13:08:22

If you can encapsulate the database interactions in a protocol, you can do that and reify an in-memory impl for your tests. If you can’t, use a real database instance.

domparry15:08:19

Any other real noob beginners out there, I wanted to share my current method of learning which seems to be going quite well. I started with 'Clojure for the Brave', which went well, but I found that the concepts weren’t cementing as quickly as I would like, so I went through some ‘4Clojure' (I use the mobile app) problems, until i got stuck, and then went back to 'Clojure for the Brave'. This really helped me to gain some knowledge, practice (cement), gain more, practice (cement more), rinse, repeat. Highly recommend if your brain works the same way.

mss17:08:26

hey all, newbie clojure compilation/ops question. I’m trying to get a clojure application I wrote live. to do that, I’d like to use lein to package up an uberjar. for whatever reason, lein is seemingly executing the -main function in my application when I run lein uberjar. this is a problem because I’m going to be building the jar on my ci server, which doesn’t have the same privileges as the eventual application server. so, is there any way to compile clojure code without executing it? is there something I’m missing here about what’s happening under the hood?

zane19:08:25

It shouldn't be executing -main. Are you sure you don't call -main anywhere?

mss19:08:50

yep that wasn’t the issue. sorry for not following up. I had a System/getEnv call in one of my functions without the env variable specified when I ran lein uberjar. I assumed I could define that env variable at runtime, not that it was a requirement at compile time. the System/getEnv call returned a nil, which caused a NPE, which broke compilation somehow? still piecing through that

mss19:08:07

appreciate the response btw @zane, thanks for the help

zane19:08:38

@mss: That's a really common issue!

zane19:08:58

The solution we implemented was to put calls like System/getEnv into a function that gets called at runtime. e.g. my.project/get-config.

mss19:08:52

interesting, will def try that. weird that one level of function nesting prevents the form from being evaluated

zane19:08:20

I'm curious why that feels weird to you!

zane19:08:43

I don't know of any programming languages where function bodies are evaluated before they're called.

mss19:08:51

well don’t you have to recursively evaluate all the forms and generate a class for each function?

mss19:08:57

to compile it to jvm bytecode?

mss19:08:22

sorry have a pretty poor understanding of this stuff under the hood

seancorfield19:08:28

If you have (def thing …) then the body will be evaluated at compile time so that the initializer for thing can be determined. If you have (defn thing …) then at compile time you are just producing a class and a method — the function is not actually called. Does that help @mss?

mss19:08:12

yes absolutely, makes a ton of sense.

mss19:08:47

so follow up question: what’s the idiomatic way to make environment variables work with component’s model of calling alter-var-root on a var?

mss19:08:56

i.e. you define you system on a var

seancorfield19:08:06

Get their value as part of the start lifecycle function.

seancorfield19:08:38

With Component, you need to avoid def since that represents global state.

seancorfield19:08:02

When start is called, that’s where you need to "build" everything your app needs, so that’s when you would call System/getenv.

mss19:08:09

interesting. makes a lot of sense

mss19:08:26

ya was just resolving my config in a var definition before

seancorfield19:08:45

If you have code that doesn’t get passed the system component, one "hack" you can use is to have (def my-state (atom nil)) and have the start function reset! it to the value it needs to have. Then the non-component code can do @my-state. But that’s a "hack" that should be avoided! 🙂

seancorfield19:08:08

(we’ve had to do this in our legacy code as we’ve slowly adopted Component piecemeal)

mss19:08:28

oh that’s nifty

mss19:08:26

really appreciate the help – thanks so much

arijun20:08:22

I'm trying to follow the modern-cljs tutorial, and I'm getting an error when trying to set up my own handler using compojure as per https://github.com/magomimmo/modern-cljs/blob/master/doc/second-edition/tutorial-09.md#the-handler

arijun20:08:38

except some spaces and comments my code looks the same when I diff it

arijun20:08:24

The first few lines of the traceback look like

java.lang.NullPointerException
        at ring.middleware.reload$wrap_reload$fn__977.invoke(reload.clj:22)
        at ring.middleware.content_type$wrap_content_type$fn__448.invoke(content_type.clj:30)
        at ring.middleware.not_modified$wrap_not_modified$fn__475.invoke(not_modified.clj:52)

arijun20:08:19

It doesn't even work to serve /

seancorfield23:08:43

@arijun: Are you sure your new handler is returning a proper value?