Settings

Theme

Avoid aligning keys and values in source code unnecessarily

databasesandlife.com

4 points by adrianmsmith 22 days ago · 6 comments

Reader

Juliate 22 days ago

Diff tools have managed pretty much well this formatting issue (ignore whitespace) so it's not really a topic anymore.

  • adrianmsmithOP 21 days ago

    Interesting. Yeah I did think maybe this could be solved by more tooling. But at my place it work it isn’t, at least at the moment. Perhaps I could change that.

    Do you have any info on what I could use to make the command-line “git diff” and “git rebase” handle this style of formatting? Ideally so the latter merges and produces code which matches “gofmt” output?

    On the other hand I suppose my point is that even if there were such tooling, using style of formatting doesn’t offer enough (any?) benefit to justify the effort of introducing the tooling.

    • Juliate 20 days ago

      Context matters, but this what I would do (and I always apply when landing in a project, own or client, that has no documented or enforced code style):

      1/ always have pre-commit hooks running lint/fmt, and document how to implement them in a common fashion in the team,

      2/ strive to follow the language conventions (and if not, have those divergences explicitly defined in the linter/formatter tool configuration), this helps the team to align with it,

      3/ having a job server-side that blocks merging PRs that do not pass both of these steps.

      • adrianmsmithOP 19 days ago

        Thanks. We're doing all that.

        But that doesn't help when you do "git rebase" and there's a large conflict which you have to resolve manually, caused by two people changing different lines, and one or both of those lines caused the formatting of the whole block to change. That's the source of my frustration.

elzbardico 22 days ago

You can pry my alignment format rules out of my cold dead hands.

I Absolutely love how the use of white space makes things more readable.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection