Align map & let or not?
I align maps and don't align let bindings. Only the former tend to be homogeneous (same types of key/values). clojure.test/are
is also ace to align.
As a maybe interesting experience to share, I aligned nothing and actively hated alignment for many years. But once I was forced to use it, I haven't wanted to go back ever since.
The key thing is to see alignment as "tables" instead of some fanciful rearrangement. tables rock, you can see e.g. make a table
in https://clojure.org/dev/developing_patches (I know that's a totally unrelated context, but you'll see tables coming up in various talks)
From my (rather limited) experience, alignment cannot work consistently in LISPs due to their extensibility, and those inconsistencies really bother my OCD.
In theory, it's easy: just align the pairs in let
s and maps. What about binding forms in doseq
s?— I guess, yes, but what about their inner :let
s? Ok, we can teach the editor to detect all these in clojure.core, but what about taoensso.encore/when-let
? With all the macros everywhere, I either have to spacebar the alignments manually, or the IDE has to be really, really smart (haven't seen one smart enough yet).
Same for maps, {:k1 v1 :k2 v2}
are obvious, but what about map-like constructs, like vararg pairs in (assoc x :k1 v1 :k2 v2) — same problem with consistently detecting what is a map and what isn't, in my opinion.
Add to that the bugs in editors, which sometimes lead to alignment not being triggered — all those inconsistencies made me give up on the beauty, and just opt for predictability.
yes for me
I wrote a cljfmt option to purge repos of this heresy 🙂
I understand why it's perhaps not a best practice, but I just like how it looks 🙂
Can you give an example of both alternatives?
;; aligned
{:bla-bla 1
:bla 2}
;; not aligned
{:bla-bla 1
:bla 2}
@mpenet because git diff?
I usually don't but sometimes I do, when I'm really bored
no, often the aligned version ends up in a mess, and visually I prefer to have things paired close to each-other
personally I think it's easier to read, but I know it's quite personal, some people like one or the other
Maybe this should be an editor feature: render like you would like to see it, without touching the source code
non-aligned for moi
for git diffs there are ways to ignore whitespace
@borkdude you mean, like, tabs!
like tabs, but without annoying other people
cljfmt can enforce one way (non aligned via :remove-multiple-non-indenting-spaces?
) not the other way around
it's a bit wild with the aligned version, you have to decide on thresholds if you want to do it consistently. It's not as easy for tooling
tools, by default, align afaict; probably because bbtasov's https://guide.clojure.style/#bindings-alignment
my annoyance is with git, a new entry can make the whole set change
emacs (cider) doesn't align by default, not in the way we mean with "align" on this thread at least
I think that's a bad example
both vars are of equal length, i.e., thing1
and thing2
My reading of that is to align the vars, not the evals
as shown in the good
and bad
examples
(let [thing1 "some stuff"
another-thing "other stuff"]
(foo thing1 another-thing))
would be my interpretation of what is the intent.
sure, but that shows alignment of the "key", not the value
https://clojurians.slack.com/archives/C03RZGPG3/p1608734431250100
I think we're talking about the value part
Yes, although the example given shows the vars being the same length, and the alignment affecting the names. It would have been better to show the vars of different lengths and either keep the values together, close - or to align the values to clearly show that the names of the keys are not important.
(let [thing1 "some stuff"
another-thing "other stuff"]
(foo thing1 another-thing))
like that.
@dharrigan https://github.com/bbatsov/clojure-style-guide/issues/219
yup
fwiw I just turn the setting on in clojure-mode on emacs ( (setq clojure-align-forms-automatically t)
) and never need to tweak or configure it from there. If something gets really awkward I just add an extra line which resets the alignment level
(let [thing-one-is-really-long 1
another-long-one 5
x 4
abc 4])
(let [thing-one-is-really-long 1
another-long-one 5
x 4
abc 4])
i'm making a geocache puzzle, and the solution of the puzzle is a list of numbers (the coordinates for the next cache). i'm looking for a simple checksum operation that can be used to verify the results, does anyone know a simple checksum that can be computed using pen and paper?
the list to verify is about 10 digits
there's the one that numerology uses: keep recursively summing digits until you have just one digit
that's easy on pen and paper, and a lot of people can do it in their head
@noisesmith thanks, this is definitely suitable for pen and paper.
@posobin I think you are right, it's not a very sophisticated algorithm, but it's a very simple one that many people already know, and will catch 8/9 errors on average I guess
The https://en.wikipedia.org/wiki/Luhn_algorithm while easy to do on paper, is probably not possible to do in one's head.