Consider not overriding default printing behaviour for nodes
Raised by me in rewrite-cljc-playground, see https://github.com/lread/rewrite-cljc-playground/issues/64
Source Chat initiated by @sparkofreason (and @sogaiu many moons ago) on Slack with participation from @borkdude.
Problem/Opportunity Rewrite-clj, and therefore rewrite-cljc overrides default printing for nodes.
This seems to go against the spirit of Clojure's pr and prn whose docstring states:
By default, pr and prn print in a way that object scan be read by the reader
Proposed Solution Maybe don't do that?
Suggestion from @borkdude:
Emitting something with a reader tag is probably a better way and then define data readers
#rewrite-clj/token[foo]
Additional context Not sure why this choice was made for rewrite-clj, the original author probably found the abbreviated output useful. Maybe for tests, as suggested by @sparkofreason.
Action I'll see what impact this change has on rewrite-cljc itself, then have a peek on what affect this change might have on popular projects that use rewrite-clj, in the past I have verified rewrite-cljc against:
Issue comments from rewrite-clj-playground:
@sogaiu: If compatibility is an issue, is the idea of having an option to switch behaviors worth considering?
@lread: Thanks @sogaiu, yes absolutely! But I won't bother with supporting backward compatibility if no popular library is relying on the current print behaviour.
@sogaiu: It would be nice to be able to ask users of rewrite-clj* directly (and hear back) :)
@sparkofreason: I took a quick look through the project listed above, and none of them appear to use this behavior in an obvious way. Seems like it would be an odd thing to do anyway, since you'd wind up having to parse the output yourself, unless you were doing a direct comparison to an expected value, such as here: https://github.com/lread/rewrite-cljc-playground/blob/master/test/rewrite_cljc/parser_ns_test.cljc#L30
@lread: Thanks @sparkofreason, that's very helpful! I've not pushed my changes yet, but I just got rid of the example usage you cited in rewrite-cljc tests.
@lread: Was just sharing an example code example on Slack and saw the benefit of overriding print. It is for debugging and makes at-a-glance visual parsing of nodes easy:
(require '[rewrite-clj.parser :as p]
'[rewrite-clj.node :as n])
(n/children (p/parse-string
"{
:a 1
:b 2}"))
;; => (<newline: "\n"> <whitespace: " "> <token: :a> <whitespace: " "> <token: 1> <newline: "\n"> <whitespace: " "> <token: :b> <whitespace: " "> <token: 2>)