5 ms·
This illustrates why working with Clojure feels so relaxing and elegant. Most languages operate on code as text. When commenting out code with //, it's easy to
by peferron 6y ago
This illustrates why working with Clojure feels so relaxing and elegant.
Most languages operate on code as text. When commenting out code with //, it's easy to mistakenly leave out a line containing a closing bracket for example. When using /* , you have to manually insert the closing * / at the exact right spot.
On the other hand, #_ simply operates on the logical form that follows it, instead of operating blindly on characters. You know it's going to do the right thing whether you want to comment a long multiline form, or a single function call in the middle of a line.
Using structural editing (Paredit) to navigate and reorganize code is an incredible experience for the same reasons.
I'm one of these people that doesn't feel "flow" or get in the "zone" when working (leading me to sometimes wonder what I'm missing out on, or if I'm lacking something, although my career is fine so far). But writing Clojure is probably as close as I can get. :)
- Groxx 6y agoAs one not knowledgeable about Clojure, and to play devil's advocate: one of the handy parts about `//` is that you can violate the language rules. E.g. I've fairly often had cases where I want to temporarily remove a check, to see if something behaves as I expect: //if (some logic) { do something //} else { // something else //} Or in other cases collapse two if/else blocks together, or stuff like that. It's not as common as commenting out a logical unit, definitely, but it's far from uncommon. How would you achieve that in Clojure? Seems like you'd need to copy/paste, like this? #_(if (cond) thing other_thing) thing
- Skinney 6y agoClojure has line comments as well.
- Groxx 6y agoAh, derp, that'd just be the `;` then? So you could do this? ;(if (cond) thing ; other) If yes: great! The best of both worlds.
- anamexis 6y agoYes, you could. Also, most lisp/clojure editing modes will have commands for manipulating S-expressions, such as slurp and barf, which make it a single shortcut to move `thing` out of the `if` expression in your example.
- ambulancechaser 6y agohave done this lots of times. (if (test) (then) (else)) (if true #_(test) (then) (else)) (if false #_(test) (then) (else)) makes it quite simple to leave the tests in. Also, quite easy to raise forms (structurally raise) and reevaluate the form and then undo but not reevaluate the form to have it modified.
- deleted 6y ago[deleted]