Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/STYLE

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



Coding Style
----------------------------------------------------------------------

Variables:
  - Integer and bool constants should be defined as enumerations.

  - Constants should have every character capitalized and each word is separated
    by underscore.

  - Global variables should never be used except in the case of a singleton
    class or a fixed size array with preset information.  Global variable names
    should start with lowercased class namea followed by words that have first
    character capitalized.  For example: debugInstance, configParserRegistry.
    In the case of singleton, an accessor function should be provided so that
    all the functions will access it indirectly.  However, it is not needed for
    array.

  - Local variables and struct member variables should be lowercased and should
    not have any separating underscore between words. 

  - Variable names should strive to be descriptive.

  - Function argument if in the case such that its type does not fully reveal
    its real type should try to be type suggesting.  For example: char *path.
    All class function should name its first variable self with the class' type.
    In the case of interface where type of first variable differs from the
    class' type, lowercased name of its type is prefered as variable name.

  - Local variables and struct members should be role suggesting.

  - In the case such that no descriptive name can be found or such descriptive
    name is way too long while having a short name is equally descriptive, then
    the short name is preferred.  For example: int i, for looping.


Functions:
  - Each word should be separated by underscores between them unless such word
    is used in many functions in which that word serves a common purpose.  For
    example: isempty, notempty, onclick.  However, class name is treated
    differently.

  - Class functions should be prefixed with the lowercased class name followed
    by an underscore then followed by the rest of the function name.  

  - Getter functions should not use the word 'get' in the function name while
    setter function should have the word 'set' in their function names. 

  - Singleton's class should still assert in the functions pretending that it is
    not singleton class.


Class:
  - Each class must provide a construtor class_new(), and destructor
    class_free().

  - Parent class should never try to call free on self.  It should let the
    children class to call free on self.  Parent should free whatever field it
    has allocated.

  - Destructor should take in double pointer and then set the pointer to nil
    when done freeing.

  - Singleton function should set variables to nil in destroy functions. 


Functors:
  - Functors' typedef should follow the the rule for local variables.
  - Struct's Functor member and function functor argument follow the same rule
    as function since they are used like a function.

Assertions:
  - Assertions should always be used when dealing with pointers internal to the
    program itself.  However, dealing with outside influence such as when
    writing a library, pointers should always be checked and not asserted since
    the users are out of the library's control.

  - helper function whose arguments are already asserted by caller and the
    helper function will never be called by other function directly should not
    assert the arguments again.

  - subclass' operations (functions that are dynamically dispatched), should not
    assert, since the parent that dispatches the function. 

  - If just calling other public function in the same class that will assert the
    variables, then assertion is not needed.

Class:
  - Class should try to hide as much of its implementation as possible, so it's
    most preferrable if each class only provides a typedef in the header w/o
    struct def.  Also, class should provide a class_new and class_free function.

  - class_free function should accept a double pointer to the class and then set
    the single pointer to nil after freeing.

  - If new/free is not possible, then class must set up init and destroy
    function.


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].