off-topic

https://github.com/clojurians/community-development/blob/master/Code-of-Conduct.md Clojurians Slack Community Code of Conduct. Searchable message archives are at https://clojurians-log.clojureverse.org/
clyfe 2020-12-23T14:35:05.248300Z

Align map & let or not?

➕ 4
⛔ 10
vemv 2020-12-24T10:42:04.268300Z

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 Latypoff 2020-12-25T09:30:28.270100Z

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.

2020-12-23T14:36:47.248700Z

yes for me

mpenet 2020-12-23T14:37:14.249100Z

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

2020-12-23T14:37:42.249300Z

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

borkdude 2020-12-23T14:38:22.249500Z

Can you give an example of both alternatives?

clyfe 2020-12-23T14:40:31.250100Z

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

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

clyfe 2020-12-23T14:41:28.250300Z

@mpenet because git diff?

borkdude 2020-12-23T14:41:43.250500Z

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

mpenet 2020-12-23T14:41:53.250700Z

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

mpenet 2020-12-23T14:42:21.250900Z

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

borkdude 2020-12-23T14:42:40.251100Z

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

👏 2
dharrigan 2020-12-23T14:42:49.251300Z

non-aligned for moi

mpenet 2020-12-23T14:42:50.251500Z

for git diffs there are ways to ignore whitespace

mpenet 2020-12-23T14:43:05.251800Z

@borkdude you mean, like, tabs!

borkdude 2020-12-23T14:43:18.252200Z

like tabs, but without annoying other people

mpenet 2020-12-23T14:43:58.252400Z

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

mpenet 2020-12-23T14:44:35.252600Z

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

clyfe 2020-12-23T14:46:15.253100Z

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

clyfe 2020-12-23T14:47:11.253300Z

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

mpenet 2020-12-23T14:47:20.253500Z

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

dharrigan 2020-12-23T14:47:50.253900Z

I think that's a bad example

dharrigan 2020-12-23T14:48:08.254100Z

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

😯 1
dharrigan 2020-12-23T14:48:23.254300Z

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

dharrigan 2020-12-23T14:48:37.254600Z

as shown in the good and bad examples

dharrigan 2020-12-23T14:49:58.254900Z

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

dharrigan 2020-12-23T14:50:34.255300Z

would be my interpretation of what is the intent.

mpenet 2020-12-23T14:50:39.255500Z

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

mpenet 2020-12-23T14:51:22.256Z

I think we're talking about the value part

dharrigan 2020-12-23T14:52:46.256200Z

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.

dharrigan 2020-12-23T14:53:19.256400Z

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

dharrigan 2020-12-23T14:53:39.256700Z

like that.

dharrigan 2020-12-23T14:55:48.257400Z

yup

2020-12-23T15:04:14.257700Z

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

👍 4
2020-12-23T21:19:59.263700Z

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?

2020-12-23T21:20:29.264200Z

the list to verify is about 10 digits

2020-12-23T21:26:20.265100Z

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

2020-12-23T21:27:09.265600Z

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

2020-12-24T08:33:05.267600Z

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

2020-12-24T17:01:52.268900Z

@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

👍 1
aaron-santos 2020-12-23T22:14:39.266500Z

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