6 ms·
The solution is to have computers enforce the code style. Pick a linter, pick a set of rules, and then forget about them. Things I beleive: - If you're pickin
by xnorswap 2y ago
The solution is to have computers enforce the code style. Pick a linter, pick a set of rules, and then forget about them.
Things I beleive:
- If you're picking up on code-style in PRs then your toolchain is backward.
- If you're changing linting rules every month then you're focussed on the wrong things
- It's better to have a consistent style than a perfect style
- secondcoming 2y agoThis is what we did with clang-format on our code base. The result is occasionally ugly code and nobody is 100% happy but at least it's consistent.
- maleldil 2y agoGofmt's style is no one's favorite, yet gofmt is everyone's favorite.[1] [1] https://go-proverbs.github.io/ https://go-proverbs.github.io/
- maxwell 2y agoWhile everyone has a favorite ES Lint ruleset but few agree on which to use.
- gpderetta 2y ago*cough*clang-format off*cough*
- secondcoming 2y agoHa, yes. I started doing that but then lost the will to continue.
- bayindirh 2y agoYes. I love how gofmt has no settings, basically. Is this how you envisioned? Great. Now I don't have to think about optimizing it. Coincidentally, the choices they made are the choices I'd made, but it doesn't matter in the end.
- maleldil 2y agoIMO, gofmt doesn't go far enough. It should sort imports and break lines automatically, or you end up with different people with slightly different preferences for breaking up lines, leading to an inconsistent style. Something like gofumpt + golines + goimports makes more sense to me, but I'm used to ruff in Python (previous black + isort) and rustfmt. I'd say that if you're manually formatting stuff with line breaks and spaces, that should have been automated by tooling. And that tooling should run both as a pre-commit hook and in CI.
- bayindirh 2y agogofmt sorts imports within the block they are in. I have a habit of putting stdlib imports, a line break, golang experimental (x) imports, a line break and external imports. I just tested, gofmt orders imports within these blocks. If I won't use the line breaks, it'll consider it a single block and will globally sort. golang also aligns variable spacing and inline comments to look them as unified blocks (or a table if you prefer the term) and handles indents. The only thing it doesn't do is breaking lines, which I think acceptable.
- maleldil 2y agoI meant that you could do this with isort in Python or rustfmt with `group_imports = StdExternalCrate` (sadly, not the default), where the imports are automatically separated into blocks, which is basically what you seem to be doing manually. My point is that many things we end up doing manually can be automated, so I don't need to care about unsorted or unused imports at all and can rely on them to be fixed without my input, and I don't have to worry about a colleague forgetting to it either.
- bayindirh 2y agoI didn't know that so many people did that so formatters have an option for this. On the other hand, I'm doing this for so long across so many languages, I never thought about it. It consumes no effort on my part. Also, gofmt not removing the breaking lines and handling groups inside themselves tell me that gofmt is aware of these choices already and accommodates this without being fussy or needing configuration about it, and it's an elegant approach.
- bjourne 2y agoWhile Python has some great linters, I don't know of any in C that can correctly and automatically enforce some coding style. Most of them can only indent correctly, but they can't break up long lines over multiple lines, format array literals, or strings. Few or none knows how to deal with names or preprocessor macros.
- brandmeyer 2y agoclang-format and clang-tidy are both excellent for C and C++ (and protobuf, if your group uses it). Since they are based on the clang front-end, they naturally have full support for both languages and all of their complexity.
- xbar 2y agoAgreed. A healthy toolchain lets a developer separate the Craft from the minutiae.
- petesergeant 2y ago100%. Enforcing lint rules is very important. What those lint rules should say is generally very unimportant because the editor should be doing all the work, and most of the time "that's just like, your opinion, man".
- pugworthy 2y agoAgreed. I don't care what the indentation is or formatting is, as long as it's consistent.
- dsego 2y agoI sometimes care when I want to introduce empty space to visually make parts of code stand out, eg multiple blank lines between functions or classes etc. I think whitespace can be effectively used like paragraphs in a book, basically make different blocks more obvious. Most formatters just squash everything to be one empty line apart, for me it can be annoying.
- dominicrose 2y agoin my experience half the people don't bother installing the tools. They just don't care about formatting/linting, at all.
- TingPing 2y agoJust don’t make it optional.
- joshstrange 2y agoCompletely agree on all points. I used to have a style that I preferred and really wanted to use everywhere but nowadays I just throw prettier at it and take the defaults for the most part. I’ll take consistent code over mixed styles every day.
- CapsAdmin 2y agoI know this sounds insane, but I used to work on some big svn codebase with many developers, without any fancy formating tools AND no one cared about consistent style. One interesting thing that happened was the ability to guess who wrote what code purely based on coding style.
- bobthepanda 2y agoThis happens to some degree in linted code bases since there’s more than one way to write the same code, and people reach for what they like