by mst · 3y ago · 0 comments
Specifically, 'one indent is four spaces, two indents is one tab, repeat', which caused utter carnage for newbies editing YAML files since literal tabs aren't valid YAML.
Back in the day, I built consensus to switch the perl https://p3rl.org/Catalyst framework over to defaulting to an apache style config in the scaffold generator specifically because about 75% of our "confused newbie" questions on IRC at the time were people whose emacs config had broken their YAML config file.
Of course we're -ahem- a few years on from that now, and people generally have already had at least one pitched battle with YAML before installing/adopting another thing that uses it, but still, oh gods but that was frustrating for a while.
If your language has a convention, then likely Emacs implements it. If not, you can send a patch to fix it.
Also with homeassistant I was "forced" to write a lot of yaml by hand and also never had real issues. Maybe its because emacs handles writing yaml fine. Anyways. I like yaml.
Their emacs configs didn't.
Hopefully most distros' default emacs installs do the right thing these days but it's not something I've checked because these days pretty much everybody already has a setup that works for YAML because of how prevalent it is.
(I like YAML for just-about-human-editable data structures but then people try to text template it rather than actually treating it as data and then I want to cry)
But as a default for any mode that cycle is ... nuts. Though I'm sure there must have been some reason for it.
The standard tab width (in most software, not just emacs) is 8. Basically nobody wants that much indentation, so your options are:
(1) Don't use tabs at all. Just use spaces. If space efficiency is a requirement, that eliminates this option.
(2) Use tabs only and change the tab width to match your desired indentation level. This is a simpler method. The downside is other people need to change their tab width to match yours. They may not want to, or their software may not support it. You have to decide whether you want to deal with that.
(3) Mix tabs and spaces. This is more complicated, but most software will display the files as expected without any tweaking.
TLDR: Tabs save disk space, but tabs are too wide, and changing tab width is a hassle, so mixed tabs/spaces is a compromise.
EDIT: Both the Linux and BSD kernel coding style specify tabs for indentation, and a tab width of 8. The Linux guide says it best: "In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning."
And, yet, that becomes so much religious dogma that people will shoot themselves in the foot.
I fixed a lot of network locking code way back when. I made sure that I had a validation framework to go along with it. It was a gigantic state machine, because that's what locking and protocol are.
But, you know, that thing had single exit point and 4-5 indent levels and extended past 80 characters because it was a goddamn state machine, had states and variables lifted directly from the specification state machine, and tested as a state machine with the validation suite.
But, hey, the kernel devs just had to rewrite it to match 2 indents and 80 character lines. So, they did.
And took 9 months until they passed the validation suite again. They didn't add a single feature. They didn't fix a single bug. But, hey, they dedented it real good.
What finally did the deed was that one of the senior devs finally got fed up, went back to my original code, wrote a Perl script (that's how regular my code was) to rewrite every state block into a function with extremely short, unintelligibly cryptic names and args in order to remove two levels of indent and make sure the function calls would fit in 80 characters.
The final kicker: someone genuinely found a real bug about 5 weeks afterward. They tried to fix it in the "better" code with less indents. They couldn't figure out which state was the problem because they mangled all the names. I went into my old code, fixed it, added a test to the suite and reran the refactoring script--and that's how the bug got fixed.
We're not developing on punch cards and VT100s anymore people--quit being stupid.
(Side note: the main issue that bit the devs is that people who are dogmatic about 2 tabs-80 characters tend to rely on early return to avoid fully-fleshed if-then-else which cause deeper chains. This does not work for state machines. There is no early return--every state should leave at exactly the point when you advance from the old state to the new state at the atomic swap. So, you can do what the senior dev did and cryptify everything, or you can just leave the damn state machine alone and accept 4 indents and 132 characters.)
Did you read the Emacs source much? They compensate by having functions span thousands of lines
...wait, what, why? Indentation is not meant for alignment, you should not do something like, say...
myAwesomeVariable: CoolType = frobnicate(moop,
mork,
mindy);
...it doesn't even look good, if you must have them aligned, do... myAwesomeVariable: CoolType = frobnicate(
moop,
mork,
mindy
);
...tabstop doesn't matter, you put your tabstop to 2 and it works, I get a fancy ultrawide monitor and put my tabstop to 8 and it still just works. The only problem is that you can't build a Christmas tree: x = 7;
da = 42;
foo = 666;
boop = 1812;
In other words, nothing of value is lost.In 2023, we've made that mistake enough that there's a consensus not to do it. But when these defaults were chosen, there was wider variation in styles. (There wasn't even a consensus on how to format braces in C.) Expecting people to never do that would have been a pretty opinionated default.
Also, you touch on another issue: terminal width and wrapping lines. Back then you couldn't just tell people to make their window wider. Their response might be, "At 80 columns, it's already the full width of my screen." Or going back further, "What's a window?"
So "apparently under some distro configs in some circumstances it does that" is pretty much all I bothered to find out, because the config data structures people were mostly expressing worked fine with a less touchy format. (and this was only the -default- format configured by the scaffold, if you handed the config system a YAML file it was still happy to load it)
Today I learned why sometimes my YAML files seemed inexplicably to end up with tabs in them.
For example, I would argue that MOST modern text editors treat a tab as approximately 4 spaces, not 8 spaces.
Exactly how said "some configurations" came to be I never figured out, it may have been a particular set of distro defaults.