In <email@example.com> kj <firstname.lastname@example.org> writes:
>The question is how to implement this "many tiny functions" strategy >in MATLAB.
>To be more specific, suppose that I start with some "large" function >foo, implemented in a ~100-line file foo.m, and I break it down >into about ~20 tiny functions, including a new (and much smaller) >entry-point function foo that calls the remaining tiny functions, >either directly or indirectly.
>The problem is that, if the new foo.m file now looks like this:
> function f = foo(a, b, c) > ...
> % End of function foo
> function b = bar(d, e) > ...
> % End of function bar
> function z = zzz(x, y) > ...
> % End of function zzz
OK, one possibility (still rather imperfect) is to replace the above with something like this:
classdef foo methods (Static) function f = run(a, b, c) % the function formerly known as foo; % it calls one or more of foo.bar, ..., foo.zzz ... end
function b = bar(d, e) ... end ...
function z = zzz(x, y) ... end end end
Now all the functions are accessible from other files, and yet they do not pollute the global namespace.
The one drawback I see is that, instead of calling foo(a, b, c), one must call foo.run(a, b, c).