What do you think about two-space indenting?

I noticed that languages invented in the last five years mostly adopted 2-space indenting.

I am happy that Rust was invented before this trend and its coding style has been fixed to 4-space indenting.

Two-space indenting is very ugly as it looks to me. I hate it.

How do you think?

2 Likes

I would rather starve to death than work for a shop that dictated 2 space indenting.

The only reason I can imagine for 2 space indenting is that they want more space to the right to accommodate far too many levels of nesting and/or cram more code into ludicrously long lines.

Both of which are serious "code smells" to me. Likely that want to cram everything into thousand line long functions as well.

I mean really, when you get down to two space indenting it's so little. Why stop there? Might as well have no space indenting. Pretend you are writing in good old line numbered BASIC.

Luckily no project I have worked on since the days of line numbered BASIC has had such a silly notion.

No, despite programming being some kind of logical exercise, aesthetics and readability are important.

Purely personal opinion of course. But such is the question.

5 Likes

I am so happy that you and me share the same feeling.
Yes aesthetics is very important.

1 Like

Personally I prefer 2 space indentation. But I usually go with the flow for whatever language I'm using.

And no, I don't nest deeply either :stuck_out_tongue:

6 Likes

For me, two space indentation is fine. I find it perfectly readable. I find editors are pretty good at interpreting which indentation style a file uses so return inserts the correct whitespace by default.

The main thing I look for is consistency, having rustfmt or similar run on save really helps. Ideally with default settings so that it is easier to have consistency between different projects.

3 Likes

Hope fully you have bigger spaces than I do. Twice as big :slight_smile:

1 Like

In olden days, the 8-space indentation is the norm. Remember that a tab character automatically converts to 8 spaces?

I have disliked 8-space indentation ever since I knew of it. I always feel 4-space indentation is perfect.

I can't figure out why people like to go from an extreme to the other extreme.

1 Like

That is something I wish everyone would get behind.

Just use "rust fmt" with it's out of the box settings. Resist the temptation to tweak this and that "just so" how you like it.

Then the Rust community around the world would produce a nice consistently formatted ocean of code. Ultimately familiar to everyone, easy to read, and no surprises.

For my part I don't agree with everything rust fmt does out of the box. I just let it do it and accept the result. Then at least I don't have to waste anytime thinking about formatting and tweaking with this and that. And I'm doing my best to contribute to that global Rust ocean of code styled in a familiar way.

6 Likes

Could you list some of those languages which adopt 2-space indenting?

2 Likes

While having a language wide "standard" (rustfmt in this case) is something I value very high, I always wondered why no language went for 1 tab as intendation.
As far as my knowledge of editors goes every single one of them supports variable tab width so everyone could be happy.

1 Like

I remember I have seen Google Dart, Microsoft Verona, Facebook Hack, and recent code of Kotlin by Jetbrains. Old code of Kotlin used 4-space mostly.

I was there in the olden days. Never worked on a project with 8-space indentation, despite being around many different projects, companies and languages.

I remember when TAB moved you to the next tab stop in your line. It's a position in the page not a fixed number of spaces. TAB does not mean "n" spaces. It means align with the next tab stop. Which could be any number of spaces and be different across the page. I'm sure modern day word processors still do that, emulating the mechanical typewriters of decades ago.

This whole notion that TAB is just insert 2, 4, 8, whatever spaces is a corruption of what TAB was.

4 Likes

I mostly agree with what you said, but sometimes I felt the need to add a little #[rustfmt::skip] here and there.
For example when there are multiple nested loops with a clear pattern in the ranges and they all align up properly.

1 Like

What do you mean? How much space is that "1 tab" ?

Well that's exactly it. It depends on the setting in your editor and as such everyone could have their code indented as they want it.

3 Likes

Though just like indenting standards, there is of course a default for tab width, and an environment with a significantly different default would be grievously at fault. I haven't tried to use proportional fonts for much coding, but I bet tabs would be a superior formatting solution there.

I used to use tabs exclusively with languages including Python and Haskell, and up to fairly recently without any complaints. Now that's incorrect per policy in those languages, but if that policy existed from the beginning it's news to me. The real problem with it is not that it's frowned on, but that I run out of horizontal width too fast.

1 Like

I'm fine with that. Display the source whichever way you like in your editor of choice.

As long as the source you let free into the world has no TABs in it, only spaces. TAB has an unspecified meaning. We don't like UB in Rust world, right?

I'm not sure since I'm no expert at utf8, but I thought tab is a whitespace character and as such should be treated from rustc as any other whitespace.

Oh boy. That is another can of worms. Proportional fonts have no place in coding. But hey, if you like your editor to use proportional fonts go at it.

1 Like

What you are talking about there is Unicode. utf8 is just a way to encode Unicode, among others.

Of course a TAB in Unicode must be white space. I presume rustc treats it as such.

But how much space? I have no idea.