5 ms·
Justified Variables: Words of the same length with related meanings
- Normal_gaussian 6y agoI lamemt the lack of support for elastic tabs. In a better world the pleasure of these justified variables could be found everywhere.
- jez 6y agoMaybe, but there’s no amount of elastic tabs that are going to make the suffix in nextAncestor previousAncestor line up the same way as nextAncestor prevAncestor so I admire the author’s time spent collecting these word groupings.
- Jaxan 6y agoWhy not though? It reminds me of this project: https://nas.sr/قلب/ https://nas.sr/قلب/. It’s an Arabic programming language and apparently their script allows for elasticity, even within words. Perhaps the Latin alphabet just sucks for aligning?
- jks 6y agoIt could work by adding a new alignment tab character, like & in TeX. TeX tables look like name & value & comment \\ long name here & 1 & one\\ x & 2 & two \\ and the columns line up at the & characters by adding suitable whitespace. Imagine some control character that you could insert in source code: next&Ancestor &= current->next; previous&Ancestor &= null; and the corresponding parts would line up in consecutive blocks, like elastic tab stops but even inside words by stretching the existing whitespace around the words.
- ggm 6y agoI've been using ifp and ofp and ths/nxt for some time. stdin and stdout are a shame in this regard
- xscott 6y agoI'm tempted to do a pull request to add "remove" to "lookup", "insert" and "update". Of course that could be "delete" as well in many languages... I also think there should be a place for "many" in the "some" and "none" grouping.
- exikyut 6y agoIMO this is one of those unintuitive things that clicks when you see it and you go "well of course that makes sense". Really cool. And now I'm reminded of http://bash.org/?406381 http://bash.org/?406381: <Axe> I <Axe> do <Axe> not <Axe> know <Axe> where <Axe> family <Axe> doctors <Axe> acquired <Axe> illegibly <Axe> perplexing <Axe> handwriting; <Axe> nevertheless, <Axe> extraordinary <Axe> pharmaceutical <Axe> intellectuality, <Axe> counterbalancing <Axe> indecipherability, <Axe> transcendentalizes <Axe> intercommunications' <Axe> incomprehensibleness. <JediHobbes> woah <JediHobbes> *blinks*
- deleted 6y ago[deleted]
- zffr 6y agoI might be in the minority, but I think using variables of equal lengths with opposite meanings is an anti-pattern. I like using clearly different words (diff lengths, diff starting characters) that still pair well together. IMO this makes it much easier to scan through code, and much less likely to accidentally use the wrong function/variable somewhere.
- pansa2 6y ago> I think using variables of equal lengths with opposite meanings is an anti-pattern. Perhaps the worst example of this is Kotlin’s var/val. I much prefer var/const.
- jez 6y agoI get the sentiment, and I'd go further to say that I prefer Rust's `let` vs `let mut`, i.e., the longer & visually noisier option discourages mutability by default, and draws attention to when it is used.
- ricc 6y agoI use a CLI app that is used like this: `command get/set [long directory]` Because of that long directory part, I use the command history instead of retyping the whole thing. I probably already lost a cumulative total of hours executing `set` instead of `get` by mistake.
- layer8 6y agoEqual-length variable names help to see differences in the remainder of the line. You are more likely to spot mistakes in code where stuff that should be the same is aligned the same.
- 082349872349872 6y agodoing words fixed style takes moxie
- jez 6y agoI only knew of the word Moxie in the context of the Pokemon ability[1] and it never occurred to me until just now that it's a real word with a real meaning haha > moxie > n. The ability to face difficulty with spirit and courage. Thanks! [1] https://bulbapedia.bulbagarden.net/wiki/Moxie_(Ability) https://bulbapedia.bulbagarden.net/wiki/Moxie_(Ability)
- transfire 6y agoSomehow bot, opposite of top, doesn't seem satisfactory. top/bum, albiet a bit snickerable, does make a good bit more sense.
- Jaxan 6y agoIn maths it’s very common to refer to top and bottom in an ordered structure. I often define a TeX macro \bit as \perp.
- exporectomy 6y agoOK but what are the legitimate reasons to spell out Greek letters? Usually, they're already a shorthand for something else that has a name, so you should use that name instead.
- yesenadam 6y agoOne nice thing about Julia is being able to use Unicode characters in variable/constant names, e.g. π and θ, instead of the usual pi and theta, in programs.
- enriquto 6y agoyou can also do this in python, perl and C (if you use gcc or clang)
- layer8 6y agoMost popular programming languages have that ability. The problem is that most people don’t know how to enter characters that aren’t on the keyboard and don’t have software installed/configured that makes it easy to do so (e.g. using a Compose key).
- yesenadam 6y agoOk, good to know. Well, Julia doesn't have those problems – in the REPL, out of the box, type "\pi[TAB]" for the greek letter, etc. And not needing an explicit multiplication sign in some places also makes mathematical code look more like maths, e.g. julia> 2π 6.283185307179586
- AlbertoGP 6y agoSame with Emacs if you select the TeX input method: Alt-x set-input-method TeX \pi → π That works for any programming language. I’ve used it occasionally for my own programs but use plain ASCII if I expect others to work on the code.
- gjm11 6y ago
- ris 6y agoPeople/formatters that justify their structures drive me completely crazy (I'm looking at you golang et al). It's like they've never tried using revision control before. It just takes a single change in the longest entry and something that was a 1-byte change becomes a 20-line diff. Noisy for code review and 20 times more likely to create a merge conflict. Your obsessive compulsions are something to be overcome, not embraced, and certainly not something to force on other people.
- dmos62 6y agoTo be fair, you could argue that your mentioned behaviour is an undesirable feature of current revision control software and code editors. The formatting could be declarative, so that compiler-meaningless indentation is not on disk. And, compiler-meaningless changes could be ignored by revision control (that's probably provided if meaningless changes aren't persisted to disk in the first place).
- ris 6y agoThis implies an amount of language-understanding from the revision control system I'd rather avoid, especially when I unfortunately spend so much of my life writing mixed source-in-source-in-source monstrosities these days.
- eyelidlessness 6y agoHow much would it have to know? I’d expect a `significant_leading_whitespace=true` config would probably do the job?
- gjm11 6y agoIt maybe depends on who's going to be interacting with the code in what ways. If you expect the code to be changed infrequently but read frequently, and if you think the justified version is easier to read or harder to miss errors in, then that could easily outweigh the cost of noisier diffs. (I'm not sure whether I actually believe the following argument, but:) The increased likelihood of merge conflict is not necessarily a bad thing. If you've got a bunch of variables, structure entries, or whatever, that are related to one another, then if A changes one of them and B separately changes another this very well may be the sort of thing you need to look at carefully and explicitly, which is what getting a merge conflict forces you to do. And (maaaaybe) the more closely related nearby variables (etc.) are, the more likely people who like justified code are to justify them. Full disclosure: I sometimes justify things in code, in cases where I think it helps to clarify relationships between nearby lines. I don't remember ever getting a merge conflict as a result, or having colleagues complain about noisier diffs. But I've generally worked in small teams and I've often been the only person working on a given bit of code, and what works well in that context is not necessarily the same as what works if you have a much larger group all poking at the same code.
- layer8 6y agoSurprisingly, it’s missing src/dst (source/destination).
- OisinMoran 6y agoThis is neat! I often find that the structure introduced by doing this makes it easier to spot some mistakes. One I've used in ML: train & valid for the training and validation sets.
- enriquto 6y agothose of use who use only single-letter variable names have this problem solved from the start
- dmos62 6y agoWell the next step is to select language primitives based on their character length: > vs >=, + vs ++, == vs ===, var vs const, map vs filter. Or you could select the appropriate function argument count based on total character count. So many opportunities to improve readability.
- dmos62 6y agoI bet people who find this worth optimizing are especially perplexed by variable-width fonts in programming.