I used to be a tab freak -- I would always use tabs to inden开发者_如何学Got 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?
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.)
精彩评论