Changes between Version 9 and Version 10 of Hacking


Ignore:
Timestamp:
02/15/11 21:20:39 (13 years ago)
Author:
angel_il
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Hacking

    v9 v10  
    7171}}} 
    7272 
    73 === Code blocks (if, for, case...)=== 
     73=== Code blocks (if, for, case...) === 
    7474 
    7575Always follow an 'if' keyword with a space but don't include additional 
    7676spaces following or preceding the parentheses in the conditional. 
    7777 
    78 This is right: 
     78'''This is right:''' 
    7979{{{ 
    8080    if (i == 0) 
    8181}}} 
    82 This is wrong: 
     82'''This is wrong:''' 
    8383{{{ 
    8484    if ( i == 0 ) 
    85     /*  
    8685    if (0 == i) 
    8786}}} 
     
    8988Always insert a space between the name and left parentheses when invoking functions. 
    9089 
    91 This is right: 
     90'''This is right:''' 
    9291{{{ 
    9392    do_example (int param1, int *result1); 
    9493}}} 
    95 This is wrong: 
     94'''This is wrong:''' 
    9695{{{ 
    9796    do_example(int param1, int *result1); 
    9897}}} 
    99  
    100  
    10198 
    10299Braces 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.  
     
    106103If the beginning statement has to be broken across lines due to length, the beginning brace should be on a line of its own. 
    107104 
    108 This is right: 
     105'''This is right:''' 
    109106{{{ 
    110107    if (xterm_flag && xterm_title) 
     
    121118 
    122119}}} 
    123 This is wrong: 
     120'''This is wrong:''' 
    124121{{{ 
    125122    if (xterm_flag && xterm_title) { 
     
    137134                g_free (*str_options[i].opt_addr); 
    138135 
     136}}} 
     137 
     138Use "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.  
     139 
     140'''This is right:''' 
     141{{{ 
     142{ 
     143    if (link_type == LINK_HARDLINK) 
     144    { 
     145        src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46)); 
     146        dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, ""); 
     147 
     148        if (!dest || !*dest) 
     149            goto cleanup; 
     150    ... 
     151    ... 
     152    } 
     153  ... 
     154  ... 
     155 
     156  cleanup: 
     157    g_free (src); 
     158    g_free (dest); 
     159} 
    139160}}} 
    140161