Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: My coding guidelines

by Abigail-II (Bishop)
on Nov 28, 2002 at 10:11 UTC ( #216272=note: print w/ replies, xml ) Need Help??


in reply to Re^4: My coding guidelines
in thread My coding guidelines

But if you use spaces instead of tabs, indentation will also align. And you don't run the risk lines will be pushed over the 80 char limit if someone uses different tab settings.

Abigail


Comment on Re: My coding guidelines
Re^2: My coding guidelines
by emazep (Priest) on Sep 08, 2005 at 05:58 UTC
    But if you use spaces instead of tabs, indentation will also align. And you don't run the risk lines will be pushed over the 80 char limit if someone uses different tab settings.
    But using spaces you are forcing the others to use for indentation the same number of spaces you've chosen, while they may prefer to use different settings.

    Think for example of a visually impaired person (or simply a tired night coder) who wants 8-spaces indentation, who deliberately sets her tabs that way, to obtain what she wants regardless of the indentation habits of her colleagues (and still preserving their freedom to nest as deep as they prefer).

    By using spaces for indentation, as you suggest, your are forcing her to use your own indentation settings (which could be even a single space for that matter), which is not kind at all. Furthermore, any decent editor permit you to (automatically) convert tabs to spaces (the amount of them you prefer), while the opposite is not (always) true.

    In a word, tabs are portable, while spaces aren't (so tabs are not evil ;-)

    Ciao,
    Emanuele.

      In a word, tabs are portable, while spaces aren't (so tabs are not evil ;-)

      I would say you are right, except for one thing. You will virtually always find situations where you can't indent properly with just tabs alone. Which means that if you work with tabs set at different size the code turns becomes very difficult to deal with. Spaces alone are much easier to work with. And they avoid the perenial argument about how long a tab will be. IMO forcing people to use your indentation is minimal issue, as the tendency seems to be that if you work on someone elses code, or on shared code, that you should follow the indentation style for the code itself, not your own preferences.

      ---
      $world=~s/war/peace/g

        You will virtually always find situations where you can't indent properly with just tabs alone. Which means that if you work with tabs set at different size the code turns becomes very difficult to deal with.
        This could be a problem, but it shouldn't be difficult to eliminate it. In order to do so, even if you use a mix of spaces and tabs to indent (or rather to align things vertically) just always use tabs to indent (that is, to align vertically the left margin of the lines), and reserve the use of spaces to align vertically only the things past the left margin (in the middle of a line, so to say) such as the => symbol in a hash. In other words, never use spaces to align the left margin and reserve their use only to align the things inside a line. Here is an example:
        my %a_hash = ( <TAB> very_very_long_key => 1, <TAB> k2 <SPACES> => 2, <TAB> another_k <SPACES> => 3 );
        I've personally used (and spread) this convention for years (mainly with languages different from Perl though) and never had a single problem or complaint.
        The only problem I can see happens if you want to use a fancier alignment like this:
        my %a_hash = ( very_very_long_key => 1, k2 => 2, another_k => 3 );
        but frankly I would avoid it (though some people seem to like it).
        IMO forcing people to use your indentation is minimal issue
        This is true as long as everyone religiously adopt the same, sensible number of spaces (4 could be OK, but not necessarily, see later), but I've seen so many times people who love to indent with just 2 spaces or even with a single space. As for the 4-spaces convention, not everyone agree: for example both the Linux kernel and the Gnome coders recommend to use 8-spaces (tabs) for indentation.

        Thanks to their portability, tabs are IMO the only way to to settle this controversy and make everyone happy.

        Ciao,
        Emanuele.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-07-29 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls