Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Google use 2 spaces instead of 4/8/whatever? [closed]

Tags:

Does anyone know why Google's coding standards (C++ Style Guide e.g. but I think the same applies to others as well) use 2 spaces for indentation instead of 4?

like image 939
helpermethod Avatar asked Dec 19 '10 16:12

helpermethod


People also ask

Why does Google use 2 space indentation?

Why does Google use 2 spaces for it's coding standards? I believe the idea is that you want to maximize the information density of code on the page, while still having enough white space that indentation is easily visible. 2 spaces seems to accomplish both.

Should tabs be 2 or 4 spaces?

1. Indentation: tabs vs spaces. Java: 4 spaces, tabs must be set at 8 spaces. Both are acceptable.

Why does Google use spaces instead of tabs?

If a couple of people work on same file it is highly possible to generate unnecessary conflicts. Using spaces instead of tabs makes it possible to easily catch such an accidental space on eyeball and this is probably a reason, why using them become a standard.

Do people actually use spaces instead of tabs?

David Robinson, the data scientist who performed this study found that programmers using space over tabs made an average of 9 percent more each year than their tab using counterparts. Read below to find out more about the use of proper indentation in coding and how it can benefit you as a programmer.


1 Answers

The only reason I can think of is deeply nested code: with 4 spaces and a sufficient amount of nested if, loops or whatever, the leftmost half of your monitor will be obviously blank, if you're using a low resolution.
Personally I would always prefer 4, but I can see why somebody might want less than that while writing HTML, for instance.

Personal preferences really - most editors will use 4 spaces by default.

like image 50
Razor Avatar answered Oct 07 '22 16:10

Razor