RFC: Add a short doc with libvirt coding style guidelines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There's a few coding style guidelines we've kind of informally agreed upon
wrt to libvirt patches, and perhaps more that we ought to make decisions on.
For the benefit of people sending patches I reckon its worth writing these
down. So I'm attaching a proposed doc 'HACKING' in which we can detail the
guidelines.  And yes, we don't uniformly comply with these guidelines in
all places....all the more reason to list them & fix cases where we don't
comply :-)

Thoughts.. ?

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
       Libvirt Hacking Guidelines
       --------------------------

  1. Apply sizeof to the return variable, not the type.

     eg Instead of

        SomeType *foo;
        ....
        foo = malloc(sizeof(SomeType))

     Use

        SomeType *foo;

        foo = malloc(sizeof(*foo))

    So if foo's type is changed in future it avoids having
    to search for & fixup all malloc statements.


  2. Do not use conditionals in front of 'free'.

     eg Instead of

       if (foo) free(foo)

     Use

       free(foo)


  3. Include "config.h" in all source files

     eg

         #include "config.h"


  4. Indent in 4 space units, without tabs

     eg Add this at end of every file for VIM & Emacs

       /*
        * vim: set tabstop=4:
        * vim: set shiftwidth=4:
        * vim: set expandtab:
        */
       /*
        * Local variables:
        *  indent-tabs-mode: nil
        *  c-indent-level: 4
        *  c-basic-offset: 4
        *  tab-width: 4
        * End:
        */


  5. Ensure any user visible strings are marked for translation

      eg wrap all strings with _(...)

        virXendError(xend, VIR_ERR_INTERNAL_ERROR,
                     _("domain information incomplete, missing domid"));


--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]