mdo/code-guide

Two spaces proof

Closed this issue · 16 comments

mdo commented

I don't mean to sound dick-ish or arrogant, it's simply matter of fact. If you use tabs, someone's dev environment might have 8-space tabs and you 4-space. With soft tabs, the same spaces in one piece of code can be copy-pasted to another person's computer and will render the exact same because a space is a space. One person's tab doesn't always equal another person's tab.

Out of curiosity is there any particular reason that you use 2 spaces instead of 4? For me personally I find it harder to see indentations when they are only 2 spaces long but it could just be what I am used to.

zg commented

You can fit more onto the screen, and you also save space by having two spaces instead of four.

I disagree.

It is more readable to use hard indents, and then mnify your code for
production.

Human readability is more important during development, and simple
minification like Grunt solves any specific issues for production.

Ganginator

Jesse Gangi
jessegangi.com
(218) 310-2447
jgangi@aerialapps.com
@Ganginator https://twitter.com/Ganginator

On Sun, Jul 27, 2014 at 9:09 PM, Zack Gold notifications@github.com wrote:

You can fit more onto the screen, and you also save space by having two
spaces instead of four.


Reply to this email directly or view it on GitHub
#102 (comment).

zg commented

Why don't you prefer the number of spaces I prefer!?

Sorry, didn't mean to start a war, was just wondering if there is any major benefit or logical reasoning behind using 2 spaces instead of 4. IMO the benefits that @zg mentioned are very minimal compared to the decrease in legibility that it causes (for me anyways).

I understand that everyone has their preference.
And I have much respect for you all, so I must state that there is no
negativity.

However, I do choose to do hard tabs in development for readability, and
then choose to minify in production after for performance.

Ganginator

Jesse Gangi
jessegangi.com
(218) 310-2447
jgangi@aerialapps.com
@Ganginator https://twitter.com/Ganginator

On Sun, Jul 27, 2014 at 9:45 PM, Josh notifications@github.com wrote:

Sorry, didn't mean to start a war, was just wondering if there is any
major benefit or logical reasoning behind using 2 spaces instead of 4. IMO
the benefits that @zg https://github.com/zg mentioned are very minimal
compared to the decrease in legibility that it causes (for me anyways).


Reply to this email directly or view it on GitHub
#102 (comment).

I don't think there is any particular reason to have 2 spaces instead of 4. Use what suits you (and your team) best. The goal of any style guide is to have a commonly agreed set of rules. Same goes for tabs. The important thing here is that all code in the project must look like it has been written by the same person.

zg commented

This issue was closed, and hasn't been reopened, so clearly he's going with two spaces.

I'm not debating that it should be anything else I am just asking what the reasoning was (if any) behind using 2 spaces instead of 4. He explained above why he chose spaces over tabs but he didn't really say why he chose 2 spaces over 4 spaces.

^ ?

mdo commented

Two spaces feels less of a waste of space and makes small chunks of code feel more related to each other. I'm just super used to it at this point—the number of spaces doesn't matter as much, so long as they are spaces.

@mdo thanks for your input. I'm a fairly new coder and am just trying to make sure I don't adopt bad habits that are much harder to break later on.

@mdo - Could your syntax tab rules be simplified to "Use soft tabs—they're the only way to guarantee code renders the same in any environment." ?? The reason for "two" also confounded me when I started learning your standards. Most other style choices seem to have a practical reason beyond your initial feeling.

Use tabs to indent, and spaces to align. Make sure the two don't touch. Simple.

That way, anybody can use whatever indentation size they want without breaking column alignment. Also, I can't stand reading code indented with 2-space soft-tabs. It drives me CRAZY.