This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.

Title

Tabs vs. Spaces ... and how many?

Description

Encodo has long been a two-space indent shop. Section 4.1 of the <a href="{www-en}documents.php#csharp-handbook">Encodo C# Handbook</a> writes that <iq>[a]n indent is two spaces; it is never a tab.</iq>, even though <iq>[t]he official C# standard [...] is four spaces.</iq> and that, should you have a problem with that, you should <iq>deal with it.</iq> Although we use our own standards by default, we use a customer's standards if they've defined their own. A large part of our coding is now done with four spaces. Some of us have gotten so accustomed to this that four spaces started looking better than two. That, combined with recent publicity for the topic<fn>, led me to ask the developers at Encodo what they thought. <ul> <b>Urs</b> was open to the idea of using tabs because then <iq>everyone can use whatever he likes and we can avoid the unnecessary discussion about the ideal value (why does it have to be an even value? I want 3 spaces!!!) Further, we might be able to save some disk space ;)</iq> <b>Sebastian</b> was emphatically <i>not</i> open to the idea of tabs because <iq>Tabs is just a lie. There are never only tabs. I've seen multiple projects with tabs, there are always spaces as well and this breaks the formatting depending on your settings.</iq> <b>Wadim</b> pointed out that <iq>the tab key produces a character that is used for indentation</iq>---heavily hinting that people who use spaces are doing it <i>wrong</i>---and then backed up <b>Urs</b> by suggesting 3 spaces per tab. <b>Fabi</b> cited <a href="https://blog.codinghorror.com/death-to-the-space-infidels/" author="Jeff Atwood">Death to the Space Infidels!</a>, <iq>What <i>does</i> matter is that you, and everyone else on your team, sticks with those conventions and uses them consistently,</iq> then expressed a preference for two spaces, but agreeing that four might be easier since that's the standard used by other companies. <b>Remo</b> backed up <b>Sebastian</b> in saying that tabs are bad, writing that <iq>I have worked on projects where we tried to use tabs. But this always ended up in chaos somehow.</iq> Two or four is fine---the longer you work with one, the odder the other one looks. <iq>Personally I think using 2 or 4 spaces takes some time getting used to it. After that, both are well suited to read code with a slight advantage for 4 spaces because the "column" widths are wider and it's therefore easier to find the closing braces when scanning vertically (our screens are really wide - so the loss of valuable space is no longer an argument).</iq> <b>Pascal</b> was along the same lines as <b>Fabi</b>. He made a good point for spaces, writing <iq>I personally prefer spaces since it takes the whole configuration in all the tools out of the picture at once.</iq> <b>Robin</b> also pleaded for consistency above all, writing <iq>I like tabs more</iq> and <iq>I'm used to a width of 2 spaces</iq>. <b>Marco</b> see the advantage of tabs for customization, but understands that it will probably lead to time wasted converting whitespace. He's accustomed to 2 spaces and Encodo has a <i>ton</i> of code with two spaces. Although <b>Fabi</b> says he sees a lot of code with four-space indents, Marco's seen a lot of code with two-space indents. </ul> So, with the rewrite of the <a href="{www-en}documents.php#csharp-handbook">Encodo C# Handbook</a> in progress, what will be our recommendation going forward? Let's summarize the opinions above: <ul> Consistency is paramount (Fabi, Pascal, Robin,...pretty much everyone) Using tabs has, in the past, inevitably led to a mix of tabs and spaces (Marco, Sebastian, Remo) An indent of 3 spaces would be nice (Urs, Wadim) Everyone else likes either a four-space indent or two while others don't really care either way. Nobody wants eight<fn>. </ul> So, we have emphatic arguments against switching to tabs instead of spaces. Although there are good arguments for a 4-space indent, there are also strong arguments for a 2-space indent. There's no real pressure to switch the indent. Encodo's 2009 recommendation stands: <b>we indent with two spaces</b>. Deal with it.<fn> <hr> <ft>If you're watching <i>Silicon Valley</i>, then you probably already know what prompted this discussion. The most recent episode had Richard of Pied Piper break of a relationship with a girl because she uses spaces instead of tabs.</ft> <ft>As Richard of Pied Piper recommended, which is just insanity.</ft> <ft>We use the <i>EditorConfig</i> plugin with all of our IDEs to keep settings for different solutions and products set correctly. The config file for Quino looks like this: <pre> # EditorConfig is awesome: http://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] indent_style = space indent_size = 2</pre> </ft>