Fork me on GitHub
#off-topic
<
2020-12-23
>
clyfe14:12:05

Align map & let or not?

30
12
jjttjj14:12:47

yes for me

mpenet14:12:14

I wrote a cljfmt option to purge repos of this heresy 🙂

jjttjj14:12:42

I understand why it's perhaps not a best practice, but I just like how it looks 🙂

borkdude14:12:22

Can you give an example of both alternatives?

clyfe14:12:31

;; aligned
{:bla-bla 1
 :bla     2}

;; not aligned
{:bla-bla 1
 :bla 2}

clyfe14:12:28

@U050SC7SV because git diff?

borkdude14:12:43

I usually don't but sometimes I do, when I'm really bored

mpenet14:12:53

no, often the aligned version ends up in a mess, and visually I prefer to have things paired close to each-other

mpenet14:12:21

personally I think it's easier to read, but I know it's quite personal, some people like one or the other

borkdude14:12:40

Maybe this should be an editor feature: render like you would like to see it, without touching the source code

👏 6
dharrigan14:12:49

non-aligned for moi

mpenet14:12:50

for git diffs there are ways to ignore whitespace

mpenet14:12:05

@U04V15CAJ you mean, like, tabs!

borkdude14:12:18

like tabs, but without annoying other people

mpenet14:12:58

cljfmt can enforce one way (non aligned via :remove-multiple-non-indenting-spaces? ) not the other way around

mpenet14:12:35

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

clyfe14:12:15

tools, by default, align afaict; probably because bbtasov's https://guide.clojure.style/#bindings-alignment

clyfe14:12:11

my annoyance is with git, a new entry can make the whole set change

mpenet14:12:20

emacs (cider) doesn't align by default, not in the way we mean with "align" on this thread at least

dharrigan14:12:50

I think that's a bad example

dharrigan14:12:08

both vars are of equal length, i.e., thing1 and thing2

😯 3
dharrigan14:12:23

My reading of that is to align the vars, not the evals

dharrigan14:12:37

as shown in the good and bad examples

dharrigan14:12:58

(let [thing1 "some stuff"
      another-thing "other stuff"]
  (foo thing1 another-thing))

dharrigan14:12:34

would be my interpretation of what is the intent.

mpenet14:12:39

sure, but that shows alignment of the "key", not the value

mpenet14:12:22

I think we're talking about the value part

dharrigan14:12:46

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.

dharrigan14:12:19

(let [thing1        "some stuff"
      another-thing "other stuff"]
  (foo thing1 another-thing))

jjttjj15:12:14

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])

👍 12
vemv10:12:04

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)

Timur Latypoff09:12:28

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 lets and maps. What about binding forms in doseqs?— I guess, yes, but what about their inner :lets? 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.

chrisblom21:12:59

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?

chrisblom21:12:29

the list to verify is about 10 digits

noisesmith21:12:20

there's the one that numerology uses: keep recursively summing digits until you have just one digit

noisesmith21:12:09

that's easy on pen and paper, and a lot of people can do it in their head

Gleb Posobin06:12:48

What do you mean recursively? Compute sum of digits, then compute the sum of digits of the sum, etc? The result is just x mod 9 then, and if x is positive and divisible by 9 it is 9.

chrisblom08:12:05

@U051SS2EU thanks, this is definitely suitable for pen and paper.

noisesmith17:12:52

@UQ4RJ22EA 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

👍 3
Kelsey Sorrels22:12:39

The https://en.wikipedia.org/wiki/Luhn_algorithm while easy to do on paper, is probably not possible to do in one's head.