Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

The One True Style of indentation:

by Petruchio (Vicar)
on Apr 14, 2002 at 02:46 UTC ( #158886=poll: print w/ replies, xml ) Need Help??

vote on The One True Style of indentation:

One space
[bar] 10/1%
Two spaces
[bar] 221/20%
Three spaces
[bar] 94/8%
Four spaces
[bar] 273/25%
Six spaces
[bar] 0/0%
Eight spaces
[bar] 12/1%
Tabs
[bar] 358/32%
Other
[bar] 8/1%
None
[bar] 3/0%
However I feel today
[bar] 38/3%
Random
[bar] 9/1%
All on one big line
[bar] 43/4%
Python!
[bar] 39/4%
1108 total votes
Comment on The One True Style of indentation:
Re: The One True Style of indentation:
by emcs (Scribe) on Apr 14, 2002 at 03:43 UTC
    As long as the code is readable, it seems to me that the amount of indentation is largely a matter of personal preference.

    As a relative newcomer to perl I appreciate the fact that everything is not cast in stone.

    I have noticed that you can sometimes identify an individual by then way they lay out their work; this becomes part of their personal signature.

    For better, or for worse.

    emcs


    The dogs bark; but the caravan rolls on.

      As long as the code is readable, it seems to me that the amount of indentation is largely a matter of personal preference.

      Sure, as long as you're not trying to work with other people. And you have to work with other people! If you're on a project with several folks, there has to be some agreeable standard or things get messy. If you want to send in patches to an author you have to conform to their indentation style (or lack there-of).

      The real fun comes in that after you've been using K&R one-tab indentation for long enough, other formatting becomes much less readable. When I'm debugging other people's code I find it's faster for me to reformat the code and then debug it. 90% of the time reformatting makes the bugs stand out like fire flies in a cave.

      Using tab indentation and letting people choose the size of their tab stop helps people share code while maintaining some personal freedom of how to look at things.

        Sure, as long as you're not trying to work with other people. And you have to work with other people!


        Thanks Anonymous Monk.

        It seems that I jumped in at the beginning of this thread, with little knowledge of the bigger picture, and a very limited viewpoint.

        However, I learned a lot from reading all the follow up posts.

        emcs

        The dogs bark; but the caravan rolls on.

      Four spaces (1 tab) is my preferred... But working with others (Unix) requires a tab setting of 8... it can be a waste of real estate at times; Other times the two line perl script is my favorite.
Re: The One True Style of indentation:
by danichka (Hermit) on Apr 14, 2002 at 04:25 UTC
    I don't care that much, but I have been using 4 space indenting since I read perlstyle.

    4-column indent.

    use Your::Head;
Re: The One True Style of indentation:
by cjf (Parson) on Apr 14, 2002 at 05:17 UTC

    Personally I consistantly indent my code 4 spaces. In my experience most people are far too picky on this issue. There isn't 'One True Style' of indentation. Anything from 2-6 spaces is pretty readable, although 8 space indents gives you added incentive to avoid nested if/else blocks :).

Re: The One True Style of indentation:
by JayBonci (Curate) on Apr 14, 2002 at 07:55 UTC
    Here's what they say to me:
    • One space - Screw readability. I'm pissed they even make me separate my operators. Perl should be more like Latin.
    • Two spaces - I have my head on straight AND I respect screen real estate.
    • Three spaces - I have a little flair, or a nervous twitch. Or the second disguised as the first. Or you listen to waltz while you code.
    • Four spaces - I read a few standards docs and now I think I'm all spiffy. Vannila Ice, I know you're in there.
    • Six spaces - I have agression issues, and my outlet is machine gunning the space bar
    • Eight spaces - You end every line with a meniachal "DIE! HAHAHAHAH! DIE! YOUR FRIENDS CANNOT SAVE YOU NOW."
    • Tabs - I'm a lazy person. I know all of the vi commands by heart. Or you drank the 80's soda.
    • Other - I'm a sideshow freak, and prefer to fill my ledgers with obfu.
    • None - Satan. I know you're in there.
    • However I feel today - I'd be you never shared an MP3 in your life!
    • Random - Richard Nixon gave me peanut butter at midnight. Pass it on.
    • All on one big line - Dammit, I'll buy a new keyboard this week. I promise.
    • Python! - It's pronounced pee-thon


        --jb
Re: The One True Style of indentation:
by dr_beln0ck (Friar) on Apr 14, 2002 at 10:13 UTC
    I use tabs because i'm lazy, but i don't think it matters what style is used aslong as the code is easy to read and the same style of indentation is kept throughout the code.

    if in doubt give it a clout.
Re: The One True Style of indentation:
by Juerd (Abbot) on Apr 14, 2002 at 10:52 UTC

    4-space indents, but two of those make a single tab.

    By the way, I just hit tab, not four times space bar (Actually, most indenting is done automatically by vim's smartindent). Mcedit handles this through the "fake half tab" setting, vim does by these lines in my .vimrc:

    set smartindent set tabstop=8 set shiftwidth=4 set softtabstop=4


    See also: Style Geekcode

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: The One True Style of indentation:
by Dog and Pony (Priest) on Apr 14, 2002 at 11:17 UTC
    I usually use tabs, and each tabstop at 4 spaces. This seems to work just about everywhere, and it is very easy to read. If my code lines would go too far to the right with 4, I probably have too long code lines and/or too deep nesting anyways.

    Posting code to this site however, I've sometimes converted the tabs into two-space indents instead of four (we all can agree that conversion is almost a must here in any case?), because with the fonts here, it is still readable with two. Same with emacs, that big standard font makes two-indent readable. Until I try to open the same source in any other editor, then I have to increase the indent. Well, of course not *any*, but any of the others I usually have access to or use.

    My goal is of course that it should be easily read anywhere, by anyone. But the two-space indenters usually say the same, so I guess we are stuck. :) It is almost as religious an issue as best editor or where to put the braces...


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      It is almost as religious an issue as best editor or where to put the braces...
      Brace placement - there is the right way, and then there are the other wrong ways.

      :-)

      Best editor is of course emacs, since I don't have to care about indenting, I just press tab and emacs moves the cursor to the right place, no matter where on the line the cursor is.

        Absolutely. I use
        function(arguments) { if (condition) { ... } else { ... } }
        Brace placement is far more important to me than indentation, though I use tabs for that with four spaces as my second choice, if, for instance, the tab key breaks or starts printing Ős. That's never happened, but if it did I'd use four spaces and buy a new keyboard. But something like
        function(arguments) { if (condition) { ... } else { ... } }
        is unreadable.
      I also prefer tabs with 4 space tabstop. With tabs, the next programmer to use the code can set the indents to his/her preferred spacing, using tabstop (or equivalent setting). Tabs offer more flexibility that way.
Re: The One True Style of indentation:
by Anonymous Monk on Apr 14, 2002 at 12:55 UTC
    I use tabs for indention, but not for other line-ups! Example. (I'll use > for tab and * for space where needed.)
    my %hash = ( >>>>foo***** = 1, >>>>whoopass = 2, >>>>that**** = 3, >>>>foobar** = 4, );
    This way people can change tab-stop to whatever they feel like, and still keeping formatting; only changing how much it's indented from the left-most border.

      I'll use > for tab
      >>>>

      Wow. Are those four-tab indents? :)

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        Heh, no. I forsaw that reply, but was lazy and couldn't find a good phrase, and hoped people would realize that I meant "I'll use > as a filler for tab, and * as a filler for space". I'd seen it in some vim configurations so I figured it would be intuitive for at least some readers.

        Must editor's tab stop is set to 4, hence the four >s. I admit, it was a bit ambiguous. :)

        Cheers.
Re: The One True Style of indentation:
by qslack (Scribe) on Apr 14, 2002 at 15:45 UTC
    I personally use 4-space tabs. I actually hit the <TAB> button to indent, not the space bar.

    When Petruchio originally made this poll, I figured that it was asking for your tabstop preference. It just didn't make any sense to me that people would indent with spaces, when tab takes many fewer keystrokes. I know that I wasn't alone in voting for "Four spaces" when my tabstop is 4. A bunch of other people in the IRC channel did the same thing.

    For those of you confused, here is a quick VOTING-HOWTO on this poll

    1. Are tabs syntactically-important in your language? If so, vote for Python.
    2. No indentation? Vote for none.
    3. To indent, do you hit the TAB key? If so, vote for Tabs.
    4. If you use the space bar (bad choice!), vote for the appropiate number of spaces.

    Quinn Slack
    perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'
      I don't personally know what Petruchio intended, but in my opinion (FWIW) it should depend on how your editor saves the resulting file. If it preserves the TAB character, vote TAB. If it converts the TAB to spaces, vote the number of spaces.

      I configure TextPad so that it converts new and existing tabs to 3 spaces, thus I voted 3 spaces. That way it doesn't look crappy if it's printed using some other editor than I used to create it. Unless, that is, it looked crappy to begin with or some formatting issue other than the default tab size comes into play.

      A related followup poll suggestion: The one true line length.   :-)

      --Jim

Re: The One True Style of indentation:
by japhy (Canon) on Apr 14, 2002 at 17:11 UTC
    It's so sad to see so many people answering incorrectly here. It's TWO spaces. I don't want to have to tell you guys again.

    <newPerlOrder>You will use two spaces per level to indent your code. You will write one-lined 'if's when possible. You will leave space in between 'if', the parenthesized expression, and the block. The opening brace will appear on the same line as the 'if'. There will be no cuddled 'else's. Here is the One True Way. Praise japhy for showing it.

    if (condition) { # stuff # and more stuff } elsif (condition) { really-short-stuff } else { # ok }
    </newPerlOrder>

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Dog and Pony quickly forms an underground guerilla to combat this new Perl order... "We will fight you to the end, evil unbelieving two-spacer! Don't touch our holy braces!"

      :)


      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.
      i do it exactly how japhy does it. I'm a "two-spacer" because it's neither too much, or too little (damn that "one-space" indentation). If i'm drunk, acting drunk, or feeling drunk, i'd like to think i'm a "All on one big line" person ;)
      <signs up for the newPerlOrder>
      Viva la order! Two spaces for everyone!

      ~Brian
      It's weird, I normally go with four spaces in personal code, but in my recent Perl6 'apocryphal' SchemeInterpreter I switched over to two spaces and I'm surprised by how much I like it.

      Then again, this is code that I'll likely be using as the basis for an pod file discussing how it works and what's changed since Perl 6, so horizontal space is precious.

      All that said, I'll use whatever the prevailing style is at whatever site I'm working on. If there is no prevailing style then I'll work to get one established and will argue for my choices, but once consensus is reached I go with that. The one thing I will not stand for is tabs used for anything but 'basic' indentation. For instance, consider the following (not good style, but it's just here to illustrate a point) code:

      sub double_dispatch { my $self = shift; my $arg = shift; $arg->method($self, args => [@_]); }
      If tabs are used for indentation then the 'actual characters' used would be as follows. Take '>>>>' to equal one tab.
      sub double_dispatch { >>>>my $self = shift; >>>>my $arg = shift; >>>>$arg->method($self, >>>> args => [@_]); }
      Using 'hard' tabs to do 'alignment' formatting is Bad And Wrong; it embeds your assumptions about tab width into the source file thus defeating the purpose of using tabs in the first place. Don't do it people.

      I would be much more sanguine about tab indented code if people stuck to this rule, but unfortunately, they don't. Even more depressingly, the likes of emacs's otherwise wonderful cperl-mode doesn't make the distinction either. So for now, I argue for 'indents shall be a fixed number of spaces per level'. All things being equal, I choose four.

      Yes, your assumptions are embedded in the source this way, but at least your careful formatting doesn't get fscked over when someone chooses a different tab width to view it with.

Re: The One True Style of indentation:
by christina_sampson (Novice) on Apr 14, 2002 at 19:57 UTC
    Wow. I probably shouldn't be saying this on my first day here, but here goes.
    I can't believe how many of y'all said tab. I should probably just re-map one
    of my meta keys to
    s/\t/  /g;
        ^
    two spaces!
    
    christina (with love :) )
      Yes! Another believer! Oh, and here's a utility script of mine, detab:
      #!/usr/bin/perl -pi # can't use die() in BEGIN -- it looks funny :( BEGIN { $sp = shift or warn("usage: detab SP files...\n") and exit } s/^(\t+)/" " x ($sp * length $1)/eg;
      To cleanse your nasty tabbed files, simply run detab 2 foo.pl, and your leading tabs are replaced with 2 spaces per tab. The way japhy intended.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        A slightly different way to do that:
        perl -pi -e 's/\G\t/ /g' foo.pl
        (Adapted from a "replace-leading-zeros-with-spaces" oneliner I seem to remember)

        Update: looks like the original came from merlyn after dominus offered a suggestion similar to japhy's

        -Blake

Re: The One True Style of indentation:
by erikharrison (Deacon) on Apr 14, 2002 at 21:50 UTC

    By definition, Python is the One True Indenting Style - right or wrong, it enforces it. And you must admit, that simply by decreeing what the appropriate indentation should be, Guido cleverly eliminated the braces and cuddled els(e|if) debate (DIE CUDDLED ELSES, DIE!DIE!DIE! - sorry. My left hand took over . . .)

    Cheers,
    Erik

      DIE CUDDLED ELSES, DIE!DIE!DIE!

      } else {

      *hug* *cuddle* *embrace* *grin*

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

WWED
by ellem (Hermit) on Apr 14, 2002 at 22:27 UTC
    When faced with this dilemma Brothers you need only ask:

    What
    Would
    Emacs
    Do?

    --
    ellem@optonline.net
    There's more than one way to do it, but only some of them actually work.

      Actually, that's ambiguous...

      M-x cperl-set-style Enter style: <TAB> BSD CPerl GNU PerlStyle C++ Current K&R Whitesmith

      So, Emacs Would Do one of the seven/eight styles above, depending on how it's customized. :-)

        Emacs does not default into cperl-mode though. It defaults into the less robust perl-mode.

        --
        perl -pe "s/\b;([mnst])/'\1/mg"

Re: The One True Style of indentation:
by atcroft (Monsignor) on Apr 15, 2002 at 00:51 UTC
    Call me a "heretic", or consider me still but an "egg" (as I do), but I think I would have to agree that there is no "true" style. As some come to perl from other languages, with the styles those languages impressed upon them, and others find perl without such shackles, we see the philosophy of TMTOWTDI show up even in such things as spacing and bracing and the other small details of coding. The important thing is that the code is usable, maintainable, and that someone can follow it, and if consistently done, so much the better. Just as an example, for code I write only for myself, I tend towards tabs, but sometimes 2 or 4 spaces; for code I post on here recently (and even some for work), I try to first run it through PerlTidy(1) with indention at 4 spaces.(2)

    I have found this discussion (and most others) quite instructive, and a help as I continue still to find my way still along this path we call Perl.

    -----

    1. But then again, I also prefer lines of either 75 or 123 or 132 characters, and yes, for code I'm having to wade through for myself, I sometimes prefer cuddled elses.(3)
    2. Just my 2 cents, for what it's worth after inflation.
    3. But this is also part of why I still consider myself an "egg".

      Egads, who let this reasonable person into the discussion?!

      Chris
      M-x auto-bs-mode

Re: The One True Style of indentation:
by yung_tw (Pilgrim) on Apr 15, 2002 at 04:24 UTC
    normally use 2 spaces to ident, not too much space to be wasted, and also the ident can be viewed.. just my personal likes. Peace.
Re: The One True Style of indentation:
by Molt (Chaplain) on Apr 15, 2002 at 09:48 UTC

    I use two spaces - I find it readable, and sensible in most of the languages I use.

    I use the tab key to put my two spaces there - It's convenient.

    I put my braces on the same line as an 'if', and align the bottom brace with the opening statement - The braces make sense to me, and I'd deserved to have stones thrown at me by maintainers if I didn't align bottom braces.

    I cuddle my elses - More code on screen, and they don't get lonely.

    I comment rather heavily - I know Perl much better than those round me but would like them to at least be able to read it.

    I insert spaces to pad out expressions as I see fit - More readable in my opinion, and with all that real-estate I saved by not doing 4-space I can afford to be frivilous.

    I post meaninglessly long explanations of my coding style - But I don't insist you hear and obey.

Re: The One True Style of indentation:
by mattr (Curate) on Apr 15, 2002 at 10:40 UTC
    I use two spaces for manual indentation in Perl, and to continue a block of information in my own todo lists which are ascii, two newlines separating each block. It prints well and looks sane to me..

    I use XEmacs which seems to get it right, tab eq 2 spaces. Personally I just find it to be the right amount, it generally leaves me enough room for short comments on the same line even when nested.

    I learned curlies from Niklaus & Wurth but forget what they said.. I use

    if (true) {
      woop;
    } else {
      werp;
    }

    ..Vertical real estate is important too. The real holy war is, how do you line up long || statements (over 2 lines for me)..

    if ( (longthing > foo) || (anotherthing < moo) || (boo) ) { werp; }
    Right??!?!?!? (smiling like jack n. in the shining) hee hee hah hah ahaha ahaa!!
      TAB's what it's all about. Easy to keep anything and everything lined up perfectly, and with a minimum of counting and such...

      work it harder make it better do it faster makes us stronger more than ever hour after our work is never over.
Re: The One True Style of indentation:
by snafu (Chaplain) on Apr 15, 2002 at 14:38 UTC
    In vim:

    set sw=4 set expandtab
    An excellent solution for tab-to-4 spaces without the actual \t. I luuuub vim

    Update:
    tab'ing is fine only if:

  • 1. Your editor replaces your \t with spaces so that your code has readability in more than one editor. Ever tried reading your code in vim after writing it in vi?
  • 2. You don't tab out to 8 spaces! That is just ludricous. Editor line wrapping is retarted looking. So, if you have code that spans out over more than 4 or 5 tabs you either have to do something like:

    code { code{ code { code { code { # Lots of tabs out to here... +must be taking a lot of space so far so you use the cat operator to k +eep from line wrapping but hey...this comment is really long and man, + I just hate line wrapping. my $line = "this is a". "line that won't". "line wrap.\n"; } } } } }
    But this kind of thing is just crazy when it can easily be avoided by simply not taking up so much space with tabstops (generally set at 8). You get just as much readability out of 4, 3 or sometimes even 2 space tabs (Im using the term 'tab' loosely here). But, I guess its all persona, therefore, Im just saying that, imo, tabs so large are just ridiculous and the use of 'tab' as a real tab is not wide or respectful to the maintainers of your code after you're done.

    I mean really! Is the following code any less readable than the above?

    code { code{ code { code { code { # and of course, I would fix my # comment too. my $line = "this is a line that won't". " line wrap.\n"; } } } } }

    _ _ _ _ _ _ _ _ _ _
    - Jim
    Insert clever comment here...

Re: The One True Style of indentation:
by Purdy (Hermit) on Apr 15, 2002 at 17:22 UTC
    Vertical tabs, baby!

    \V rocks! ;)

      \V rocks! ;)

      But Perl does not have it. There is no \v and vertical tabs are not in \s.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

Re: The One True Style of indentation:
by tjh (Curate) on Apr 15, 2002 at 17:27 UTC
    Hmmm...

    I guess I blend (or fence straddle) this issue.

    TAB configured to TWO SPACES is the Right Answer.

Re: The One True Style of indentation:
by FoxtrotUniform (Prior) on Apr 15, 2002 at 17:39 UTC

    I code to a rather strict interpretation of K&R style, but I use two-column indents instead of eight- columns, mostly to conserve screen real estate. (And of course I cuddle my elses!)

      Update: Cuddled elses are:
      if(foo) { ... } else { ... }
      whereas perlstyle, IIRC, recommends:
      if(foo) { ... } else { ... }

    Another thing: I try to keep my line lengths below 72 columns. This keeps it easy to read even when you're editing it on the server console (don't ask), with vi in line-numbering mode. (And if a line's longer than 72 columns, it's probably malformed anyway.)

    I used to be vehemently anti-1TBS, citing all the usual arguments about braces getting lost and code being cluttered and hard to read. Then I took a course from a prof who used 1TBS all the time, and it just clicked. (Sort of like the way I started out using Emacs, and switched to vi.)

    --
    Good luck, tilly
    :wq

      Yes. Screen real estate is very important to me too. I love the concatenation operater for this purpose.

      I could get use to 1-TBS but I don't want to :) This is the beautiful thing about coding is that its very personal and distinct. Its like literature. No two people code the same nor do any two people write literature the same.

      Holy (programming) wars are fun to argue about but they are really useless. Btw, cuddled elses...are they the

      condition () { more code }

      or

      condition () { more code }
      I like the second but I admit that the first is growing on me. This is a topic in-and-of-itself for a holy war. :) I think I see the next vote topic! =P jk

      _ _ _ _ _ _ _ _ _ _
      - Jim
      Insert clever comment here...

Re: The One True Style of indentation:
by Chainsaw (Friar) on Apr 15, 2002 at 20:13 UTC
    Well , I usually indent my code using 2 spaces. Cause is easy to read and understand the code and fallow, if you need to search any specific item in the code.

    But 4 or 6 spaces are ok too.


    God help me always to see the other face of the coin. And prevent me from accusing of betrayal those who don't think just as I do.
Re: The One True Style of indentation:
by malaga (Pilgrim) on Apr 15, 2002 at 20:22 UTC
    this seems to be a very emotional subject.

    i use tab, unless i don't have the space, then i use 2 to 4 spaces. i remember reading somewhere that it's supposed to be a tab.

    but after reading all this, it sounds like 2 spaces is the best bet. so i'm changing.
My tab is 4 spaces / ergonomics
by func (Acolyte) on Apr 15, 2002 at 22:14 UTC

    I configured vim to use four space tabs. I did this after reading the Vim-HOWTO which recommends 4 space tabs for good ergonomics.

Re: The One True Style of indentation:
by cecil36 (Monk) on Apr 15, 2002 at 23:47 UTC
    I always use tabs and anything that uses curly braces, I put the braces on a line by itself. Been doing that since my days of learning to program in C++.
Re: The One True Style of indentation:
by BUU (Prior) on Apr 16, 2002 at 02:50 UTC
    condition () { more code }
    Is the one true bracing style! It just makes sense! None of this wander around through half the line just to find where the first brace is!

      Uh, no. Allman style may be your favourite indent style, but if you say "one true bracing style" to a hacker, it isn't what they'll think of.

      --
      Good luck, tilly
      :wq

        heh, oops. What is bracing style then?
Re: The One True Style of indentation:
by brianarn (Chaplain) on Apr 16, 2002 at 14:38 UTC
    Oh my gosh! In all of our religious fervor over indentation space, we've all forgotten about Cowboy Neal!

    Where's Cowboy Neal? <sniff>

    ~Brian
      *sniff* I had the same thought myself...

      yours,
      Michael

Re: The One True Style of indentation:
by Rex(Wrecks) (Curate) on Apr 16, 2002 at 18:02 UTC
    Hmmm, personally I use 3 space indent via mapped tab key (no hard tabs, they are bad IMHO becuase I write a lot of cross platform stuff and they never turn out the same in any different editors).

    I also like the Allman style of indenting and bracing
    if { #Stuff } else { #more stuff }
    However readability is the key to any of it. I'm not religious about it and I find 2 space or 4 space just as easy to read as long as it is CONSISTANT throughout the code block.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: The One True Style of indentation:
by coreolyn (Parson) on Apr 16, 2002 at 19:30 UTC

    I've got a couple of problems with tabs. Primarily it is with our source control which never seems to read the tabs from MSDOS files the same when pushed out to our Solaris boxes. Additionally every editor needs to have the tab set to the same value in order to have the same 'look' and organization.

    coreolyn
      every editor needs to have the tab set to the same value in order to have the same 'look' and organization

      Why is that? Can you give an example of when having tab as indention makes things look bad?
        Can you give an example of when having tab as indention makes things look bad?

        When an editor has replaced some spaces with tabs, and some not, then you read it on another editor, the result looks very bad.

        If I use a tab in vi on a unix box then (after submitting to source control which xlates the return characters for OS's) and then check it out to my 2000 box, I have to set whatever editor I use to the same 4 space tab character, otherwise my code can have a tab of sometimes 8 characters. Possibly this has something to do with the checkin/checkout process. Bottom line - I've had to adjust to using spaces for my indentation in order to have the code look the way I want it to on a consistent basis.

        coreolyn
Death to Tabbers!
by Anonymous Monk on Apr 17, 2002 at 16:29 UTC
    4 spaces
    Opening brace on a line by itself.
    No cuddled "} else {"
    Never tabs!!!

    Kill tabbers!

      Wrong. You can always convert tabs to spaces with tools like expand. When i post code to this site i run my code though expand -t3 to convert each tab to 3 spaces.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
Re: The One True Style of indentation:
by $name (Pilgrim) on Apr 17, 2002 at 17:10 UTC
    I supose I cheat? emacs perl-mode
    $name
    MGW Aplications Developer QuinnTeam Inc.
Re: The One True Style of indentation:
by Anonymous Monk on Apr 17, 2002 at 21:14 UTC
    When people cannot agree on visual indentation within a development team, the solution is to encode indentation with one hard tab per indent step, and have everyone configure their editor to display hard tabs the way they like. This screws more(1) and diff(1) outputs of course. One can argue that a hard tab in a file is a markup code for user-defined indent step, just like in MSWord or FrameMaker.
      When people cannot agree on visual indentation within a development team,

      This is one of those times that a benevolent dicatatorship has its benefits. Programmers have bigger things to deal with than piddly-shit arguments like tabs 'n' spaces and brace style.

      The key is that all the tools support whatever people want to do. The solution of "some do this, some do that" is not acceptable if it means that diff doesn't work, for example. In that case, a decision must be made, or tools adapted, or productivity suffers.

      xoxo,
      Andy
      --
      <megaphone> Throw down the gun and tiara and come out of the float! </megaphone>

      That won't always work if you ever try to line things up using spaces on top of tabs.

      If you have to work in a team, I think consistency is more important than "the best way". There should be one true brace/indenting style PER TEAM.

All on one big line
by Dr.Altaica (Scribe) on Apr 17, 2002 at 22:37 UTC
    Reminds me of when I wrote MPI programss. Message Parsing Interpreter not Message Passing Interface.
    |\_/|
    /o o\
    (>_<)
     `-'
    
Re: The One True Style of indentation:
by darksym (Beadle) on Apr 18, 2002 at 03:01 UTC
    At the risk of being a freak, I must say, I don't care for tabs or two spaces. Two spaces is too few. A tab is a tab of a lot too much, especially for most normal terminals. It doesn't help that tabs are essentially variable width either.

    Tabs mixed with spaces are even worse. If there are to be leading spaces, they should all be spaces.

    And can we please get ping-pong line styles working? This left to right stuff is killing me. j/k

    Example:
    use pingpong;
    #!/usr/bin/perl
    ;"n\dlroW olleH" tnirp
    # ^ Much better
      Have you seen the Boustrophedon Text Reader I've wanted to write a Boustrophedontext widget for perlTk but have do many progects allready.
      |\_/|
      /o o\
      (>_<)
       `-'
      
Re: The One True Style of indentation:
by tomazos (Deacon) on Apr 18, 2002 at 12:11 UTC
    Which way is the best is pretty much irrelevant for me now. The "return-space-space" twitch is permanently hardwired into my brain. I've got more chance of learning Dvorak than changing away from two space indents.

      I'm sure you really, really believe that, but it's just practiced behavior. If you practiced another behavior long enough -- say, if the company you write programs for develops a coding standard calling for four-space indents -- then you'd learn that too. It's just syntax, and you can pick it up with a little practice and an open mind.

      Chris
      M-x auto-bs-mode

        Then I'd write a keyboard daemon such that whenever I hit "return-space-space" it got to the word processor as "return-space-space-space-space". :)
Re: The One True Style of indentation:
by tradez (Pilgrim) on Apr 18, 2002 at 19:48 UTC
    If you are coding in VIM, Tabs are simply the way to be. This was you can mek your code readable to anyone that can use VIM. What I mean by this, is say I like 2 and you like 4 space indentions. All you have to do in vim to see my file the way you like yours to show is
    :set ts=4
    and BAM! Long as we both use
    :set ai
    :set si
    VIM VIM VIM!!! TABS TABS TABS!!! They both get my vote ;)

    Tradez
    "Never underestimate the predicability of stupidity"
    - Bullet Tooth Tony, Snatch (2001)
Re: The One True Style of indentation:
by jrsmith (Pilgrim) on Apr 19, 2002 at 13:44 UTC
    i'm a rebel. i use tabs, AND i cuddle my else's :)
Re: The One True Style of indentation:
by Koala (Initiate) on Apr 20, 2002 at 20:59 UTC
    Having started in C, indentation is irrelevant! As long as there are logical line breaks in a language (present), changing the presentation is a useless endeavor. An observer would still need to separate statements, and would go through the same motions as if code was tab-ridden and each line had a description 5x its length. -Koala
Re: The One True Style of indentation:
by Felonious (Chaplain) on Apr 22, 2002 at 17:40 UTC
    code as you wish, I'll just perltidy -ce -t -l 132 -pt=2 yourprog.pl if you use one of those 'inferior' coding styles.;)

    -- O thievish Night, Why should'st thou, but for some felonious end, In thy dark lantern thus close up the stars? --Milton

View List Of Past Polls


Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-08-23 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (171 votes), past polls