; [semicolon]
It's similar to // or # in the other languages. Source code from the point you put it until the end of line won't be executed.
I use it for a quick short documentation of the code or when I want to try remove a line quickly. It's the most easy to use one because all the IDEs and text editors support it out of the box.
(comment (expr)) [comment macro]
Use it to wrap expression you don't want it to be run. It's more convenient to use when using with tool to help maintaining balance of the parentheses such as paredit or parinfer.
I use this one a lot in while I'm doing interactive development via repl. I always put the code to execute function the I'm implementing in the same file with the function definition so that I can quickly test out when I change something. I wrap that code with comment macro so that I won't be execute automatically by Clojure. When I want, I send only the inside code to the repl to see what's the output of the function.
#_ reader macro
It comments out an expression that follows it, from opening to closing parens
This one I've just learnt about it recently. It comes in handy when I don't want to care about where is the end of the expression. I just put #_ and thing will behave as I expected. It's great for multiline comment, similar to the comment macro with a less keystrokes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This line is commented out | |
(this-code-will-be-executed) ; (this-code-will-not-be-executed) | |
(defn developing-function [& _] ) | |
(comment ; Use this in development. Remove it when finish. | |
(developing-fuction 1 2 3 4)) ; Send inner expression to the repl | |
; #_ is use to comment out an expression quickly | |
(defn sameple-code | |
[api] | |
(when-let [uri (swagger-spec-path api)] | |
(let [{status :status :as response} (api {:request-method :get | |
:uri uri | |
mw/rethrow-exceptions? true}) | |
body (-> response :body slurp (cheshire/parse-string true))] | |
#_(when-not (= status 200) | |
(throw (ex-info (str "Coudn't read swagger spec from " uri) | |
{:status status | |
:body body}))) ; This line and 3 lines above will not be executed | |
(when-let [errors (seq (v/validate body))] | |
(throw (ex-info (str "Invalid swagger spec from " uri) | |
{:errors errors | |
:body body}))))) | |
api) | |
; Source code of function sameple-code is taken and adapted from compojure-api project |
ClojureBridge is done a better explanation than me
No comments:
Post a Comment