5 ms·
unless you have anything aligned in columns then all bets are off (something which many code formatters can do automatically for you e.g. lists of bindings)
by joncampbelldev 9y ago
unless you have anything aligned in columns then all bets are off (something which many code formatters can do automatically for you e.g. lists of bindings)
- scrollaway 9y agoTabs for indentation; spaces for alignment; I don't know why you'd want to insert tabs in the middle of a line. Also, most people who do have several years of experience under their belt will tell you: don't align. Mid-line alignment is a waste of a maintainer's time to have to update alignment blocks every time you add/remove variables... and statement-alignment is unreadable[1]. [1] https://github.com/pennersr/django-allauth/blob/a44134688f5be0a26f5e93b607f8c4e3f5b0782b/allauth/account/views.py#L685-L688 https://github.com/pennersr/django-allauth/blob/a44134688f5b...
- hn_throwaway_99 9y ago> Tabs for indentation; spaces for alignment On a large code base with multiple committers, I've never seen this rule followed consistently. In fact, I think this shows a poor engineering decision: "Let's make a rule where everything looks OK 95% of the time, except when you change tab widths (which is, presumably, why we made the rule in the first place.)"
- tomsmeding 9y agoWell everything looks OK 100% of the time if everyone followed the rule. Sadly, human history tells us that's an invalid assumption to make.
- bpicolo 9y agoForcing people to remember relatively minor things is a poor use of headspace. Enforce a code formatter/linter, make the test suite success dependent on it, and never argue again.
- benibela 9y agoI often run into trouble with IDEs that think they are smart, but aren't. "I see you have a space following a tab, so I will replace all your spaces with a tab, whenever you save the file"
- fao_ 9y agoI don't see how that code is unreadable, but for me it isn't representative of how I would align that block anyway.
- simias 9y agoI do find properly aligned code easier to read in general, I'm not willing to give that up. The crux of the issue is poor tooling. Aligning correctly is a pain because most editors suck terribly at it. For instance neither emacs nor vim align correctly when using tabs by default (they use as many tabs as they can and then pad using spaces, instead of indenting only with tabs and aligning only with spaces). If they did it would be painless to indent and re-indent. When some of the most venerable code editors out there can't even seem to get it right I think there's no point in fighting it. Learn to stop worrying and love the space, I know I did. Or alternatively use a language like go which provides a standard tool to indent everything, make it mandatory pre-commit and never look back.
- scrollaway 9y agoYeah; the correct answer to a good codestyle is good tooling; high quality automated tooling. Things like gofmt and prettier are excellent. yapf and clang-format are also pretty good, but need a lot of set up. But I never found a single editor that handles spaces correctly. I currently use vscode with vim bindings and whenever I deal with a space-indented codebase I want to tear my hair out: I inconsistently have to hit backspace sometimes once, sometimes multiple times to get rid of an indent level in insert mode. And don't get me started with yaml, a really painful experience to edit it.
- tomsmeding 9y agoCan't vscode automatically remove an entire indentation level with a single backspace? Many editors can do that, maybe with a non-default setting, but regardless.
- coldpie 9y ago> Tabs for indentation; spaces for alignment; If you try this, it fails for people who use a different tab size than you, which is the whole supposed point of using tabs. But yes, the correct answer is don't align. Utter waste of time.
- treehau5 9y agoThis entire thread is why I love gofmt so much. I haven't thought about this useless bullshit for years.
- coldpie 9y agoMyself, working on an old open source project, I just don't care. Match the nearby style best you can, use your own style on new code, who cares, get on with your work.
- Gracana 9y ago> If you try this, it fails If it fails, then you have not understood and you are not using your tools correctly. If your alignment depends on tab width, then you are not using tabs for indentation and spaces for alignment, you are using tabs for indentation and alignment and spaces for alignment, which of course breaks when you change your tab width.
- deleted 9y ago[deleted]
- coldpie 9y agoAh, I see what you mean. I've never seen an editor work this way, normally they just swap spaces with tabs, leaving however many spaces can't be swapped. Which is probably why I've never seen tabbed code in the real world that doesn't look like utter garbage.
- pseudalopex 9y agoThis was definitely a problem back in the day, but I think most popular editors do the right thing now. And like you say, alignment is usually a waste of time anyways.
- tomsmeding 9y agoThe alignment in that link is laughable. Please use newlines and an extra indentation level. I believe older versions of Xcode did that by default with objc (maybe still; didn't check lately) if you press enter in the middle of a function argument list. Really annoying.