[Click] Coding style

Eddie Kohler kohler at cs.ucla.edu
Wed Feb 10 13:10:14 EST 2010


Hi Ruben!

Well, I could go on for a long time; but short version there are two answers.

(1) Click's modularity lets you implement your own coding style in your own 
elements.  Go ahead!  That's the point of the design: your elements' coding 
style won't really hurt anyone else.

BUT

(2) Here's how I like to write elements.

* Four space indent, eight space tab character.

* Compile cleanly: no warnings.  That means if GCC says to parenthesize 
something, parenthesize it.

* "K&R"-like conventions:
   - No space after a function name ("f()", not "f ()").
   - Space after keywords ("for (...)", not "for(...)").
   - Avoid unnecessary braces:
     if (x)                          if (x) {
         foo();     BETTER THAN          foo();
                                     }

   - Newlines after the initial portions of compound statements:
     if (x)
         foo();     BETTER THAN      if (x) foo();

* Identifier conventions:
   - Classes are named InCamelCase.
   - Methods and variables are named in_lower_case_with_underscores.
   - Instance variables are named _in_lower_case_with_leading_underscore.
   - Use short variable names like i for counters, etc.
   - Use longer variable names for instance variables, etc.

* Name choice: Name instance variables and, particularly, Click-level keyword 
arguments by pattern-matching on existing elements.  For example, Queues have 
a CAPACITY, they do not have a MAXLENGTH; so if your element has a maximum 
number of packets configuration argument, call that argument CAPACITY.

* Violate any of these rules if it makes your code more readable.

Hope this helps
Eddie


Ruben Merz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> Hi,
> 
> Is there any document describing the coding style for Click? Is it
> "standard" C++? Do folks care about it or not?
> 
> Looking for instance in include/click/element.hh, I find the following
> macros for emacs, which is concerned essentially with indentation:
> 
> // -*- c-basic-offset: 4; related-file-name: "../../lib/element.cc" -*-
> 
> Anything else?
> 
> Thanks
> Ruben
> 
> - -- 
> Ruben Merz                   Deutsche Telekom Laboratories
> http://www.net.t-labs.tu-berlin.de/people/ruben_merz.shtml
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iQEcBAEBAgAGBQJLcY5OAAoJEIem9YkUyRjtEyQIAKSTHtgJKd0vnS8Y3zdZpSiS
> +ebzN90hPvCpehDBNyPECrFuh8+k4q5M4PA9rR++k8fRz6KN2mQoDGHo9zefFep5
> wAL7JRYM4XDTzoXMquzh/2TG57afbIUBWgNLuSNawQ662sXYyEdJNHIBwGRPh8Nt
> ewHKwnwK/BEeAdQmFZDOzhoLhfN7u1QRsr5V/IhZ+HyCyWWn7xW5aZiEL/TQlPso
> 5pEtKMs6lzCKF2R1hx3AZy8AqT6/n9CwiUiB1LvqUJJG6cmjYLXdHpcLe8g1EX4c
> FR5NCNkiqGJM7/17+pFBye3dibgywpSCUTTy8RxrnB0izliYfMEY4QOto2Mng6Q=
> =60Dd
> -----END PGP SIGNATURE-----
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click


More information about the click mailing list