Coding standard? Indentation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bandobras
    Knight
    • Apr 2007
    • 726

    Coding standard? Indentation?

    I keep making a mess of indentation whenever I touch a C file from Angband, so I wonder what I should set up my Emacs to (or Eclipse, or 'indent' utility). I see a year ago I had the following conversation on the NPP forum, but now that V is again active I wonder if there are any opinions...

    > > > Merry Christmas!
    > > >
    > > > wonder what coding standards do you adhere to.
    > > > E.g. GNU (http://www.gnu.org/prep/standards/standards.html)? Any other?
    > > >
    > > > Also, I wonder what indentation you use: GNU, K&R? Spaces or tabs for indents?
    > > > 4-wide or 8-wide tabs? What was the original standard of Moria?
    > > > Of Ben Harrison's Vanillia? Do you ever use
    > > > the indent utility to maintain a single format?
    > > >
    > > > BTW, is NPP os a CVS/SVN somewhere?
    > > >
    > > > Thanks a lot!
    > >
    > > CJN: AFAIK, most *bands, including NPP, use K&R style with 8-wide tabs and tab for indent.
    > >
    >
    > Bad, bad, bad. But at least the tab width is standard ---
    > however the text must go off 80 characters wide terminal very often...
    > Hmm, from the look of the code it's not pure K&R. Obviously not GNU, too.
    > I guess everybody indents as he likes...
  • takkaria
    Veteran
    • Apr 2007
    • 1951

    #2
    Originally posted by Bandobras
    I keep making a mess of indentation whenever I touch a C file from Angband, so I wonder what I should set up my Emacs to (or Eclipse, or 'indent' utility). I see a year ago I had the following conversation on the NPP forum, but now that V is again active I wonder if there are any opinions...
    takkaria whispers something about options. -more-

    Comment

    • Bandobras
      Knight
      • Apr 2007
      • 726

      #3
      A very nice article. It says

      Use the BSD/Allman style, and indent using tabs. Avoid lines over 80 character long (though this is not strict).
      Is it 80 characters with 8 characters wide tab? That's a very wide tab...

      Supposedly (Wikipedia)

      Code:
      indent somefile.c -st -bad --blank-lines-after-procedures -bli0 -i4 -l79 \
      -ncs -npcs -nut -npsl -fca -lc79 -fc1
      indents code by BSD/Allman. I wonder how much of V would fit in 80 lines if run through with that utility and with 8-characters tab.

      Emacs can be set up for BSD/Allman probably just with

      Code:
      '(c-default-style (quote ((c-mode . "bsd") (c++-mode . "bsd"))))
      '(c-basic-offset 3)
      '(standard-indent 3)
      '(tab-width 3)
      I'll try and see if I'm less destructive with that setting.

      Edit: more emacs code
      Last edited by Bandobras; December 22, 2007, 01:56.

      Comment

      • takkaria
        Veteran
        • Apr 2007
        • 1951

        #4
        Originally posted by Bandobras
        Is it 80 characters with 8 characters wide tab? That's a very wide tab...
        8 characters would be crazy. I generally use 3, just because everyone else uses even numbers -- in this way, I can see spaces-instead-of-tabs really easily.

        Supposedly

        Code:
        indent somefile.c -st -bad --blank-lines-after-procedures -bli0 -i4 -l79 \
        -ncs -npcs -nut -npsl -fca -lc79 -fc1
        indents code by BSD/Allman. I wonder how much of V would fit in 80 lines if run through with that utility and with 8-characters tab.
        Indent always manages to screw up the source. Steven Fuerst (previous Z developer) wrote a patch for indent that makes it indent code Angband-style.
        takkaria whispers something about options. -more-

        Comment

        • pav
          Administrator
          • Apr 2007
          • 793

          #5
          Tabs are ment to be eight spaces wide That's the end of it.
          That said, it does not matter much on a 300+ columns terminal.
          See the elves and everything! http://angband.oook.cz

          Comment

          • Bandobras
            Knight
            • Apr 2007
            • 726

            #6
            Those wide-screen monitors?

            Comment

            • pav
              Administrator
              • Apr 2007
              • 793

              #7
              Originally posted by Bandobras
              Those wide-screen monitors?
              Pretty wide. Good for coding, bad for scrollback.
              See the elves and everything! http://angband.oook.cz

              Comment

              • Bandobras
                Knight
                • Apr 2007
                • 726

                #8
                Originally posted by takkaria
                8 characters would be crazy. I generally use 3, just because everyone else uses even numbers -- in this way, I can see spaces-instead-of-tabs really easily.
                So, I now use 3 spaces wide tab, too. But I recently encountered a case where tab width matters. (This is how my emacs formats it by itself.)

                Code:
                 int v = MY_CONST * (wieeerd_struct->loooooooooooong_field
                                     + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                                     - wieeerd_struct->medium_field)
                It's obviously tab width-depenent, so what am I doing wrong? Does it agree with BSD/Allman?

                P.S. A simpler example:

                Code:
                 int v = (wieeerd_struct->loooooooooooong_field
                          + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                          - wieeerd_struct->medium_field)
                Last edited by Bandobras; March 22, 2008, 00:54.

                Comment

                • takkaria
                  Veteran
                  • Apr 2007
                  • 1951

                  #9
                  Originally posted by Bandobras
                  So, I now use 3 spaces wide tab, too. But I recently encountered a case where tab width matters. (This is how my emacs formats it by itself.)

                  Code:
                   int v = MY_CONST * (wieeerd_struct->loooooooooooong_field
                                       + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                                       - wieeerd_struct->medium_field)
                  It's obviously tab width-depenent, so what am I doing wrong? Does it agree with BSD/Allman?

                  P.S. A simpler example:

                  Code:
                   int v = (wieeerd_struct->loooooooooooong_field
                            + wieeerd_struct->longeeeeeeeeeeeeeeeeeer_field
                            - wieeerd_struct->medium_field)
                  You use tabs to indent to the same as the line you're continuing on from, and then spaces after that. This solves indentation issues with all setups.
                  takkaria whispers something about options. -more-

                  Comment

                  • Bandobras
                    Knight
                    • Apr 2007
                    • 726

                    #10
                    Originally posted by takkaria
                    You use tabs to indent to the same as the line you're continuing on from, and then spaces after that. This solves indentation issues with all setups.
                    Ha, so this is emacs fault --- it does not let me mix tabs and spaces with default settings. Instead it fits as many tabs as it can and then a few spaces. Of course it's configurable, for sure...

                    Comment

                    • Bandobras
                      Knight
                      • Apr 2007
                      • 726

                      #11
                      Originally posted by Bandobras
                      Ha, so this is emacs fault --- it does not let me mix tabs and spaces with default settings. Instead it fits as many tabs as it can and then a few spaces. Of course it's configurable, for sure...
                      After some experimentation and some googling I'm afraid it's not configurable. Unless I want to script my own c-mode, that is, which I don't. I don't want to part with automatic indentation that Emacs gives me, so I have no choice but to break indentation whenever I contribute, either by inserting too many tabs in some cases (as shown above) or by turning to spaces-only mode.

                      I'm wondering which way is better and what tab width to assume (4 reads best for me, 3 would be fine, but statements align with conditions in ifs, 2 is not enough visual feedback with such long functions as C has).

                      No, I won't switch to vi.

                      Comment

                      Working...
                      😀
                      😂
                      🥰
                      😘
                      🤢
                      😎
                      😞
                      😡
                      👍
                      👎