Fork me on GitHub
#code-reviews
<
2022-02-26
>
noisesmith00:02:27

in addition to the above good advice, I would bind the regexes to meaningful names in a let block or def. I would have suggested some names to bind but it's too hard figuring out what each step is meant to do.

noisesmith00:02:56

also #()instead of named functions here is actively hostile to readers

noisesmith00:02:37

since # and % so readily blend in with the regex syntax when skimming

noisesmith00:02:15

java regexes (which is what #"" becomes) support in-line comments via a syntax switch, it's a judgment call whether using a feature most people don't know is worth it for the readability on the regex https://www.regular-expressions.info/ https://www.regular-expressions.info/java.html

Clojure 1.10.1
(cmd)user=> (def x-y-split
               #"(?x) x   # pattern must start with x
                      (.) # capture the item in the middle
                      y   # pattern must end with y")
#'user/x-y-split
(cmd)user=> (re-seq x-y-split "xayxby")
(["xay" "a"] ["xby" "b"])
personally I would argue that using regular expression already means you expect users to deal with features that are obscure and I find this style of re much easier to read

❤️ 1
noisesmith00:02:35

to elaborate a bit more (?x) is a syntax switch, and it turns on two features that I care about here: ignoring whitespace and allowing # comments until end of line

noisesmith01:02:59

finally - I should have linked this - the docs for "free spacing mode" which is what the syntax ?x enables is called https://www.regular-expressions.info/freespacing.html

Lukas Domagala02:03:49

Thank you, that does help with the crazy regexes!