6 ms·
Its not all roses; I tried to comment out a few routes in my clojure compojure code by doing something like this to my code a while back. (defroutes data-rou
by manishsharan 6y ago
Its not all roses; I tried to comment out a few routes in my clojure compojure code by doing something like this to my code a while back.
(defroutes data-routes
(GET "/something1" [] (sample-json-data))
(GET "/something2" [] "hello1")
(comment
(GET "/something3" [] "hello3")
(GET "/something4" [] "hello4"))
GET "/something5" [] "hello5")
)
Then when a client tried to access /something5 , I began getting null pointer execptions. This took me a while to figure out what I had done wrong.
- Borkdude 6y agoIn that case you should use a reader ignore: #_(GET "/something3" [] "hello3")
- nimih 6y agoThe reader ignore macro can be stacked in clojure, so you can also do #_#_#_#_GET "/something3" [] "hello3" if it strikes your fancy. The possibilities for bikeshedding here are truly remarkable.
- clojurenoob 6y agoI notice I accidently do similiar thing with parenedit. I can accidently move forms in and out of where they should be. Not an issue if the functions are small but with longer ones I might slurp off screen.
- bjoli 6y agoCommon mistake. For non-lispers: Macros evaluate from the outside, which means the defroutes macro will expand before the (comment ...) macro. For this to reliably work, you need a reader macro that removes the code before macro expansion. I don't know if clojure has that, but common lisp and some schemes have utilities for it.
- nimih 6y agoThe comment macro should really come with a warning that it should only be used as a top level form. Using it inline (a very natural thing to do if you're coming from a language with more typical block comments!) only ever leads to suffering, in my experience.
- hombre_fatal 6y agoI notice default syntax highlighting in Emacs, Vim, and VSCode make that odd-one-out "GET" a different color than the rest which would make this a lot easier to catch than otherwise.