views:

338

answers:

7

The more I browse the code to open source projects in languages that aren't Python, the more I realize that it seems a lot of programmers don't believe in proper indentation. (I won't mention any projects specifically to avoid having anyone take this question too personally.) Usually code is indented, but in a way just different enough from the standard style that it drives me crazy, especially in old/crufty code. I've noticed that when I write in C-like languages, I tend to indent correctly as religiously as when I'm writing in Python, with the exception of debugging code that I actually want to stick out like a sore thumb. Given how easy it is with a modern IDE to fix incorrect indentation, what are some rationales for not religiously keeping indentation in sync with braces?

+10  A: 

Most cases of this problem that appear in the source base I work on most of the time are because of intermixed tabs & spaces. In one person's editor, with tab stops set every 4 characters, it looks fine, but on another person's system with 2 or 8 space tabs it looks awful. You can rearrange those numbers however you want; some files are messed up regardless. Changing the spacing is a giant pain for merging down the road, so it just never gets fixed.

Carl Norum
+1: Tabs in source code is a terrible idea unless everyone is using the same tab spacing. Which won't be the case in an open source project.
Groky
It's really just mixing the two that's a problem. Using tabs consistently is actually ideal, because then everyone can set how far an indent actually indents. But that's so impractical that I still don't use tabs at all.
Chuck
I'm with Chuck - in my office we all use tabs, and we all get to see what we like. Works like a charm.
Ray
I don't like tabs. There are plenty of tools out there that don't have adjustable tab spacing, and 8-space tabs are ridiculous, even with widescreen monitors.
Carl Norum
The fact that some tools force eight-space tabs is an indictment of those tools, not tabs themselves. That's like criticizing C because it only allows eight-character names.
Chuck
@Ray - I'd say you were very lucky, and must have very conscientious colleagues or very tight code reviews. In my experience code indented with tabs always ends up looking like a pig's ear.
Groky
@Carl Norum:And just WHO is going to use such tools for serious programming? My observation is that adjustable tab size is a standard feature in any editor/viewer capable enough to be used in a real programming workflow. Could you give some examples of such tools that need to display code, and can't have the tab size configured? I can't come up with any :-/.
slacker
In a school project we used a script that, upon checking into the repository, stripped all preceding whitespace and replaced it with only tabs or spaces (can't remember which). This ensured consistency.
NomeN
@slacker - I sometimes need to *read* code in Notepad. For example, when trying to work out what's happening with my program from someone else's machine (e.g. a customer's). I wouldn't write code using Notepad, but this is all about reading code.
Groky
@Groky - I just whine a lot when the indentation is off. My co-workers are tired of listening to me.
Ray
@slacker Beyond Compare is awesome. But it's tabs can't be set any way I've ever found.
Carl Norum
+1  A: 

it's easy to have 'poorly indented' html if you're coding in php, i'd say its more important for the php to be neatly indented than the html it spits out...

Haroldo
+1  A: 

Two points in addition to Carl's observation:

  • "Proper" indentation is a matter of convention and language structure.
  • A check in to source control that consists only of changing the indentation of a bunch of lines is likely to be viewed very poorly without prior consultation.
dmckee
+1  A: 

Maybe simply those programmers' idea of "proper indentation" is different than yours? Maybe YOUR code looks like an ugly mess of f***ed up indentation to them? Seriously, each programmer seems to have his own idea of "proper" indentation, and a curious inclination to bash other people's indent styles as "wrong". Indentation has been a prominent topic of flame-wars from the beginning of Internet (and earlier). No need to add more fuel to the flame.

That all being said, which style you use is relatively unimportant. It is much more important to use consistently the same indent style throughout the project. The most common mess starts when each programmer on the team tries to use and force his style on the rest of the team. The result is an ugly mess of mixed and unfitting indent styles that drives people crazy. That is why it is important to set up coding standards for every project that has more than a few programmers on it. I repeat - what coding standards are chosen is unimportant, consistency counts.

slacker
While the message you may want to send is just fine, please be mindful of your attitude and word choice. When your expression seems abrasive, you may be much less helpful than you imagine.
KevenK
-1...jumping onto others for making fairly innocuous observations and calling them "f'ed up" and "intolerant" has also been around for quite some time.
Adam Robinson
Also, yes, there are subtle style differences, but I think everyone agrees that indentation should **always** be consistent within a file. I've seen enough projects where it isn't to make me think of this question.
dsimcha
@Adam Robinson:I did not jump onto anyone, and did not call names on anyone. I just made my own "innocuous observation" that other people may have similarly disdainful attitude towards your own coding style, as you have towards theirs. And they all too often have. Maybe I simply have seen the "My style is the One True" attitude much too often..
slacker
@slacker: Clearly your message came across as, at the very least, abrasive to more than one person.
Adam Robinson
I know it's not a poll or anything, but I thought wording was just fine and was not abrasive or counter-productive; especially in context of the original question.
StaxMan
A: 

+1 for the spaces vs. tabs issue being a major source.

At our office, our MISRA projects all require 3 space indentation. I use UltraEdit, so I just use Tab (if the auto-indent doesn't work right) which I have set to 3. Then, I use the editor to convert tabs to spaces. It works well for me.

Awaken
+1  A: 

Why don't people dress correctly? Why don't people use the right amount of garlic when they cook? Why does everyone listen to weird music? Your question assumes an authority that defines correctness which I've yet to see.

Besides that, I do like code that is consistently formatted across the file. If you use 1 tab or 3 spaces I don't really care as long as you use it consistently. Same with braces on the same line or a line on their own, don't care, just be consistent.

I personally use VS which out of the box auto-formats everything for me and I'm completely happy with the default rule set.

Chris Haas
+1  A: 

It's widely accepted that coding style is a matter of 'personal choice' and that one style is as good as another. I don't think this is necessarily true. An article recently written for the accu (only available online to members) suggests that various speed reading techniques can be applied to the layout of code to make it easier to read and understand. There are undoubtedly masses of data on the way humans take in information, but this article was the first I've seen applying it to code layout.

There may well be considerable information demonstrating that certain layouts of code are more suitable for humans to read and understand, but none of the (many) arguments I have seen refer to information like this, and generally involves defending the styles people have become used to.

David Sykes