Hacker News new | ask | show | jobs
by tmm 1487 days ago
This is the approach I took when I was teaching myself C in the late '90s. Indent with tabs, align with spaces intuitively made a lot of sense.

Then I started using code formatters, initially `indent', then vim plugins. Eventually, I found myself using Visual Studio professionally, and became content letting the IDE decide how code should be formatted. Now, I do whatever the language/community seems to prefer. For .NET stuff, Visual Studio defaults; Go and Rust have their own formatters, RubyMine defaults for Ruby, etc.

Everywhere I've worked whenever the code formatting debate comes up, "use the IDE/compiler/community standard" always wins the day. The hardest thing seems to be convincing Windows users that text files need to end with a newline. Is there a git option (like `autocrlf') for that?

3 comments

You can set up an Editorconfig[1] file to automatically fix trailing whitespace and insert the final newline, among other things. Most editors have support for it (either built-in or in a plugin).

It's a lifesaver when you care more about formatting than any of your coworkers and can set up something that handles it for them.

Additionally, configuring editors/IDEs to format code when the file is saved is very useful to enforce formatting rules.

[1]: https://editorconfig.org/

I had the same experience with Java and its looong lines of AbstractFactoryFactoryBuilders. Tabs + spaces offered the best of both worlds, and enabling whitespace visibility.

In the end it doesn't matter what's my preferred way of indenting code, the hardest part is always making people agree on it. So whenever a new project starts and the team needs to define code styling, we go with the language/IDE defaults. Anything else requires IDE setup and attention to indentation, which is too much to ask for when people barely pay attention to code quality.

> Indent with tabs, align with spaces intuitively made a lot of sense.

gofmt does this.

> use the IDE/compiler/community standard

gofmt does this too :-)