Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world
dull_mens_club·Dull Men's Clubbytoynbee

Tabs are better

It is SO STUPID that spaces are widely preferred for indentation in code.

For the past, I don't know, two hours I've been trying to fix YAML formatting issues that could have been fixed without any human intervention if only tabs were used. (It's a big file, hence the duration.) (I know YAML doesn't support tabs. That's kind of my point.)

I even reluctantly asked Gemini (forced upon me by work; I was hoping it would change my mind in this case) why anyone would prefer spaces. It said the same irrelevant thing most people say: because some tools don't support tabs properly.

Know what that sounds like to me? A problem with the fucking tool.

I don't know if this is the right place to post this, but I can't think of a better option.

View original on lemmy.world
117

112 replies

lemmy.ca

No.

Wanting two different white space characters that are indistinguishable from each other, when a single one will do, is stupid.

Also, YAML is stupid, as is every language that chooses to use whitespace as a delimiter (fight me python nerds).

40
fonix232reply
fedia.io

I agree on indentation as delimiter being stupid for a PROGRAMMING language, but for markup/data serialisation languages that are primarily meant to be human readable, it is a great solution.

21

Syntax can be your delimiter, and white space done how the human sees fit. That’s the proper solution, imo

11
lemmy.ca

Yeah well you're wrong.

Braces help everyone, just like punctuation does. Try and read a Cormack McCarthy novel and the importance of punctuation to denote structure for readability will become immediately apparent.

Using whitespace as a delimiter is just nerds min maxing too far.

6
Victorreply
lemmy.world

Yeah well you're wrong.

Relax, this is clearly a subjective matter.

5

Some people are just so incredibly "AKQCSHUALLY" about certain things. And they don't even see that there's no right or wrong, it's just your use case vs mine. Narrow-minded af.

4
charokolreply
lemmy.zip

I don’t know, I’ve never found Python structure remotely hard to read

5

Except when some chucklehead used two character intents. This is why tabs are superior; if you want to be squinty, be squinty. The rest of us get 8 char intents that make the logic easy to see.

4

A novel by definition isn't a data structure meant for serialisation. Your argument is akin to going up to a mapmaker and telling them do to their job different because van Gogh did it different and look how his art turned out!

Braces in a data structure help nobody but computers. That's why I specified that for HUMAN READABILITY, YAML is superior to JSON, even though they easily translate between each other. Try to read a single-line, optimised for transport JSON vs try to read a neatly formatted YAML document. YAML is inherently closer to how humans perceive data.

2

With tab you end up with two. Unless you write if(foo==bar){ ...

2

If it's just there for readability then don't have two characters that can be interpreted differently.

Your text editor / viewer is capable of entering two spaces when you hit tab.

-1

Everything that doesn't align with my subjective, personal mental model is stupid. 😭

5
lemmy.world

Python nerd here, willing to fight.

Easy language, simple script, faster learning, faster writing, better person, superior language.

Also currently trying to write english as concise as Python to ration my brainpower, you can thank my huge brain later when I do epic things like saving the world with whitespace delimiters.

2
toynbeereply
lemmy.world

Well, I haven't used this account in almost a year, but apparently when I did I tagged you as "Epic apologist."

So an incorrect take from you makes sense!

I do agree that YAML is stupid, though.

edit: Apparently I have used this account more recently than a year ago, but only sparsely. I apologize for misleading you.

2
lemmy.ca

Lmfao, imagine bragging that you need to put people into buckets so you can dismiss them.

Learn how to use your brain and respond to the argument at hand.

-7
toynbeereply
lemmy.world

Hah, all right, this could be fun.

At no point did I brag. Presenting facts about myself as bragging says more about you than it does me. You complaining about that, doubly so.

I'm not putting you in a bucket so far as I can tell. I used a function of my Lemmy client to identify you. Epic is a bad storefront and Tim Sweeney seems to be a bad person; certainly he was actively anti Linux until it impacted his bottom line. I disapprove of that because I support Linux and also think morals should account for things other than, well, accounts.

It's possible I'm wrong, in which case I welcome debate, but I didn't get here without using my brain. Also, I was trying to be funny with my initial response; if you used your brain, you would recognize that.

Ultimately, I don't like you. Not because I disagree with you - I can handle that - but because you're rude. Which I can also handle, but still don't like.

4
lemmy.ca

The irony of someone labelling people and then bringing up those labels in unrelated conversations to dismiss them, and yet still having the audacity to call others "rude".

Look in a mirror bud.

-1
toynbeereply
lemmy.world

Is your entire objection to me that I tagged you? You didn't address any of my other points. I'm willing to discard your Epic affinity if you want to talk about anything else.

3
lemmy.ca

You made no points about tabs and spaces, you brought up an unrelated conversation, then somehow convinced yourself I was the dick in the situation.

2

Well, fair enough about me not referencing the original point. I was quite mad (for largely unrelated reasons) when I made the original post, then when you responded, I was trying to be funny rather than helpful.

I did reference an Epic conversation. Perhaps that was unhelpful. I didn't expect the conversation to gain sufficient length that it would matter. I apologize, I was working more towards humorous than helpful.

However, I made all of my points about tabs being superior in my original post or other comments. I wasn't trying to obfuscate things in further comments.

0
lemmy.zip

Based on this conversation, I've added a tag, "space lover".

It's too late for you, I have already won. Also, username checks out.

2

The username is coincidentally entirely unrelated … I hadn’t even noticed the relevance lol

1

❤️ Python! But letting me program is stupid and a bad idea. So it works. Deal with it 🤣

1

The classic programming holy war. As far as code is concerned, just have a formatter for the language, whichever tabs or spaces the formatter uses. I just hit tab and let the formatter decide. I most use Rust and I honestly had to lookup if rustfmt used tabs or spaces because I honestly didn't remember.

As for the YAML part, that's just because YAML sucks

18

What if... we invented a character with the sole purpose of delimiting indentation?
People could even configure whatever width makes sense to them locally. We could call it fabulations with how fabulous it would be.

18

That's not really what's described by "delimiting" and especially not by "configuring the width". Which are features of tabulations.

And it's Linux where line feed is carriage return and line feed together (down a line and back to the start) while Windows separates those and is historically consistent (although that's been clunky for a long time).

0
sh.itjust.works

I loathe YAML (and Python for that matter). Anything that uses whitespace as syntax is a problem. The exception is Whitespace, it gets a pass for being hilarious.

I couldn't agree more with you though - it's a problem with the tool. If it doesn't support tabs that's not my problem, and if the language used whitespace for style instead of syntax everything would still work fine.

18
lemmy.ca

We have a 40+ year old software (still developed, but some stuff never changed). They have the software read tables from space separated files. They trouble is each line has to line up with columns above it, so if you have a long string in one row, you have to go to every single line and space them with empty space to all line up the same.

To make it even worse it was based on 80 character max, so if your column headers are more than 80, you create a second line with more column headers. So row 1 is your columns, row 2 is your next set of columns. Row 3 are spaced entries to line up with row 1. Row 4 are spaced entries to line up with row 2.

And word wrap dosnt work because column rows have a CR after them.

Its a freaking nightmare. This is why tabs are better

17
BCsvenreply
lemmy.ca

Oh, god. Humans did this formatting abomination twice?

7

Japan and IT have an ... Interesting relationship. If you can code, looking at parsing libraries can be interesting. There are all kinds of csv-ish abominations here. Multiple header rows, different headers if a line is empty, etc.

9
lemmy.world

That sounds like a simple problem that could safely be fixed in a day or days depending on the size of the data set, with a high degree of confidence.

4
BCsvenreply
lemmy.ca

Unfortunately its tied into the code and appa that compile those tables. And they need to support legacy customers who've built on top of that system. The software still opens files from that era to support aerospace customers who have a database of parts from that era.

3
lemmy.world

Why can't you make it work with another format, and use a flag for legacy format for those clients. Then you don't have to deal with it as much

2

I wish we could. I had hoped they'd move to CSV at least. Newer parts of the software support excel files.

I assume Its feeding into a legacy codebase that they obviously don't want to touch because it works and supports auto and aerospace across the globe. And many places still use data they generated in the 70s.

The whole thing is terrible to work with, thankfully AI is great at converting simple formating to convoluted bullshit formatting.

1
piefed.social

I too prefer tabs. It's always been that way. It annoys me when an editor tries to be smart with spaces, and insert auto indentation instead of an actual tab character. It annoys me even more when I press the tab key, and the editor interprets that as "I guess that means you want spaces.".

I will concede that tabs can be a bit too wide when you end up nesting a bunch of stuff, so I'm fine with them being displayed as a set of spaces, but when I hit tab, I want an actual tab character. Otherwise I would use the spacebar.

16
0opsreply
piefed.zip

Most editors I've used let you set a tab width in units of spaces. I prefer tabs at a width of two spaces. That's the great thing about tabs though, we can all share the same codebase and set the tab width to whatever we each desire

12

I will concede that tabs can be a bit too wide when you end up nesting a bunch of stuff

Nope, that’s a code smell; if your code is veering off into the rhubarb because you’re nesting like crazy then that’s a signal to break up your function. 8 char tabs help you code better.

6
piefed.social

tabs have never been a consistant thing. its basically just a certain amount of spaces. I can totally see why tabs would not be used.

13

Exactly, and by design: each user is allowed to set their own tab width and not mess everyone else up.

Like 8 space tabs? Go for it.

Want only 2-space indents? Just update your settings.

The semantic mean of a tab is "indent" - it should be up to each user what their idea of an appropriate indent width is.

16
toynbeereply
lemmy.world

I used to like you because of your username, but that ended today.

1
toynbeereply
lemmy.world

Surely, as a human, you can work with me and recognize that the thing about tabs is that they can be adjusted to represent whatever number of spaces you like? The thing about spaces is that two spaces will always be two spaces wide. What benefit does that provide?

1
piefed.social

I mean I feel your arguing against yourself here. its more precise to specify using a space or two spaces or three spaces, etc. like in python the formatting is the structure becasue it does not use brackets and such. File formats are exactly like they sound. specific formats. consistancy is paramount.

4
toynbeereply
lemmy.world

I acknowledge that consistency is beneficial, but Python works with both tabs and spaces. The difference, in this context, is that if you like two spaces for indentation, but I like four, your code will always have sections of two when I look at it. I can make configurations that change it and so can you, but why is that needed?

Meanwhile, in this hypothetical, if we were to use tabs, you could set your tab to represent two spaces and I could set mine to represent four and we'd both be happy with the same, unchanged code.

5
piefed.social

yeah I see what you are saying but again I can see why consistancy would be given priority.

1

100% Whitespace should not be a funtional element of a language. Let me format it however looks best to me then just end the line with a ;

10
slrpnk.net

The kind of coding I do is amateur hour at best and I use tabs instead of spaces

It's neater and (for the kinds of stuff I do) works

Also makes finding my errors easier

8

Sounds like you're doing it right, regardless of what style guides say.

7
toynbeereply
lemmy.world

I knew someone was going to reference this. It's surprising that it took so long.

6

The good reason I've heard is because it's consistent. Tabs can change length depending on what's displaying it (this is both a feature and an issue). Spaces will mostly be consistent.

However, you say the issue is with the tool, and I agree, but in a more complex way. A good tool won't really care which you use. A good tool can interpret them identically and adjust the display to your preference. Bad tools are why people will have a preference for one or the other, and the above is the good argument for (and also against) spaces instead of tabs.

6
programming.dev

i fought against tabs for years because I figured one character vs four will decrease file size (I'm old enough to remember a time when that mattered) but eventually gave up to spaces as I started working with more and more collaborators and found consistency to be more important than a few bytes. now if only we can solve line endings.

5
toynbeereply
lemmy.world

Maybe I'm confused, but it seems like you used to dislike tabs, but now dislike tabs?

7

I think like is too strong a word in this case. Consistency is key and fighting the tide, even if it is not the best solution, is foolish.

1
sopuli.xyz

I just forget about it because my editor changes my tabs to spaces so I usually hit the tab key anyway. Would prefer tabs, but it is what it is.

5

but it is what it is

Since LLM’s the only devs left are those with this mindset and I hate it.

[React won] but it is what it is

[Liquid Ass] but it is what it is

[LLMs] but it is what it is

[PHP lost its simplicity] but it is what it is

1
lemmy.world

I have worked on projects that get run through automatic formatting when committed to repos

Perhaps you need something like that and you can auto format the way you want on the way out

5
fonix232reply
fedia.io

Git has post-checkout and pre-commit hooks that can easily do this.

Means your local copy is in your style, but you commit in the repo style.

Insane thing to do, but nobody's stopping you...

2
toynbeereply
lemmy.world

Or people could do the logical thing and just use tabs.

edit: remove extra space.

2
dudefacereply
lemmy.world

My text editor will use spaces if it is in the liter file or how it auto detects in yaml files etc

The experience is no different when using tab / shift+tab

1
toynbeereply
lemmy.world

The experience of entering the text isn't the part to which I object.

Claiming that spaces as indentation are functionally equivalent to tabs is what inspires my objection.

1

I don’t think you gave an example in your original post as how tabs would have solved your problem, and dealing with yaml a lot myself I can’t imagine exactly what may have happened besides incorrect indentation

I get rich errors with yaml language server and I configure it with spec files for kubernetes manifests so it tells me exactly where my issues are

1

Automatic code formatting, and failing a PR due to an automatic formatter is lazy and wrong. Code formatting should be a (strong) set of guidelines, but never a hard and fast rule. Every code base ends up with some section that is visually easier to understand but breaks the formatting check.

1
feddit.online

You should create an elaborate set of tiles making your case and attach them to the asphalt on roads to convince folks to switch.

3
lemmy.world

Tool issue indeed. Using vim I don't really care which it is if vim is configured correctly.

2

Not at all, that was vi. Unusable, I tell you. The improved vim is from at least 1905!

But seriously, once you know a few basics, it's very fast editing, far faster than many gui editors.

1

Easy solution, use only a single space for each level of indentation.

/s, probably. Though one could make an editor expand the single spaces at the start of a line to an arbitrary width, for readability.

2
Davereply
lemmy.nz

A single space shown by the editor at an arbitrary width is basically what a tab is lol.

7

It's an issue with Yaml, not the spaces though. Also "fork" bombs, impossible to implement properly, the Norway problem, etc.

2

Spaces themselves are not problematic. They seem to do their job fairly well. Their job, however, is not indentation.

3

I heavily use githooks to let everyone have their cake and eat it too. Eg:

Git post checkout hook converts something i don’t like to how i prefer it

Do some things

Git pre-commit hook converts my preferred thing back to the format as committed.

Usually i can do these with a one-liner from some combination of jc, jq, yq, and yamlfmt and for everything else there’s sed. If there’s a linter or formatter in the repo I’ll run those in a pre commit hook after all my stuff. The best part is it just takes an executable so you can write it in anything you can shebang, compile, or interpret.

JC is underrated and YQ i avoid for most cases but it’s quite good with comment handling and preservation

1

Show me your hooks. I work with a psychopath and although he's a great guy I need this argument to stop.

2
lemmy.dbzer0.com

So your work provides Gemini to help you, and you ask it existential questions instead of pasting the borked file in so it could spit it back to you fixed in 30 seconds?

-1
toynbeereply
lemmy.world

It was not able to determine which lines in the file needed to be corrected. That's part of what lead me to ask it "existential" questions.

5
Cethinreply
lemmy.zip

Couldn't you write a quick script to replace spaces with tabs? It should have been pretty trivial if you needed it.

1

vim actually provides retab but I've gotten very mixed results using it in the past.

2
lemmy.world

I suppose you're one of those people who claim nano is a good editor too

-1
toynbeereply
lemmy.world

nano is as good as notepad.

I nearly exclusively use vi(m), though.

3

Correct answer, although more accurately I am a NeoVim + LazyVim man nowadays.

1