Changes between Version 9 and Version 10 of Hacking
- Timestamp:
- 02/15/11 21:20:39 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Hacking
v9 v10 71 71 }}} 72 72 73 === Code blocks (if, for, case...) ===73 === Code blocks (if, for, case...) === 74 74 75 75 Always follow an 'if' keyword with a space but don't include additional 76 76 spaces following or preceding the parentheses in the conditional. 77 77 78 This is right: 78 '''This is right:''' 79 79 {{{ 80 80 if (i == 0) 81 81 }}} 82 This is wrong: 82 '''This is wrong:''' 83 83 {{{ 84 84 if ( i == 0 ) 85 /*86 85 if (0 == i) 87 86 }}} … … 89 88 Always insert a space between the name and left parentheses when invoking functions. 90 89 91 This is right: 90 '''This is right:''' 92 91 {{{ 93 92 do_example (int param1, int *result1); 94 93 }}} 95 This is wrong: 94 '''This is wrong:''' 96 95 {{{ 97 96 do_example(int param1, int *result1); 98 97 }}} 99 100 101 98 102 99 Braces 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. … … 106 103 If the beginning statement has to be broken across lines due to length, the beginning brace should be on a line of its own. 107 104 108 This is right: 105 '''This is right:''' 109 106 {{{ 110 107 if (xterm_flag && xterm_title) … … 121 118 122 119 }}} 123 This is wrong: 120 '''This is wrong:''' 124 121 {{{ 125 122 if (xterm_flag && xterm_title) { … … 137 134 g_free (*str_options[i].opt_addr); 138 135 136 }}} 137 138 Use "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 } 139 160 }}} 140 161