Code blocks must be short

Share this topic:



Link to this posting

Postby Ursego » 21 Feb 2013, 15:45

Don't allow code blocks to overgrow.

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, for example, BEGIN/END in PL/SQL.
2. Code branching operators (like IF ... ELSE ... END IF).
3. Looping operators (FOR ... NEXT, LOOP ... END LOOP, DO ... WHILE etc.)

It's a great idea to keep the opening and closing operators on one screen. If you see that it's impossible then think about extracting the block's code into a new function.

That solution will also decrease the indenting: for example, the fragment

PB:
Code: Select all
if [condition] then
   [very long code fragment with its own indents]
end if

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

will be looking in the new function as

PB:
Code: Select all
if not [condition] then return
[very long code fragment with its own indents]


C#:
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".
User avatar
Ursego
Site Admin
 
Posts: 112
Joined: 19 Feb 2013, 20:33

Return to Managing Functions

Who is online

Users browsing this forum: No registered users and 1 guest


Code blocks must be short

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





cron
free counters

eXTReMe Tracker