in reply to (jeffa) 2Re: Losing or overwritting values
in thread Losing or overwritting values

Whether you like to hug the open brace (example 1) or put it's on it's own line (example 2) is a matter of personal preference - both are correct. However, you really need to line the closing brace up with what started it.

Lining up the braces with keywords is also a matter of personal style. I do it and I wish every one did. Unfortunately, some people don't. Really, it's all a matter of style and there is no correct or incorrect way to do it. I think the real important thing is consistency.

Also, i recommend using tabs instead of spaces

I strongly disagree with this. Use spaces. Tabs just end up being an additional hassle for the programmer. Tabstops have to be set correctly in order for the code to look good. That's not a huge problem but it is an annoyance. The real problem occurs when a tab-using programmer comes along and modifies source code written by a space-using coder (or vice-versa.)

So, once again the answer is consistency. The reason I advocate spaces is that they are inherently consistent and do not rely on an editor or terminal variable as tabs do. A space is a space is a space whereas a tab is eight spaces or maybe four or perhaps two or possibly three and sometimes six... etc.

I know some people advocate using tabs for indentation and spaces for alignment. In my estimation, that's only half a solution. Worse, it creates its own problems later when the code needs to be maintained.

I'd break my tab key off if I didn't use it for completion in my shell.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: (jeffa) 2Re: Losing or overwritting values

Replies are listed 'Best First'.
(jeffa) Tabs are from Venus, Spaces are from Mars
by jeffa (Bishop) on Jan 05, 2003 at 16:41 UTC

    Like you said ... this is all opinion, the important thing is consistency. (And if you don't use vi ... )

    However, i will continue to fight for tabs over spaces when indenting on the left side. The right side was made for spaces, but using spaces on the left side is just too much typing for me. "Let's see, do i hit the tab 3 times or the space bar 12 times?" I am sorry, but using spaces on the left side is simply having to do more work than i really need to do. I started out using spaces, switched to tabs, and i have been using tabs ever since. Besides:
    # need to convert 4 spaces to a tab? perl -pe 's/ /\t/g' foo.pl # need to convert a tab to 4 spaces? perl -pe 's/\t/ /g' foo.pl
    These could be made more robust, but i think the point has been made. As long as we can easily convert from one to the other, we shouldn't worry about whether or not we use tabs or spaces, as long as we are consistent. But me? I use tabs. I am just too lazy not to.

    "The reason I advocate spaces is that they are inherently consistent and do not rely on an editor or terminal variable as tabs do."

    And this is exactly the same reason why i advocate tabs. If i am on a smaller screen, i can set my tabstop in vi to 3. If i am on a larger screen, i can set the tabstop to 6. It is more flexible. Thanks to expand, i can deliver my code with tabs converted to any number of spaces. Let the computer do the work.

    P.S. (FWIW), this is a heated argument at the Computer Science department at my University. The camps have picked sides and the line has been drawn. Some professors teach their students to use tabs, others spaces. Neither side has convinced the other that they are right, and i doubt they ever will. Now, let's get back to Perl! ;)

    UPDATE:

    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)
    
      The right side was made for spaces, but using spaces on the left side is just too much typing for me. "Let's see, do i hit the tab 3 times or the space bar 12 times?" I am sorry, but using spaces on the left side is simply having to do more work than i really need to do.

      I've found that that's the normal argument for tab-using heathens¹ such as yourself. Really, it probably means you just haven't fully learned the capabilities of your editor. Even with the (admittedly broken) stock vi on Solaris, you can set ai, set ts=80, set sw=4 (or whatever) and get by just fine without wearing out your spacebar. Vim and other vi clones have added the softtabstop and expandtab options. It's easy with emacs, of course. It's doable with almost every half-featured programmer's editor available for any platform...

      1. I know this is a holy war here. The "heathen" comment is meant in good humor, of course.

      -sauoq
      "My two cents aren't worth a dime.";
      
        Except it remains easier to backspace away tabs than spaces.

        Makeshifts last the longest.