indentation

Brian J. Tarricone bjt23 at cornell.edu
Mon Aug 30 01:43:16 CEST 2004


{ if this is annoying anyone, please email don and me off-list, and 
we'll take it to a private forum. }

Don Christensen wrote:

> Okay, I'm going to reduce my credibility even further and show you a
> snippet of my preferred coding style:
>
>     if ( func_call( arg1, arg2 ) != ENUM_VALUE )
>     {
>         call_func( arg3, arg4, arg5 );
>     }
>
> Can you tell I like whitespace?  I'm not going to argue why I like
> this style, especially since it seems to be so much less popular outside
> the company where I used it than it was inside.

yeah, i'm not really a big fan of the extra whitespace.  i'm not a total 
WS-minimalist, i.e., i'd write that line this:

if(func_call(arg1, arg2) != ENUM_VALUE)
    call_func(arg3, arg4, arg5);

i think when people talk about whitespace, it's really not a style issue 
- i think it's a readability issue.  i personally have no problem 
reading code with very little whitespace, but, if it makes it easier on 
your eyes to space things out a bit more, then you should, obviously.  
(on the other hand, this kinda makes me feel bad that i make others read 
my whitespace-challenged code ^_~.)  then again, i could be totally 
wrong, and it _is_ just a style issue.

> I do have to disagree that using tabs and being able to change indents
> will look consistent no matter what.  Consider the following code using
> tabs set to two spaces (I've used spaces to make sure the examples
> look as I intend them to):
>
>   if (function_call_with_long_name(argument_one_with_long_name,
>                                    argument_two_with_long_name)) {
>     conditional_code_here;
>
> Change it to tabs using four spaces and it looks like this:
>
>     if (function_call_with_long_name(argument_one_with_long_name,
>                                                                      
> argument_two_with_long_name)) {
>         conditional_code_here;
>
> Of course, you could craft your style to reduce or maybe even eliminate
> this problem, where the two examples above might translate to:
>
>   if (function_call_with_long_name(argument_one_with_long_name,
>       argument_two_with_long_name)) {
>     conditional_code_here;
>
>     if (function_call_with_long_name(argument_one_with_long_name,
>             argument_two_with_long_name)) {
>         conditional_code_here;
>
> I would argue that this is less than desriable.

that's why i do two things:

1) when i want to line things up like that, it's not an indent issue, 
and an indent is the "wrong" way of thinking about it.  it's only 
"right" because you're using spaces for indents.  when i line things up, 
i use the spacebar.  but, right, i don't really line things up too 
often; i've crafted my style so it looks consistent, by indenting 
multiline stuff an extra tab width.  then, to make it more clear, i pull 
a page from your book and add a curly brace on a blank line, lined up 
with the start of the block:

if(condition1 || condition2
       || condition3)
{
    func1(foo, bar);
}

i'll vary the extra indent depth if the parentheses nesting requires 
it.  sometimes it looks funny, sometimes it makes sense, but it's always 
consistent, which is what i'm mainly going for (perhaps that's dumb, but 
so be it).

> This has been a fun discussion, especially since it has been quite
> cordial.  I think we both have done a good job of not getting overly
> defensive about our personal opinions.  Not all such discussions go
> so well.

agreed.  i tend to do better if the person i'm talking to doesn't become 
overly defensive (or offensive) from the get-go.  once they do, it 
unfortunately usually sets me off.

> By the way, welcome to California!

thanks ^_^.  enjoying it here so far...

    -brian




More information about the Xfce4-dev mailing list