site banner

Friday Fun Thread for November 22, 2024

Be advised: this thread is not for serious in-depth discussion of weighty topics (we have a link for that), this thread is not for anything Culture War related. This thread is for Fun. You got jokes? Share 'em. You got silly questions? Ask 'em.

2
Jump in the discussion.

No email address required.

Which indentation style do you prefer?

IMO, Ratliff makes the most sense, because it's the only style that reduces the number of tabs after typing the closing brace, rather than before.

if(this){
	that();
	if(nothing){
		something();
		}
	}else{
	other();
	}

Indentation style is a problem for the IDE. The user should never think about it.

I find it disconcerting and nonsensical for the IDE to automatically delete a tab before the cursor when the user types a closing brace in non-Ratliff styles. Also, I'm not much of a programmer, but I imagine that writing a program to pretty-print code in non-Ratliff styles must be a major hassle, because it would force you to move the cursor backward and then forward again after finding every closing brace.

Lack of spaces makes it harder to read for me, but otherwise for work code, it's coded into the IDE and whatever it is it is, I usually don't spend any mental energy dwelling on that. For my own code, I usually have everything set up for K&R.

Rust's default indentation that cargo fmt forces on everyone is pretty solid and I am super happy that literally everyone uses the same style everywhere.

Not everyone uses rustfmt, and it's configurable anyway. So I wouldn't say that everyone uses the same style.

I don’t understand why more people don’t recognize that Allman is clearly superior.

Certainly I prefer Allman, because it delineates blocks better.

If you get paid by the line, then it certainly is.

K&R, accept no substitutes.

It's logically consistent, space-efficient, orderly and readable. The others don't even come close.

While Visual Studio and C# are my drugs of choice, the worst thing about them may be the default linter & style guide's insistence on Allman.

K&R has always been the best, and as you say, it's not close.

I prefer K&R with mandatory braces around single-statement blocks.

Whatever the linter thinks is ok

There's a saying "code should be written to be understood by humans first an only incidentally executed by a machine".

None of them are actually harder or easier to read, it's just a matter of familiarity. You need to train your brain to quickly parse code and tweak that for new indentation styles.

You're going to have a better time if you just learn to read the most common styles quickly. You're inevitably going to be reading a lot of other people's code.

I like otbs. It's K&R without skipping braces on one liners, which can lead to bugs on a messy merge.

This looks very wrong to me. Closing brace being at the same indentation as the start of the block is what makes sense to me.

if (condition) {
    do_it();
}

This is my preference, but I'll work in whatever the code base I'm playing in already has.

Agreed. I also prefer two spaces of indentation to four, four is just such a waste of space for (imo) no readability benefit.

The thing is that indentation should be tabs. Then everyone can set whatever depth they want their tabs to render as.

That's fair. I do wonder why tabs are so widely hated, given the flexibility like you said.

Because there's usually a rule about maximum line length, in order to keep lines fitting inside the screen or window. Variable-length tabs play havoc with that rule, and auto-formatters would be constantly flipping lines back and forth as code was touched by different developers. Which introduces a lot of extra noise into commits.

Not to mention that sometimes we use tabs to deliberately format things into columns, not just indent code. Variable-length tabs throw that off.

All in all, the gains from having the code look the exact same for each developer outweighs the individual aesthetic gain of your preferred tab size.

,>Because there's usually a rule about maximum line length, in order to keep lines fitting inside the screen or window.

There's really no need for this anymore, it would be trivial to have the editor wrap the line in a nice way (go has no line length limits in the official style guide).

Not to mention that sometimes we use tabs to deliberately format things into columns, not just indent code. Variable-length tabs throw that off.

That's just an abuse of notation. Spaces are for alignment.