oakmac / standard-clojure-style-js

Standard Clojure Style in JavaScript
ISC License
81 stars 1 forks source link

Relocated comments #155

Open milelo opened 2 weeks ago

milelo commented 2 weeks ago

I often temporarily comment out lines during development for alternative implementations etc. standard-clj moves some of these comments which is very unhelpful for me:

Before

(p/catch (fn [e] (-> e str println)
                 ;(-> e .-name println)
                 ;(-> e .-message println)
                 ))

After

      (p/catch (fn [e] (-> e str println)))))
                 ; (-> e .-name println)
                 ; (-> e .-message println)

Also:

            (jsc/extrudeLinear {:height 6
                                    ;:twistAngle 0 
                                    ;:twistSteps 1
                                }@!file-data))))

After:

            (jsc/extrudeLinear {:height 6}
              ; :twistAngle 0 
              ; :twistSteps 1
              @!file-data))))

I also find this formatting unhelpful, if I want to add an extra parameter to the end I will have to relocate the comment as well which is likely to get missed.

                :filename "model.xml"
                :type "text/plain" ;"application/xml"
                })))
                :filename "model.xml"
                :type "text/plain"}))) ; "application/xml"
oakmac commented 2 weeks ago

Thank you for the report. There is a pretty thorough discussion of this behavior on Issue #60. I also have a comment on this Clojureverse thread that is relevant.

The tl;dr is: use a comma , to "hold" the parens on the next line in cases where you think it is important to keep this formatting. This explicitly communicates developer intent that "these comments are important, and they should be located right here".

I often temporarily comment out lines during development for alternative implementations

Standard Clojure Style is a tool that is primarily designed for "code at rest" as opposed to "code in flight". In the examples above, is this the desired final state for this code? Or something where the developer is still playing around with things and exploring options? IMO, it looks like the latter.

I am not suggesting "this code is bad", or "you're doing or wrong", or anything of that nature. If we were working on a team of ~20 developers and I saw this code on a Pull Request, I would probably say something like "Can we clean this up a little bit before merging?". And maybe in that context Standard Clojure Style might nudge the author to do that without intervention.

milelo commented 2 weeks ago

Ok thanks for the comments. My assumption was, as a proposed standard, it would be desirable to use all the time including during development, likely run on save and by all Clojure users no matter their proficiency or desired code quality. As such I think this policy would potentially be annoying for many who are unlikely to know these tricks; incidentally the "," trick doesn't work in Calva. It would seem more intuitive for users who would like the comments after the closing brackets to put them there and not force this on all users. I've no desire to enter the debate but this is my contribution and opinion as a more casual user.