Changes between Version 11 and Version 12 of Hacking


Ignore:
Timestamp:
02/15/11 21:41:37 (14 years ago)
Author:
angel_il
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Hacking

    v11 v12  
    7171}}} 
    7272 
    73 === Code blocks (if, for, case...) === 
     73=== Conditions in Code blocks (if, for, case...) === 
    7474 
    7575Always follow an 'if' keyword with a space but don't include additional 
     
    7979{{{ 
    8080    if (i == 0) 
     81 
    8182}}} 
    8283'''This is wrong:''' 
     
    8485    if ( i == 0 ) 
    8586    if (0 == i) 
    86 }}} 
     87 
     88}}} 
     89 
     90=== Functions usage === 
    8791 
    8892Always insert a space between the name and left parentheses when invoking functions. 
     
    9195{{{ 
    9296    do_example (int param1, int *result1); 
     97 
    9398}}} 
    9499'''This is wrong:''' 
    95100{{{ 
    96101    do_example(int param1, int *result1); 
    97 }}} 
     102 
     103}}} 
     104 
     105=== Braces === 
    98106 
    99107Braces for code blocks used by '''for, if, switch, while, do..while''', etc. should begin on the next line after the statement keyword and end on a line of their own.  
     
    136144}}} 
    137145 
     146=== Goto === 
     147 
    138148Use "goto" only when necessary. "goto"s are evil, but they can greatly enhance readability and reduce memory leaks when used as the single exit point from a function.  
    139149 
     
    158168    g_free (dest); 
    159169} 
    160 }}} 
     170 
     171}}} 
     172 
     173=== Readable The Code === 
    161174 
    162175Use your best judgement and choose the more readable option. 
     176Remember that many other persons will review it: 
    163177 
    164178'''This is right:''' 
     
    166180    bytes = read (fd, &routine.pointer, sizeof (routine)); 
    167181    if (bytes == -1 || (size_t) bytes < (sizeof (routine))) 
     182 
    168183}}} 
    169184 
     
    174189    if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int)) 
    175190        return NULL; 
     191 
     192}}} 
     193 
     194=== Make use of helper variables === 
     195 
     196Please try to avoid passing function calls as function parameters in new code. This makes the code much easier to read and it's also easier to use the "step" command within gdb. 
     197 
     198'''This is right:''' 
     199{{{ 
     200void 
     201dirsizes_cmd (void) 
     202{ 
     203    WPanel *panel = current_panel; 
     204    int i; 
     205    ComputeDirSizeUI *ui; 
     206 
     207    ui = compute_dir_size_create_ui (); 
     208 
     209    compute_dir_size_destroy_ui (ui); 
     210 
     211    recalculate_panel_summary (panel); 
     212 
     213} 
     214 
     215}}} 
     216 
     217'''This is wrong:''' 
     218{{{ 
     219void 
     220dirsizes_cmd (void) 
     221{ 
     222    compute_dir_size_destroy_ui (compute_dir_size_create_ui ()); 
     223} 
    176224 
    177225}}}