#Tabs considered harmful?

89 messages · Page 1 of 1 (latest)

median gyro
#

....

fallen siren
#

call me crazy but i have hard_tabs = true in my rustfmt.toml

thorn anvil
#

I saw an article on how indentation style, is a question of accessibility, and that given tabs are pretty consistently and clearly wider than spaces, they're the preferable option when it comes to accessibility...

buoyant charm
#

how about, NO

strange jackal
#

Useless troll thread imo

#

No valuable debate will come out of this since tabs vs spaces is an entirely subjective “discussion” with no real world consequences

willow skiff
#

I'd say the tabs vs. spaces debate is somewhere in between IRL politics (Ukraine, etc.), and the topic of this server (Rust), in terms of how controversial they are

median peak
#

Accessibility is the only thing that matters here

strange jackal
#

I don't see how either is more accessible

#

which a slight advantage to tabs where the user can set the width (I'd say 0.1% of programmers know this)

#

most people slinging code just hit the tab key, and the text indents. The actual implementation of why/how it is indented isn't super important imo

high mountain
#

Since accessibility is mentioned in this, let me quote these two threads:
https://news.ycombinator.com/item?id=18414562
https://news.ycombinator.com/item?id=18478776

evincarofautumn

I work on programming languages (as a career & hobby) and I’d like to make sure that my main language project is designed with accessibility in mind. I need some guidance & opinions from people with disabilities (e.g., blind or visually impaired people, or people with mobility issues) about your pain points with existing tools.This doesn’t need ...

ioquatix

I've often wondered what things we have in style guides which make it difficult for visually impaired programmers. I would like to know how to make my code easier for you to read and write. Please help me to improve my code for you.

high mountain
#

So regarding the accessibility of tab (adjustable indentation), it seems to be limited to the group who has not lost vision entirely, but relies mainly on magnifiers to write code.
Unfortunately any attempt to survey people with disability in a community runs into the problem of chicken and egg: if the community is not accessible, there would be no one with disability to survey. But we can only try.
I wonder whether there is an initiative on this.

crisp badge
#

tabs are the superior option period

#

oh wow, this was an old thread

#

tabs give a unified style, for example if one codebase uses 2 spaces and one uses 4, you cant copy code from one to the other without having trouble with the indents. if both of them used tabs there wouldnt be an issue, plus with tabs each person can have the code display the way they like

#

and before anyone brings up alignment, you should 1. not write code where thats even an issue 2. if you must, use tabs for indentation and spaces for alignment

dusky nova
#

I would love an editor feature that actually does that

#

I’ve also heard of “semantic indentation”, that is throwing away fixed tab stops in their entirety

dapper beacon
#

Also elastic tabstops

buoyant charm
#

why are so many people pro tabs, I don't think I've ever seen a codebase using anything other than spaces

dusky nova
#

I don’t dislike tabs. I dislike code display tools that treat source code as plain text with some color

thorn anvil
#

Backspace clears spaces in groups of four...? Nice! But if you need to change code formatting in a particular context, it can get screwed up pretty quickly...

pale geyser
#

disclaimer: it's not actually a code editor

#

it's a dedicated program that visualizes an AST and you manipulate the AST directly

#

no text files are manipulated

dusky nova
#

Does it still let you type code using the keyboard?

pale geyser
#

yea, you still type type/function/var names and stuff, you just don't have a backing text file for it

dusky nova
#

An AST seems too low level for programming against

pale geyser
#

unfortunately, this means that git/terminal support is very limited, because you're manipulating a serialized AST, not text
fortunately, this means that how the code looks is entirely user-dependent. it can look however you want! you're not rendering text, after all, you're rendering an abstract graph

dusky nova
#

Or do you mean it visualizes it as code text?

pale geyser
#

yeah, it visualizes it as code text

dusky nova
#

Nice

pale geyser
#

if you type fn it'll declare a function, not type a literal "fn" anywhere, etc

#

and you can't type invalid syntax because there is no syntax to parse

dusky nova
#

Code is much more difficult to read without tooling than with

#

Also does it save an AST or CST?

#

If it saves an AST you’ll be able to make everything the same code text style

pale geyser
#

CST?

dusky nova
#

A very rigid style mind you

#

Concrete syntax tree, which saves stuff like alignment, superfluous parentheses, multi line method chaining, etc.

#

With just an AST you get stuff more like rustfmt

pale geyser
#

yeah none of that at all, it stores as an AST

#

parenthesis are not saved at all, for example, they're just visualized (and can be typed out) to make it obvious you're declaring a function

#

but you could configure the graphical part to replace ( with [ if you wanted

#

anything, so long as it's unambiguous that you are, in fact, declaring a function using the GUI

#

At least, that's the idea. I don't know if Dion actually got that far. But their progress was really impressive!

dusky nova
#

Hmm what about blank lines?

#

Those are the one thing that I think are universally common

#

Perhaps they are presentation groupings like comments?

buoyant charm
#

if I press tab and that writes four spaces, does it count as tabs or spaces?

lucid tiger
#

spaces

pale geyser
#

i.e. they're part of the AST, but they're just ignored during compilation, just like comments

#

ideally they'd be visually toggleable too

#

..the sad part is that you kind of need to integrate this into your programming language of choice

#

you cannot feed this into any existing compiler without forking it, and languages that use it are fundamentally incompatible with eg. vscode unless they have a "text parser" extension or something

high mountain
lunar agate
#

I use my IDE's formatter

#

Get on my level

sinful slate
#

oh i didn't expect to be able to move the post into the recent activity section by clicking that

grand magnet
#

People are always like "spaces are better, use spaces," but nobody can really tell me why. I find tabs to be better for the single reason that it decouples visual indentation from actual indentation. Each indentation level only needs to be one deep and then you set whatever width you want in your editor. What advantage do spaces have? Encforcing the same width for everyone, regardless of preference? Using more bytes per file? Like seriously, why do people like spaces so much?

#

In any case I'll use whatever convention the programming language or software company/project dictates, because I'm pragmatic, but my preference is definitely tabs.

quartz sail
#

I completely agree. It seems to me that the obvious and infallible solution is to use tabs for indentation and spaces for the specific cases that you need things to align for aesthetic purposes.

pale geyser
#

So as far as I can tell, spaces are better for fine control, and tabs are better if all your indentations are exactly the same width

#

And mixed spaces+tabs are better if you want to maximize suffering

grand magnet
#

Tabs for indentation, spaces for alignment. Will work on any tab width as long as it's all the same number of tabs at the start, and spaces otherwise. And if that's not a supported scenario, then the problem is the tooling, not the concept.

crisp badge
#

i completely agree with this

heady plank
# pale geyser C# doesn't have a rustfmt equivalent to make things look pretty, so it's done by...

Surely someone's written an autoformatter for C# by now? Every other language has at least one tool for this, even if it isn't official.
Anyway, I don't personally see a benefit from using the former over the latter for method chains:

long_var_name.foo()
             .bar()
             .baz()
             .quux()
long_var_name
    .foo()
    .bar()
    .baz()
    .quux()

Alignment simply cannot be done using tabs, and if mixing spaces and tabs is undesirable the solution is simply not to align anything. Line beginnings are aligned by default and applying equal indent does not change this regardless of the method of indentation used.

I've actually only seen one argument against tabs that I think truly holds water: If tabs are used, the length of a line becomes ambiguous, so enforcing a maximum line length for all users becomes impossible without mandating a specific tab width for this purpose.

This argument has a flaw, however. If spaces are used, using a nonstandard indent size becomes impossible (without converting the file on save/load at least), which simply avoids the problem of ambiguous line lengths without actually solving it. Line length is also only meaningful if a maximum line length is specified, and if you can specify a maximum line length, why not also specify tab width?

Max line length is best enforced automatically, and the ambiguity only applies to those who use a non-standard tab width. Preventing people from using a non-standard indent size at all doesn't actually solve anyone's problem.

It's funny that this argument lives eternal, considering everyone seems to agree that:

  • Consistent style within a codebase is far more important than stylistic choices themselves.
  • Any editor should support either tab- or space-based indentation transparent to the method of user interaction.
median gyro
#

dotnet-format?

pale geyser
#

that is a formatter, yes

#

there are plenty of formatters for C# but they aren't even remotely as aggressive as rustfmt

patent kraken
#

"I've actually only seen one argument against tabs that I think truly holds water: If tabs are used, the length of a line becomes ambiguous, so enforcing a maximum line length for all users becomes impossible without mandating a specific tab width for this purpose.
". I don't agree with this argument as i don't see the need to make all users have the same tab size. I think being able to change the indent size without changing the code is a great part of tabs.

dusky nova
#

That wasn’t the point

#

The point was that indented code causes further rightwards drift on higher tab widths

patent kraken
#

again tab width is configurable in IDE's

dusky nova
#

Again, you missed the point

#

The point was that a user would be able to view the code using a tab width that the code was not written to support within the conventional line length constraints

#

Any more questions should go to @heady plank

heady plank
#

Yo. I have notifications on for this thread already because I like to allocate my time poorly. ferrisBut

thorn anvil