Hacker News new | past | comments | ask | show | jobs | submit login

I prefer spaces purely out of consistency reasons.

Some systems say a tab is 8 spaces, others say it's 4. Some editors can set a tab to any customizable N spaces. But a space is always a space so your code will look like you intended (or should I say indented) it no matter who's looking at it.




While I agree with you personally, I could see the counterargument of: A tab is always a tab, and I can tweak my IDE to render a tab as however many spaces I like (2, 4, 8, etc) without changing the code.


> I can tweak my IDE to render a tab as however many spaces I like

Sure, IDE's are easy (though many people use multiple IDE's and/or editors across multiple machines).

I've also got a couple diff tools, a few VCS's, also the online parts of VCS like web-based pull request review UI's.

Tabs also tend not to play as nice with vertically aligned elements, if you prefer that for things like say the '.' on multi-line chained method calls, or longer function parameter lists.


I'm a tabs for indentation, spaces for alignment person myself. A multi-line statement should have the same number of tabs on each line. Any line after the first should then have spaces as needed.

I'll work without complaint or changing it with any existing code whether spaces or tabs. Mix the two for indentation however and fixing it is the first commit I make before touching anything else.


In a lot of cases though, you can't change what a tab is (consider looking at code on GitHub).


You can on Github but it requires using `?ts=4` in the url or committing an editorconfig file. Perhaps there are extensions that do it automatically.


This is a good point. Maybe at some distant point in the future we will softly decouple formatting from code by delegating it all to finely tuned autoformatters, or totally decouple it by storing code in a slightly more abstract form such that whitespace rendering becomes largely a presentation preference.



I don't understand this reasoning, I can set my editor to show x-spaces at the beginning of a line as however many I want. So I can make code indented with 2 spaces look like it was indented with 4.


That approach doesn't work if you use spaces both for indentation and alignment, you'd only want to multiply the indentation spaces. What editor has that setting?


Why would you "intend" for your indentation levels to be a certain pixel width on the reader's screen? Shouldn't that be the reader's choice?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: