a companion discussion area for blog.codinghorror.com

Death to the Space Infidels!


#81

That said, only a moron would use tabs to format their code.

  • unless you happen to be programming in whitespace or Python.

The python style guide PEP 8 actually says to prefer 4 spaces per indentation level; however, the python code base doesn’t follow these rules very carefully.

I’ve worked at exactly one organization that had a style guide they stuck to religiously. Other places have style guides, but:

  1. No one actually reads them.
  2. No one takes the time to convert legacy code to the new style, even if it’s just a change in indenting that could be automated.

Personally, I did find that a uniform style guide made me more productive at the one place that used it. I didn’t agree with all elements of the guide, but when I could count on everything being in a specific format, I could read other people’s code much more easily. It also helped that comment formating was standardized and that function contracts were required.

I think that the real solution is that language designers come up with a style guide that just comes with the language and is used by all standard libraries. Java does this, and people are much more likely to follow the java style guide than they are to follow a coherent style in a language like C++ where there is no standard style.


#82

I don’t understand the footnote-- in Python you still have the option of tabs or spaces. Code just needs to be indented consistently.

It it, however, recommended to use 4 spaces per indentation level.


#83

Death to space-indentation!
Long live tabs!


#84

But seriously, tab means indent. It has a semantic value. Space is a word separator… hence why you need an ugly hack like a bunch of them in a row to approximate an indentation.

With tabs, there’s no half-indentation. It’s simply impossible. With spaces, when you’re coding in a hurry it’s easy to get some off-by-one issues that aren’t quite noticeable but get irritating.

Just use tabs: saves bytes, saves user layout preference, saves time, saves sanity.


#85

Even though you can use tabs in python, I’d like to point out that PEP 8 declares that spaces are preferable (unless dealing with a legacy project that already uses tabs). PEP #8 is an interesting read in its own right, and is pretty relevant to this topic:

http://www.python.org/dev/peps/pep-0008/

Of course, PEP 8 is just the recommendation for the standard library - you can do whatever you want on your own projects (except for mixing spaces and tabs!). That said, I personally follow PEP 8 when I don’t have a compelling reason to do otherwise - I figure I could do a lot worse than emulating Guido!


#86

…Shneiderman found that when program statements were arranged in a sensible order…

… When statements were shuffled, the experts’ superiority was reduced.

From what you’ve shared, it seems more like the study was on formatted and non-formatted code, not much in the nuances of different formats.

Instead of spending time to convert everyone else to our beliefs, we should try to be as open as possible. The more focused on our own we become, the likelier we are to stop learning, and become stagnant. The more styles we are influenced by, the better we can become at adapting, scrutinizing and imitating.


#87

ok,
let me get this straight. DID JEFF ATWOOD JUST CALL ME A MORON?
seriously, a one who grew up on C, (which jeff did/could not)
i found it easier to press the tab key once and continue typing
instead of the two or more times required for the friggin spacebar.

i also found that if one is a meticulous geeky coder that most
of us are, WE TAKE THE TIME TO CUSTOMIZE EACH AND EVER PC WE SIT
AT AT AND CHIEF CUSTOMIZATION IS FIXING THE FRIGGING EDITOR SO THAT
TAB MEANS WHATEVER WE WANT IT TO!!!

that said, i am a moron so i could be wrong. tab is for look, space
is for syntax my dear GWBASIC-programming-none-C-learning-copy-and-paste-programming-so-must-use-spaces-CODE-NAZI!!!


#88

Let the team decide. The only rule I have is that once it’s decided, it’s used consistently. In my group we all set our formatting rules in Visual Studio to the agreed upon settings. Then it’s simply a matter of Ctrl-K, Ctrl-D to format the code consistently. I’ve even added a macro that in addition to reformatting, also updates the copyright header and sorts/organizes using statements (C#).

http://blueonionsoftware.com/blog.aspx?p=e40c1a15-6461-4224-b020-c66101bd07ba


#89

I’m still waiting for the time when your favorite IDE and SCM will take care of the coding styles, allowing different views for different programmers. This might be possible using metaprogramming frameworks with a model view on your code in the same way as a model view on your diagrams, eg. Janus MPS (as a mostly unrelated example).

This should NOT be an issue a programmer has to worry about.


#90

To paraphrase, the solution to almost all problems in computing programming is another layer of indirection. Some people prefer 2 spaces for an indent, some prefer 4, some prefer insert n. Having an indent character is just another layer of indirection that lets the user interpret what indent means. We just so happen to use the the ascii 0x09 as the indent character. There is as much reason to insert a specific number of spaces as your indent as there is to sprinkle your code with magic numbers. Barbaric…


#91

I do religiously format other people’s code. But not to my style preference, but to a specific coding standard [0]. This lead developer is leading by example. He’s making an effort to increase the overall readability and maintainability of the code. The way the paragraph is quoted makes it seem like the lead developer was merely changing things on his own accord and preference – which would make for an excellent TDWTF – but something tells me he wasn’t.

[0] The real problem with style standards is that most programming languages don’t have a single, authoritative oracle. And, naturally, everyone has an opinion. Fortunately, in C#, such a standard exists and its enforced by StyleCop. I spent a lot of time pushing for people to write style compliant code. And any great developer immediately sees the value in having a CONSISTENT codebase.

Consistency trumps personal preference (even my own) when I write code. This is what ought to be taught. Not just tabs vs. spaces.


#92

I never cared much about spaces vs tabs. What I do care a lot is:

int main() {
return 0;
}

versus

int main()
{
return 0;
}

I like the first example a lot more than the second. The vertical space saved is good and the clarity of the second is not that much greater since the identation already makes that block more visible.


#93

I like tabs because I find easiest to move around the code with the keyboard.

If I have to press 8 times the arrow key I get mad and grab the mouse to take the cursor where I want.


#94

a coworker says, People that columnize the code like tabs.

Where’s the article about the evils of columnizing variable declarations and assignments. I just think its harder to read each line, depending how far the spacing is could map the wrong value to the variable when reading, also requires the regex search instead of the simple myvar = version which is really less of a problem now days with the find all references feature.


#95

Let me put it in few and simple words: If you are worried about tabs contra spaces, you are using the wrong tool. Stop living in 1988. If your development environment is so ancient that this is a valid point of debate, you ought to give up programming and move into a retirement home.


#96

I don’t care, as long as everyone on the team uses the same.

To avoid a holy war, my team agreed on the default settings of our IDE (Eclipse).


#97

Use a format nazi tool like StyleCop and don’t allow check-ins unless code passes all its rules. :wink:


#98

That said, only a moron would use tabs to format their code.

Yeah, but I like 2 spaces. 4 is just stupidly wide.

If lovin’ tabs is wrong, then I don’t wanna be right. Please cancel my subscription.


#99

It would be easy enough to automate the formatting rules for a project. Parse tokenize, format, overwrite. You could also fix block formatting, operator spacing, etc. If there is a standard, you can auto-enforce it.


#100

Color of the bikeshed anyone? It’s amazing how we developers like to argue at great length about th most trivial crap. http://en.wikipedia.org/wiki/Color_of_the_bikeshed