50 points

Tabs let you define how big you want each indent to be

…except when they don’t. Many common environments have a hardcoded tab size of 8, which is insanely big for using it for indentation.

permalink
report
reply
43 points

Because other people might have restricted environment which might not suit their preference is not a good reason to level it down IMO.

Also, I think 9 is the best size for indent (matter of preference), do you think I should switch to space so everyone can enjoy this wonderful view I have ?

permalink
report
parent
reply
17 points

Ah, the best kind of indent. A tab and a space.

permalink
report
parent
reply
9 points

Or just set tabsize to 9, that’s the point :)

permalink
report
parent
reply
4 points

Why would you ever need 9 other than trolling people on the internet?

permalink
report
parent
reply
4 points

Straight on point!

permalink
report
parent
reply
6 points

It’s not just “might”. Termux is pretty much the only good choice for programming on Android.

I think 9 is the best size for indent (matter of preference), do you think I should switch to space

I think you should switch to an exorcist.

permalink
report
parent
reply
3 points

What’s your point ? You can use vim on termux and set the tabsize to whatever you want for example.

permalink
report
parent
reply
10 points

This is the biggest problem with tabs. Too many tools don’t let you adjust the size (or make it very difficult). This is the only reason I usually prefer spaces (only very slightly).

My dream solution is elastic tabstops and I’ve posted about it here before a few months ago. The problem with wanting elastic tabstops is that it seriously compounds the issue of “editors don’t properly support it”

https://nickgravgaard.com/elastic-tabstops/

permalink
report
parent
reply
19 points

What environment are you using that has a hardcoded tab size? I haven’t seen this since typewriters.

Some projects just use tabs as a compressed form of 8 spaces. But that is a sin. Use tab to mean “one indent level” and align with spaces if you need to. (the occasional ASCII art diagram)

permalink
report
parent
reply
7 points

What environment are you using that has a hardcoded tab size?

  • Termux
  • SourceHut
  • “View page source” in the browser
permalink
report
parent
reply
15 points
*

Termux

I think running tabs -N (where N is you preferred tab size) in the terminal should work. This is what I use in my zshrc on desktop.

SourceHut

Yup, they seem to be pretty opinionated here. If you look at the source there is just an inlined style with a single rule pre { tab-size: 8 }. I guess that is what you get when you use opinionated tools. The user’s browser isn’t right, my preference is right!

“View page source” in the browser

On Firefox this uses my default tab size of 4. But I guess changing this default isn’t user-friendly.

permalink
report
parent
reply
3 points

What environment are you using that has a hardcoded tab size?

Microsoft Windows’ Notepad. I have sometimes used that when on a public computer.

permalink
report
parent
reply
4 points

Github uses 8 as a default. It’s configurable though.

permalink
report
parent
reply
13 points

As an embedded software developer that does linux kernel drivers I’ve come to love the tab size 8 indentation level.

I’m paraphrasing: “if your indentation level gets too deep, it’s time to rethink/refactor your function.”

And with tab 8 you’ll notice it rather quick if your function does too much/unrelated stuff.

A function should be short and do one thing only, if possible. It also makes unit testing easier if that’s a requirement.

permalink
report
parent
reply
-1 points

When you’re operating on such a low level of abstraction, it’s no wonder you don’t need deep nesting.

permalink
report
parent
reply
1 point

Oh, I’ve done my fair share of C++ and Python as well. But you got to agree with me that when you are on your fourth indented “if case” it’s time to step back and think about what you are trying to achieve. I mean it’s probably going to work, but probably also very hard to maintain that type of code.

permalink
report
parent
reply
15 points

I consider tabs for indentation a failed concept.

The idea is good, but it evidently failed. Most guidelines and newer Tools recommend or require or use spaces for indent. They have their reasons too.

The prevalence of spaces makes it hard to make a contrary argument for tabs. By now, I don’t think it’s worth even if it had reasonable advantages.

Editors/IDEs that parse syntax can adjust space indent too. A mixture for indent and alignment is not obvious for everyone (I always display whitespace in my editors and am deliberate and consistent, but many people and editor defaults won’t be). Some defaults of four or eight space-width tab display is atrociously wasteful and inaccessible.

Spaces are a good enough baseline. It works well enough. And most importantly it works consistently. That’s why it won in prevalence and use.

permalink
report
reply
2 points
*
Deleted by creator
permalink
report
parent
reply
4 points
*

Do you have actual experience with it?

Some time ago I read a comment from someone with impaired eyesight who used an editor that would adjust space indent just fine.

Accessibility is a thing I always consider.

permalink
report
parent
reply
7 points
*
Deleted by creator
permalink
report
parent
reply
6 points

If I could only get everyone who works on the thing I work on to use a whitespace visualizer, it would be enough. We can fight about tabs or spaces after we get rid of all the unnecessary trailing ones.

permalink
report
parent
reply
2 points

I created a tool for removing trailing whitespace across the whole project. After cleanup now it’s at least only a matter of pointing it out in reviews and occasionally fixing landed sources.

permalink
report
parent
reply
5 points

You’ve a .editorconfig in your repo right? Right?

permalink
report
parent
reply
2 points

I’m glad someone linked this. Should be further up in this thread.

permalink
report
parent
reply
4 points

In case folks aren’t aware, https://editorconfig.org/

permalink
report
parent
reply
1 point

Wrong.

permalink
report
reply
2 points
*
Deleted by creator
permalink
report
reply
Deleted by creator
permalink
report
parent
reply
31 points

Tabs for indent, spaces for alignment. This is the way, I can’t believe people are still fighting that ?

permalink
report
reply
3 points

Then you lose the benefit of tabs: you can’t adjust the tab width without destroying alignment. So you end up with a confusing mix of characters for no benefit.

Mixing them is the worst option.

permalink
report
parent
reply
3 points

You might not understand how to do it properly so here’s the idea:

Tabs will let you reach the indentation level of the current block, then from here, you’ll use spaces to align stuff property. Here’s an example, where >••• are tabs (I’m exaggerating alignment for the sake of the example) :

>•••if (condition1 == true
>••• || condition2 != false)
>•••{
>•••>•••struct ident people[] = [
>•••>•••>•••{
>•••>•••>•••>•••.name   = "bob",
>•••>•••>•••>•••.pubkey = "value1",
>•••>•••>•••},
>•••>•••>•••{
>•••>•••>•••>•••.name   = "alice",
>•••>•••>•••>•••.pubkey = "value2",
>•••>•••>•••}
>•••>•••];
>•••>•••secureConnection(people[0].name, people[0].pubkey,
>•••>•••                 people[1].name, people[1].pubkey,
>•••>•••                 CRYPTO_ALGO_DEFAULT);
>•••}

As you can see, everything will stay correctly aligned as long as it’s within the same block.

permalink
report
parent
reply
3 points

You’re confusing using tabs for indentation and spaces for alignment with using tabs and spaces for indentation. This means each line starts with tabs. Next you optionally have spaces for alignment with previous lines. Then you have content (like code or comments). Because you never have a tab following a space the alignment is never destroyed by adjusting how wide a tabstop is.

permalink
report
parent
reply
0 points

I am not, it’s easy to find examples where tabs first then spaces breaks down.

permalink
report
parent
reply
5 points
*

The opposite is true, though. If you use tabs for indentation and spaces for alignment, you can adjust the tab width without destroying alignment. That’s the big benefit of the tabs-for-indentation-spaces-for-alignment mix.

You can’t do that with only tab characters, you can’t even align stuff with tabs because it has variable width.

permalink
report
parent
reply
1 point

You can preserve alignment in a mixed context, but it complicates things.

permalink
report
parent
reply
29 points
*

Anything for indent (barely matters, as long as the editor forces it to stay consistent), and fuck alignment, just put things on a new line.

permalink
report
parent
reply
16 points
*
struct Ident arr = [
{
.id
= 0,
.name
= "Bob",
.pubkey
= "",
.privkey
= ""
},
{
.id
= 1,
.name
= "Alice",
.pubkey
= "",
.privkey
= ""
}
];
permalink
report
parent
reply
17 points
*

Not like that, lol

Just saying, instead of this monstrosity

CreateOrderRequest(user,
                   productDetails,
                   pricingCalculator,
                   order => order.internalNumber)

Just use

CreateOrderRequest(
    user,
    ...

Putting the first argument on a separate line.

Same if you have an if using a bunch of and (one condition per line, first one on a new line instead of same line as the if) and similar situations.

permalink
report
parent
reply
6 points

The way god indented.

permalink
report
parent
reply
0 points

seconded on not aligning things. its the whole source of the problem in the first place and doesnt even serve a purpose

permalink
report
parent
reply
1 point

It does help with reducing thrashing between edits in git diffs. Or rather, opinionated autoformatters do, which is the only reason I bother with alignment.

permalink
report
parent
reply
9 points

I used to think this way, at least when writing C++. But it’s objectively harder to do and convince other people to follow, especially if they can’t be bothered to change their environment to display tabs and spaces differently. It’s a losing battle so now I just do spaces when working with other people

permalink
report
parent
reply
-1 points

Always do spaces, because you can never trust how someone else has their tab configured.

How is this even a debate anymore. I thought we all agreed on this years ago.

permalink
report
parent
reply
3 points

you can never trust how someone else has their tab configured

Why on earth would I care how someone else has their editor configured? It’s none of my business, and none of yours either.

permalink
report
parent
reply
6 points

I’ve yet to find tooling that supports this. Clang format has a setting that looks like it does it, but actually does something else. If I have to press the spacebar a bunch of times each time I add an argument to a function, that’s a pain, and it’s a bigger pain to convince the people I’m working with that that pain’s less bad than using spaces everywhere and having the IDE deal with it.

Until the people making editors and auto formatters acknowledge that the obvious most sensible whitespace style is even a thing, I’m forced to do something else and be really grumpy about it.

permalink
report
parent
reply
0 points
Deleted by creator
permalink
report
parent
reply
1 point

I understand your point of view. Personally I either copy the previous line and replace the arguments there, or insert X number of space using the repetition feature of my editor. It also has a feature that will align multiple cursors together with the “farthest” one using space, which is a killer feature for me! (See this presentation video @1:40).

permalink
report
parent
reply
5 points

It’s hard to do this consistently (especially in a team) because people might (and statistically in a large enough project, will) use the tab key for alignment since it’s faster than pressing space, or just be confused about what whitespace is tabs and what is space. Just using space everywhere is idiot proof and requires no work to micromanage. The only way to use tabs is to not align at all.

permalink
report
parent
reply
3 points

And this is why language servers and formatters are so critical.

permalink
report
parent
reply
1 point

I agree that it’s hard, but not impossible. This usually boils down to how Nazi people are when merging code. In a corporate environment, nobody gives a damn so yeah you gotta use whatever you want because there are already different indentation systems within the same file anyway :)

But hey, you gotta live by the changes you want to see happen, so I personally put a lot of effort in formatting my code regardless.

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3K

    Monthly active users

  • 1.7K

    Posts

  • 28K

    Comments