Page 1 of 1

Code blocks must be short

PostPosted: 21 Feb 2013, 15:45
by Ursego
Keep the operators, which open and close the block, on one screen. If it's impossible then refactor (extract) the block into a brand new function.

A code block is a fragment, placed between opening and closing operators. These operators are (in different languages):

1. Special code block delimiters: braces ({ and }) in C-like languages and BEGIN/END in PL/SQL and Transact-SQL.
2. Code branching operators (like IF ... ELSE ... END IF).
3. Looping operators (FOR ... NEXT, LOOP ... END LOOP, DO ... WHILE etc.)

That solution will also decrease the indenting. For example, the fragment

Code: Select all
if ([condition]) {
   [very long code fragment with its own indents]

will be looking in the new function as

Code: Select all
if (![condition]) return;
[very long code fragment with its own indents]

But that is already the subject of the topic "Code after validations".