A
Antoon Pardon
Op 2004-09-01 said:I'm afraid that's bollocks, equivalent to saying that building an
airliner by connecting subassamblies together is just camouflaging the
complexity.
No it is not.
Those subassemblies each have their own function. Usually you
can even use subassemblies to build different planes.
But if something is complex and for whatever reason not easily
divided in subassemblies than just picking a number of things
that are in each others neighbourhoud and calling that a
subassembly won't accomplish much. And that is eactly what
you do if the only reason for making something a function
is because the code in question was nested too deep.
Presumably your chosen method would be to assemble a pile of all the
parts and then just stick them together one by one? God help the test
pilot if so...
Well you presume wrong.
[One of] the pointabout classes and functions is precisely that they
do allow you to reduce the complexity by providing repeatable unit
behavior which you can test before you rely on them in your higher-level
logic.
So? That doesn't mean you should define one, just because some
code was nested too deep.
The alternative is monolithic programs, which are well known to be
difficult to compile and maintain.
If your program logic is too deeply nested with conditions then
functions and classes provide a powerful logical abstraction to fight
the complexity and improve code reliability and maintainability.
Only if that code has some usefull abstraction. Just putting some
code in a function doesn't provide any usefull abstraction.