Hacker News new | ask | show | jobs
by wwweston 2496 days ago
In case anyone wonders why someone might answer "both" (other than an entirely undisciplined approach):

Tabs for line indentation, spaces for every other kind of alignment is one philosophy. It's the one that seems to hit the sweet spot for most of the issues that I care about (cross-editor consistent yet flexible management of line indentation depth as controlled by hits of the tab key + tabstop setting).

But if you're running the project and decide spaces are The One True Way™, I'll figure out a way to get the editor to do it for me and ask you for a raise for the trouble (and, of course, market standards). ;)

4 comments

> I'll figure out a way to get the editor to do it for me and ask you for a raise for the trouble

You don't have to "figure out" anything. It's the default of every IDE I've ever used.

I press tab, VSCode inserts 4 spaces. I press shift+tab, it deletes 4 spaces.

Nobody actually presses spacebar 4 times to indent unless they are forced to use vim on some remote machine.

> It's the default of every IDE I've ever used

Which is probably not every IDE or editor.

> I press shift+tab, it deletes 4 spaces.

How entirely intuitive and not-awkward compared to hitting delete.

> they are forced to use vim on some remote machine.

Vim is not exactly unpopular as an editor of choice.

But overarching all that -- the ;) at the end of my comment should have been a clue that I was not sincerely arguing that figuring out how to use spaces for tabs is an involved task. Even somebody using vim (whether forced or by choice) should know `:set expandtab`. Most editors worth investing in will provide a convenient way of doing this.

Rarer are the editors that will also let you change indentation width on the fly while expanding tabs to spaces, though, which is generally easy if you use tab characters for indentation. I'm not super familiar with VSCode, but having just fired it up and tried it out, maybe it can do this if you turn on Detect Indentation, though it doesn't seem to be the default, and I haven't put it through the paces for less trivial cases.

> How entirely intuitive and not-awkward compared to hitting delete.

Try it, you'll like it. Especially when you want to untab an entire block of code instead of just one line.

- Highlight entire block of code

- shift+tab unindents entire block (whereas delete would delete entire block)

Plus, once you know a lot of shortcuts, `shift` seems to be sort of a negating key so it actually starts to be intuitive. (i.e. in vim, if you are searching for a string, "n" will move to next match, "shift+n" will move to previous match)

> > they are forced to use vim on some remote machine.

> Vim is not exactly unpopular as an editor of choice.

I think by "some remote machine" he's implying "default configuration", because vim can be configured to insert spaces; I would know, I have mine set up that way.

You can actually just press delete and it will delete a full tab-stop’s worth of spaces.
>Nobody actually presses spacebar 4 times to indent unless they are forced to use vim on some remote machine.

My PhD advisor does... His preferred editor is vi (not vim, but vi)

> Nobody actually presses spacebar 4 times to indent unless they are forced to use vim on some remote machine.

Totally, hazard pay factor. ;)

..but I do it because of habits learned in python shell and also because of that cowboy character on the Simpsons cartoon that called himself OCD about the number 4 and then counted 1,2,3,4 tapping his foot and shooting his gun into the air.

That was only necessary in Python shell briefly because of a bug. The bug was supposed to be a release blocker, but accidentally got marked incorrectly. It's fixed now, and has been for some time.
> Nobody actually presses spacebar 4 times to indent unless they are forced to use vim on some remote machine.

Even then, you can just use >> and << in vim; as long as it's set up correctly it'll insert spaces.

Works with whole sections in visual mode too ("v, down, down, down, >" will indent four lines).

Are you sure you meant vim, not vi? 'Cause...

:set expandtab

I answered "both" because I'm not running all of the projects I'm working on and some of them prefer tabs and others spaces - so I just go with the convention that that particular project uses.
This is why tools like gofmt is great. No more debates about spaces vs tabs.
The problem with “tabs for indentation, spaces for alignment” is that it voids the claimed tab-benefit of “anyone can configure tabs to be whatever width they want”.