Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spaces vs. Tabs -- Best Practice? [closed]

I used to be a tab freak -- I would always use tabs to indent my source code, and if I saw any spaces, I would instantly do a regex search/replace to replace all leading spaces with tabs.

...until I realized that I hadn't noticed the presence of a lot of the spaces in some files, such that they opened up inconsistently in different editors (e.g. Notepad++ vs. Emacs vs. Visual Studio).

What are good reasons for why one is better than the other in general? Is either one generally known as better practice?

like image 413
user541686 Avatar asked Jan 19 '11 06:01

user541686


1 Answers

With good text editors, it does not really matter. It is just a technical background detail. The UI behavior will be just the same.

The only important thing here is that everyone in a project makes the decision what to use, and that everyone sticks to that. Because, as you discovered, there will be problems if both tabs and spaces are used for indentation inside a file.

UPDATE: When I mean that everyone in a project makes the decision what to use, I of course mean that everyone should agree on the same decision. :D (This can be the tricky part.)

like image 192
Johan Kotlinski Avatar answered Sep 18 '22 12:09

Johan Kotlinski