3 ms·
Four of those were to catch formatting errors. IMHO it's best to just use an automatic code formatter. clang-format is extremely good. When I write code for pe
by nwallin 6y ago
Four of those were to catch formatting errors. IMHO it's best to just use an automatic code formatter. clang-format is extremely good.
When I write code for personal projects I don't even bother trying to format it correctly. The only whitespace button I use is the spacebar. tab is mapped to the function that reformats the entire document according to the formatting rules I've configured.
At work, whenever I apply a change in a function I will autoformat that function whenever. I can't just format the entire file, but formatting errors are rife in the codebase I work on.
goto fail; is real.
- wilsonrocks 6y agoBinding auto format to the tab key has blown my mind!
- llarsson 6y agoAlternatively, do it on save. :) gg=G in vim is fast enough to type for me, though.
- tdfirth 6y agoSecond this. I'm pretty happy writing code in a plain old text editor much of the time, without most IDE features. One thing I just can't live without, however, is a code formatter. Formatting code by hand is tedious and repetitive and I have no patience for it.
- nuriaion 6y agoWe made it part of our ci to test if all files are formated with the formater and i bound the formater to the save operation. So i can just write, save the file and everything is nice :)
- williamdclt 6y agoDefinitely. Install a code formatter, make it part of your linting process so that it fails your CI, run it on save in your editor, never have boring conversations about formatting ever again with your team.
- jedimastert 6y ago> tab is mapped to the function that reformats the entire document according to the formatting rules I've configured. Huh. you know...
- meowface 6y agoYeah, an automatic formatter and linter/language server handles the first 5 very smoothly. The 6th one (surrounding terms with word boundaries) is useful in many situations, but a lot of editors also support doing this natively; e.g. "Match Whole Word" in the VS Code search input fields. I don't want to be too cynical about the article, since these are absolutely all good things to know due to their myriad uses in other circumstances. But if your intention is to apply these to code you're writing, as the article describes, I don't think any of them are practical if you're already using an IDE/IDE-lite. (It probably makes a lot more sense if the author is using a lighter editor like vim without a lot of plugins, though.)
- douglaswlance 6y agoThe author uses VSCode: https://lemire.me/blog/2021/04/04/my-programming-setup/ https://lemire.me/blog/2021/04/04/my-programming-setup/