Re: Artistic style.

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Wed Feb 07 2001 - 16:43:13 EST

  • Next message: Jens Ivar Jordre: "Re: Artistic style."

    Hi Jens Ivar, Konstantin, et al. 
    
    While waiting for a batch job to finish, building BRAT, ROOT, etc., I
    thought I'd drop a penny on this one. 
    
    On Wed, 7 Feb 2001 21:09:42 +0100 (CET)
    Jens Ivar Jordre <jens@fi.uib.no> wrote
    concerning ": Re: Artistic style.":
    > On Wed, 7 Feb 2001, Konstantin Olchanski wrote:
    > 
    > > On Wed, Feb 07, 2001 at 07:41:44PM +0100, Jens Ivar Jordre wrote:
    > > >
    > > > I'd just like to point out a useful program for our coding and different
    > > > conventions. The program is called Artistic Style. It does indention
    > > > and formatting of raw C, C++ and Java code.
    > >
    > >
    > > These programs are a dime a dozen. Nothing to get excited about.
    
    I totally agree. 
    
    The best "code formatter" is the developers mind and hands. Ofcourse
    one may use some tools to help one out, but they will never ever
    replace a sound attitude toward writting readable code. 
    
    There are a six things that are the developers best friend: 
    
    1 A good refernce for the language of choice, on our case that would
      be Bjarne Stroustrup's book, or the ISO/ANSI C++ Standard. 
    2 A good reference to the used software libraries, which in our case
      amounts to http://root.cern.ch/root/html/ClassIndex.html + the
      User's Guide (now version 0.7 I believe) 
    3 A good compiler, that is GCC (avalible for _all_ platforms) 
    4 A good editor, that is Emacs (avalible for _all_ platforms) 
    5 Code versioning and archiving systems, like CVS.
    6 A pen and a piece of paper for writting down flow diagrams, class
      diagrams, algorithms, ideas, etc. In fact, this is the most
      important tool of all! Much more so then a computer. 
    
    Let me comment on point 4 in the context of code formatters and the
    like: 
    
    Emacs, as you all probably know, is THE editor, no matter what you
    do. In fact it is much more then an editor - it's a kitchen sink: you
    have the foset, the drain, the dishwashing brush, the knife, the food,
    the paint (not togther I hope), and so on. 
    
    Hence, it should be of little surprise that Emacs can automatically
    format you code as you write, almost regardless of what you're
    writting. 
    
    Personally, I use Emacs for almost everything, heck sometimes I even
    execute ROOT from a shell in Emacs. More specifically, I use Emacs for
    writting code. Now, per default, line-wrapping (also known as
    auto-fill) and colored fonts (aka font-lock) is not turned on for
    C/C++ code in Emacs, so what I do, is that I put something like the
    below in my ~/.emacs (On Windoze I believe it's %HOME%\emacs): 
    
     ;;; Add colours to all modes. 
     (global-font-lock-mode t)
     ;;; My hook for C/C++ code 
     (defun my-c-mode-common-hook ()
       "Hook for C/C++ mode"
       ; (setq c-comment-continuation-stars "*")
       (c-toggle-auto-hungry-state 1)
       (if (eq global-font-lock-mode t)
           (progn
              (add-to-list 'c++-font-lock-extra-types "\\sw+_t") 
             (add-to-list 'c++-font-lock-extra-types "FILE")
             ; Below for ROOT
             (add-to-list 'c++-font-lock-extra-types "T\\sw+")
             ; Below for BRAT
             (add-to-list 'c++-font-lock-extra-types "Br\\sw+")))
       (if (eq global-font-lock-mode nil)
           (turn-on-font-lock))
       (turn-on-auto-fill)
       (set-variable 'c-comment-continuation-stars "*") 
       (set-variable 'c-indent-comments-syntactically-p t)
       (set-variable 'c-cleanup-list 
                     '(
                       ; brace-else-brace 
                       brace-elseif-brace 
                       empty-defun-braces 
                       list-close-comma 
                       scope-operator))
       (set-variable 'c-hanging-semi&comma-criteria
                     '(c-semi&comma-no-newlines-for-oneline-inliners
                       c-semi&comma-no-newlines-before-nonblanks
                       c-semi&comma-inside-parenlist))
       (set-variable 'c-hanging-braces-alist 
                     '((brace-list-open) 
                       (substatement-open after) 
                       (block-close . c-snug-do-while) 
                       (extern-lang-open after) 
                       (inline-open . nil) 
                       (inline-close after))))
     ;;; Empty hooks for C++ mode
     (defun my-c++-mode-hook ()
       "Hook for C++ mode"
       )
     ;;; Empty hooks for C mode
     (defun my-c-mode-hook ()
       "Hook for C mode"
       )
     ;;; Set hooks for C/C++ modes 
     (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
     (add-hook 'c++-mode-hook      'my-c++-mode-hook)
     (add-hook 'c-mode-hook        'my-c-mode-hook)
     ;;; Decorate almost everything 
     (setq font-lock-maximum-decoration
           '((c-mode . 3) (c++-mode . 3)))
     
    You can refer to my code in BRAT (e.g. BrDb<...>) for examples, for
    better or for worse - though I believe it's somewhat readable. 
      
    > At least I agree with the first one.
    > 
    > > > If used, it will make our code easier to read.
    > >
    > > I rather doubt this claim. The best way (the only way) to make code easy
    > > to read is to *write good code*. Linus Torvalds wrote quite a few
    > > excellent assays on this.
    
    If you care for what Linus has to say (and who doesn't - I mean, even
    Bill hs to listen when the mad fin speaks), refer to 
    
         /usr/src/linux/Documentation/CodingStyle
    
    on almost any Linux box. 
    
    > Couldn't agree more regarding the best way. However, it is easier to read
    > code that has structured indention than complete anarchy.
    
    Uh. Don't confuse Anarchy with Chaos. Two very different things.
    
    However, there are unfortunually many examples in BRAT of how
    unreadable and chaotic code can be if not indentet . I guess Jens Ivar  
    suggesting to use something like AStyle reflects the current situation
    very well. 
     
    > > > It has some built in styles. Maybe we could settle upon one of these.
    > >
    > >
    > > Coding styles, "spaces per tab", the only right place to put the curly
    > > braces, underscores versus mixed-case in variable names, kConstant
    > > versus UPPER_CASE_CONSTANT.
    > 
    > It only deals with indentation. Style on data members, function names etc.
    > is not touched.
    
    Kris wrote an exellent set coding convetions for BRAT once. That is
    still valid.
     
    > > Being there done that. Do we get to vote on each feature? (Yawn...)
    > >
    > >
    > > > A link to its sourceforge web page is put on the regular private area
    > > > computing page: http://www.rhic.bnl.gov/brahms/WWW/private/computing.html
    > > > The direct link is: http://astyle.sourceforge.net
    > > >
    > > > Do try it out!!!
    > >
    > > Don't waste your time. Go and write some good code instead.
    >
    > Depending on your taste, chose from any of the two statements above.
    
    May I propose an alternative to both of your: USE EMACS!!!
    (I believe Konstantin uses Emacs, but I may not remember right). 
    
    Ups, sorry - I turned a bit religious there. No, really, I highly
    recommend using Emacs. You avoid all that crap of having external
    programs to do your formatting, since Emacs formats on the fly, and
    you do get some help so that you may relax your (some times)
    overheated brain :-( 
    
    And to you Windoze users: There's nothing wrong with writting your
    code in Emacs, and compiling it using Windoze Visual C++ (or is that
    F**k++?). 
    
    Ups, now BRAT and ROOT is through compiling, and my batch job done -
    that means back to work. See ya' 
    
    Yours, 
    
    Christian  -----------------------------------------------------------
    Holm Christensen                             Phone:  (+45) 35 35 96 91 
      Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
      DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
      Denmark                                    Email:       cholm@nbi.dk
     
    



    This archive was generated by hypermail 2b29 : Wed Feb 07 2001 - 16:44:15 EST