Re: if/else loops
- From: The Natural Philosopher <tnp@xxxxxxxxxxxxxxx>
- Date: Tue, 05 May 2009 17:53:15 +0100
Jerry Stuckle wrote:
rf wrote:Tim Streater wrote:In article <KgqLl.8350$y61.4746@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
"rf" <rf@xxxxxxxxx> wrote:
Jerry Stuckle wrote:A piss-poor rule.
I keep my function short and to the point, also. But I also don'tWhen I learned OOP many decades ago the rule was exactly one entry
strew return statements all over the place.
point to a function (at the start) and exactly one exit point (at
the end). The "teaching" languages did not *have* a return
statement, much less a goto statement.
Your opinion? Or do you care to cite something.
If something inside an if (for example) becomes so non-trivial as toSo you end up with trillions of functions each doing damn-all. And how
cause indentation problems then that something probably deserves to
be in its own function.
do you give them sensible names to cover what little they are doing?
Yes, you end up with lots of functions. Lots of well documented easy to understand (read maintainable) functions.
Exactly.
Another of the principles put forward those long decades ago was that if a function went "over the fold", meaning that it was longer than two pages of fan-fold computer paper, about 120 lines, then it was too long. A function should be able to be read and understood by your average maintainence programmer almost "at a glance".
I worked partially within a project where these things were strictly adhered to. IBM customer engineers were contracted out at AU$1,000,000 PA to ensure this. The language was, believe it or not, COBOL, a language where it is quite easy to write totally incomprehensible and un-maintainable code.
The main insurance claims update program tallied over a million lines of code (these were the batch update days) and had a team of a hundred and fifty programmers working in it, plus the project managers and such. The road map for the program covered an entire wall.
Every module had exactly one entry point and exactly one exit point. Not a goto in sight. Even error situations (that we use try-catch these days to implement) were catered for.
That's tough to do in COBOL! :-)
Every module (the "procedure division") was less than one or two pages long.
And, it worked. The program was written and fully unit tested in 80 percent of the allocated time of two hundred man years. We went out to lunch Big Time.
I'll also add, it's common in C code to try to hold functions to about 20 lines or less. That's not a hard rule - but if you're running over that, you should at least examine your functions to see if you're doing too much in one function, and should possibly split it into multiple ones.
Not really. If a fiunctiuon is only called from one placem , why=y bother
/************************************************
Its just as easy to write a large comment and add a page
break, and let someione know that here the code is entering a new functional phase
and if there are issues with variable scope. in C you can define a new block like this
************************************************/
{
int new_variable;
some code...
}
Never confuse clarity of writing, with how the program flow is organised.
COBOL had its own restrictions: typically subroutines were rolled in and out of memory. To large a subroutine and no more core...
.
- References:
- if/else loops
- From: Scott Johnson
- Re: if/else loops
- From: Jerry Stuckle
- Re: if/else loops
- From: Jerry Stuckle
- Re: if/else loops
- From: Gregor Kofler
- Re: if/else loops
- From: Jerry Stuckle
- Re: if/else loops
- From: Gregor Kofler
- Re: if/else loops
- From: Jerry Stuckle
- Re: if/else loops
- From: rf
- Re: if/else loops
- From: rf
- Re: if/else loops
- From: Jerry Stuckle
- if/else loops
- Prev by Date: Re: Odd string behavior
- Next by Date: Re: Auto online update of files and directories for CMS
- Previous by thread: Re: if/else loops
- Next by thread: Re: if/else loops
- Index(es):
Relevant Pages
|