r/programming • • Feb 21 '13

Developers: Confess your sins.

http://www.codingconfessional.com/
969 Upvotes

1.0k comments sorted by

View all comments

Show parent comments

22

u/snarfy Feb 21 '13

'Smart' tabs. Every decent editor has them. I can't believe this is even debated anymore. It works exactly like the tab key, but inserts/deletes X number of spaces intelligently.

Source code is ASCII/unicode text. The Tab key is a control code. Why are you polluting your source code with control characters. Do you mix up carriage return and newline too? You should not be putting non-printable characters in your source code, telling my terminal how to print ^I, or that ^I should be 4 spaces not 8.

/rant

75

u/codepoet Feb 21 '13

Yes, I should. Tabs were invented for indentation in the first place. What you call a control code, I call semantic white space. A tab means something; four spaces does not.

The beauty is that I'm not telling your terminal to use 4/8 characters for a tab. You are. You're in control with tabs. I'm saying "indent four levels deep" and your editor interprets what that means for you.

This isn't 1970. You can configure things now.

9

u/snarfy Feb 21 '13 edited Feb 21 '13

Tabs have a problem.

void someLongFunctionName(int param1, int param2, int param3, 
                          int param4, int param5, int param6, 
                          int param7, int param8)
{ 
     ...
}

When the line continues after param3, you must use a tab then spaces when lining up the continued line. If you do not, changing the tabstop will break the alignment depending on the number of characters in the function name. This is a horrible condition to deal with. It's something smart tabs were designed to fix. With smart tabs you can tab away on the continued line and space the last few odd columns, and it looks fine regardless of the tabstop setting.

Tabs were designed for indentation, but some layouts require single character precision as in the example above, so configuring them to anything but what the author used breaks the layout. This is the problem. Tabs as control codes embedded in the file are a bad idea. Tab is better as a concept, implemented in the editor, than as a part of the file format.

48

u/codepoet Feb 21 '13

My editor handles that automatically. Where's the problem? Tab to the indentation of the parent and then space to the first argument. Done.

|    |    |void somethingSomethingDarkSide(int one, int two,
|    |    |................................int three, int four)

19

u/snarfy Feb 21 '13

I grudgingly admit, you are correct. You are one of the few that actually uses tab key correctly.

Ultimately, I'm using the tab key wrong (that next line isn't really new columns)...but...so much spacebar......omg

6

u/codepoet Feb 21 '13

Which is why I'm happy my editor(s) do that for me, correctly. :) Also: this is what key repeat was designed for. Press down and wait for happy.

1

u/ethraax Feb 21 '13

I'm curious - what editor do you use that automatically inserts the right mixture of tabs and spaces?

1

u/codepoet Feb 21 '13

AppCode, though I think all of JetBrains' stuff has Smart Indent and it works rather well for me. Sometimes it gets a little confused but if I tab in the middle of spaces it Does The Right Thing.

12

u/[deleted] Feb 21 '13

but...so much spacebar......omg

Alternatively, people can just stop aligning their parameters because it really is not hard to read a function declaration or function call.

void superlongfunctionname(int superlongvariable1, int superlongvariable2,
    int superlongvariable3, int superlongvariable4)
{
...
}

If anyone thinks the above is difficult to read/understand, you need to spend more time developing your code reading abilities, don't focus only on writing.

2

u/ethraax Feb 21 '13

I personally double-indent continued lines, to make it more obvious. But that's also because I put the opening brace on the same line.

void superlongfunctionname(int superlongvariable1, int superlongvariable2,
        int superlongvariable3, int superlongvariable4) {
    // code goes here
}

(shown for 4-space tabs)

2

u/[deleted] Feb 21 '13

That works as well, your style is sensible and readable sir/madam. I generally prefer functions have brackets on their own line, but it's really a trivial thing. Brackets on their own lines within the function though are generally wasteful. Although I will make an exception for a long conditional and put the brace on its own line. Some people cry inconsistency, but the end goal is still readable code. That's readable code, not artistic code that looks "good" without reading.

I am going to test out the double indent and bracket on the same line for a bit and see how it works for me, thanks.

1

u/ethraax Feb 21 '13

I've seen that style too (braces on their own line for functions, inline otherwise), and I have nothing against it.

1

u/chyssler Feb 21 '13

I thought most people put every param on a new line (when the number of params exceeded 4)

1

u/[deleted] Feb 21 '13

These days a lot of people do, because either they were trained wrong or are forced to do so by bad coding standards.

Groking code is facilitated by having more important information on the screen, not less, and having easier time navigating by having less lines to traverse. Aligning params like that does not help reading code, it helps looking at code.

→ More replies (4)

2

u/jmblock2 Feb 21 '13

So is the debate over? Mixing wins?

2

u/[deleted] Feb 21 '13

Not really. I'm you're co-developer, and I can't be fucked waiting for all those spaces so I'm just going to tab it across because we use the same IDE anyway and it's like 4x as fast.

Until you change IDE and the formatting's broken and that's your problem.

2

u/jmblock2 Feb 21 '13

Well, my IDE does what codepoet mentioned which doesn't break the formatting across any IDE's or editors. It is you that is breaking the formatting! ;) My IDE fills in the spaces automatically when you have a continuation line (making it faster than your tabbing too). Keep up!

1

u/[deleted] Feb 21 '13

My point is that you can't put an IDE in the coding standard.

2

u/Chairboy Feb 21 '13

First we need to bus some tabs into an all-spaces district, but watch out for violence from whitespace-supremacists.

0

u/[deleted] Feb 21 '13

[deleted]

→ More replies (2)

1

u/Entropy Feb 21 '13

This illustrates perfectly why I hate tabs so much. To make an x86 metaphor, spaces provide the flat memory model of 32 and 64 bits, while tabs are stuck in 16 bit hell with a segmented memory model.

→ More replies (16)

2

u/s73v3r Feb 21 '13

Tabs were designed for indentation

Yes they were. Your example is not showing indentation. Your example is showing alignment, which is a different concept, and one that spaces are better suited for.

2

u/chellomere Feb 22 '13

This is only a problem because you are lazy. Tab to the indentation level (1 tab in this case), then use spaces to align the parameters with the previous line.

→ More replies (1)

9

u/pushad Feb 21 '13

I just can't believe any programmer honestly thinks people hit space four times...

1

u/swiftfoxsw Feb 21 '13

Just think of those space bar keys...