Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: how to implement the "many tiny functions" paradigm?
Replies: 7   Last Post: Jan 10, 2013 4:10 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
kj

Posts: 179
Registered: 8/17/09
Re: how to implement the "many tiny functions" paradigm?
Posted: Jan 10, 2013 1:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

In <kckj4h$m4s$1@reader1.panix.com> kj <no.email@please.post> 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).

Are there other drawbacks I'm not seeing?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.