Personally, I find this sort of stuff to be very unreadable. If
it is used multiple times, it is not quite so bad. If it is used but
once, it is a disruption to following the caller.
There is also context to consider. I have sometimes considered
moving some short, common code to subroutines to find that by the time
I re-established the context in the subroutine, the subroutine's code
would be longer than having the code in the caller.
That is extreme.
No need to call me an idiot. Actually, I don't advocate "extracting all
code in an inner loop, if it would require a conditional break or
continue". I advocate distinct intuitive steps into simple methods,
always, unless you have a specific reason not to. A good reason, not
just any reason.
You are talking past each other. He is not talking about
intuitive steps, but just automatic "methodising" of code.
Many experts in the field of software design agree. I learned this
practice directly from Martin Fowler as a matter of fact, in a training
session he did on TDD at my company.
Who calls a method is irrelevant to only value of such a method, unless
the number of callers is zero of course.
If it is only one, in-line might be better.
Intelligent thought is always required, for all software design. The
problem is when people do things by guessing.
Or by manifesto which is much the same.
It depends on the loop. How about instead "processNextStuff()" (where
stuff is replaced with a meaningful name).
innerLoopStuff2(), innerLoopStuff3(), ... ?
I'm not going to say "It must always be done!" but I will say that when
done *right*, it will improve the maintainability of the code base
significantly.
But then it probably would be done as the code is written,
because it is a sensible -- what you called "intuitive" above --
design.
I like my code to tell a story at one level of abstraction. It
makes it easier to follow the logic. The high-level code is all in
one sequence. With this, I can skip the lower-level logic most of the
time. If I need to adjust the higher-level logic, it is a good sign
when I do not have to concern myself much with the lower-level logic
(because what I came up with for it is still what is needed).
Thanks,
Daniel
Yet Another Idiot Apparently.
Nope. You are too thoughtful for that.
Sincerely,
Gene Wirchenko