{"id":1061,"date":"2015-05-27T12:43:34","date_gmt":"2015-05-27T12:43:34","guid":{"rendered":"https:\/\/guwii.com\/?p=1061"},"modified":"2016-08-01T09:42:17","modified_gmt":"2016-08-01T08:42:17","slug":"tabs-vs-spaces-for-indentation-in-coding","status":"publish","type":"post","link":"https:\/\/guwii.com\/tabs-vs-spaces-for-indentation-in-coding\/","title":{"rendered":"Tabs Vs Spaces for indentation in Coding"},"content":{"rendered":"
This is one of the most trivial areas of coding that people argue over, often bringing up very nitty, and picky points as a point of reasoning.<\/p>\n
There is annoyingly, good reason to argue though. The indentation method you choose for your coding can have very surprising knock on effects in the future, so which one should you really use?<\/p>\n
And before you even start reading, if you currently have no preference or opinion<\/em>, I’m going to give you the answer. Spaces with 2 indents are the go to answer that are generally most widely accepted and used, especially by big companies (Facebook \/ Stripe \/ Twitter API’s etc), so if you’re just starting out with coding, or have never even given it consideration before, 2 indented space’s are the go to method – this is the most commonly used setup, and unfortunately it’s better to just fit with the norm, unless you have strong opinions otherwise, but it’s generally these pointless arguments that just fragment the situation even further. But why? Not all operating systems, code editors\/IDE’s treat code indentation the same way. Tabs are the most common problem, some code editors will treat each tab indent as very small, where as others will treat it like a huge block. This leads to not all code indentation looking the same across multiple developers systems. With spaces you do not have this translation problem, a space, is always just 1 space.<\/p>\n The reason most companies\/API’s\/libraries etc choose 2 indented spaces is:<\/p>\n The most important thing is that all of your development team choose an indentation method, indent size and stick with it. However, I generally urge towards spaces<\/em> for indentation, as that’s the most common indentation method. If you’re a Sublime Text user you can add these rules to your
\nFor coding indentation, you should use:<\/p>\nSpaces – with 2 indents<\/h1>\n
\nHowever, it’s important you use the same method as the rest of your development team (or try and get them to change ;)), consistency is the real best answer. So if that means using tabs, then so be it.<\/p>\n
\nThe way in which you indent your code may seem trivial, and for the most part it usually is. But it’s not until everything goes wrong that you really wished you had chosen the correct method and stuck with it.<\/p>\n\n
\nNot only that, use 2 indented space also, as most libraries\/API’s you may import\/use in your projects will generally use this spaced indenting method. So if you’re using tab indentation, you will have to convert the imported libraries to tabs.<\/p>\nPreferences.sublime-settings<\/code> file to ensure tabs get converted to spaces and also use 2 spaces as a default indentation level:<\/p>\n
\r\n
\"tab_size\": 2,\r\n\"translate_tabs_to_spaces\": true<\/code>\r\n<\/pre>\n