Profetas wrote:
Nested statements helps to generate complex source code,
what is the nesting limit that you normally consider?
I know that the Halsted and McCabe analyses can define the
acceptable level, but in your personnel point of views what is the
limit before you re-code the block into multiple blocks
a 3 level nesting example
If (z is true)
while (x < Y )
begin
if (z==x)
......
else
.......
end if
end
end
else
while (x < Y )
begin
if (z==x)
......
else
.......
end if
end
end
end if
I think that 3 level sometimes 4 is acceptable.
but I was wondering would you restrict it to 3 or 4?
is there anyway to avoid this excluding the creation of new
functions?
First, take your own example and avoid creating non-existent
levels. The 'begin's (which are '{' in C) are not a level of
control. Then limit the line length to 72 chars or so. You should
also use the rule of 7, which says that a function should deal with
no more than 7 items at once, because the human brain becomes
confused with more.
Rewriting your example into reasonable (IMO) format:
If (z is true) {
while (x < Y) {
if (z == x) ......
else .......
}
}
else {
while (x < Y) {
if (z == x) {
......
}
else {
.......
}
}
}
Which smells (to me) as if misconstructed. I suspect the .....
areas should have been parametized in some form, so that the
overall code should be simplified to:
if (z) operateon(x, y, zz);
else operateon(z, y, z);
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!