Fork me on GitHub

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


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.


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.


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?


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


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


appreciate the response btw @zane, thanks for the help


@mss: That's a really common issue!


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.


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


I'm curious why that feels weird to you!


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


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


to compile it to jvm bytecode?


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


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?


yes absolutely, makes a ton of sense.


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?


i.e. you define you system on a var


Get their value as part of the start lifecycle function.


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


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


interesting. makes a lot of sense


ya was just resolving my config in a var definition before


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! 🙂


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


oh that’s nifty


really appreciate the help – thanks so much


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


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


The first few lines of the traceback look like

        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)


It doesn't even work to serve /


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