Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^4: Tabs vs Spaces lets give this a go

by mreece (Friar)
on Oct 08, 2006 at 18:58 UTC ( #577019=note: print w/replies, xml ) Need Help??

in reply to Re^3: Tabs vs Spaces lets give this a go
in thread Tabs vs Spaces lets give this a go

sometimes, the situation calls for
my $lmao = $wtf ? 'omg' : 'lol' ;
which can't be done with only tabs on the left.

Replies are listed 'Best First'.
Re^5: Tabs vs Spaces lets give this a go
by tilly (Archbishop) on Oct 08, 2006 at 20:01 UTC
    End of line indentation has a number of problems. I suggest reading Code Complete for more. Using a 2-space indent I would write the above (assuming it is long) as:
    my $lmao = $wtf ? 'omg' : 'lol';
    and, as you can see, this can be done with only tabs on the left.

    Not that I use tabs - I dislike them as well - but saying you can't use tabs because you use an indentation style that I dislike isn't going to convince me. (Though if you use that indentation style, then I agree that you should not use tabs.)

      Ive never liked or agreed with the Code Complete on this subject. The argument tends to be "its costly (in terms of time and effort) to modify/update". However I personally find that often in that time when im fiddling with spaces to get the indenting right im also thinking and analysing about the bigger picture. So getting things lined up is to me the equivelent of idly doodling while I think about something more complex.

      And I find that yours is nearlly illegible, wheras the OPS is very clear. If I was working on that line of code there is a very good chance I would reformat it just to ensure that it does what i think its meant to do. The (apparent) lack of structuring in the line is a code-smell to me that would make me immediately wonder what the story was.

      I find that ternary ops are most legible when they follow the structure:

      $target = (cond) ? option1 : option2;

      Except in C where I would write it:

      target = (cond) ? option1 : option2 ;

      A difference that I put down to perl being trailing semicolon tolerant, and C being trailing semicolon intolerant.

      So while I have over time come to agree with Code Complete about many of its arguments and suggestions, I have to say that ternary ops are NOT a place I think they apply.

      BTW, I agree with your general comments in your other replies in the thread. I just disagree about the utility of lining stuff up in code. I find it often pays for itself, but it shouldnt be done neurotically. Theres a balance to be found I think. And its not "never line stuff up" and its not "always line stuff up", to me its "sometimes stuff should be lined up".


        Actually the argument that convinces me is not the difficulty of updating code, but rather the speed with which you indent very, very far. I'm a strong believer in keeping code indented to no more than 80 characters (less if possible), and end of line indents combined with long variable names can make the indentation grow fast.

        And the biggest reason why I care about line widths is that I like to fit as much code as possible on the screen at once. I can fit just about 3 terminals on my screen at work side by side at 80 characters wide. (There is a small overlap, but it is liveable.)

        In any case, I don't write many ternary ops, so I format those this way out of consistency. It is more an issue with function calls, which I also format in one level of indent, plus another for the comma. That is I format things like:

        long_function_name( $argument1 , $argument2 , $argument3 );
        (Yes, I usually use a 2-space indent.) versus something like this
        long_function_name( $argument1 , $argument2 , $argument3 );

        Incidentally I'm curious about your C example. According to my rusty memory, C should be fine with either format. A language with semi-optional semicolons (like Ruby or JavaScript) has to be formatted the other way, but I thought C could format either way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577019]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2021-02-27 12:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found