Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 kj Posts: 197 Registered: 8/17/09
Re: how to implement the "many tiny functions" paradigm?
Posted: Jan 10, 2013 1:45 PM
 Plain Text 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?

Date Subject Author
1/9/13 kj
1/9/13 dpb
1/9/13 Yuri Geshelin
1/10/13 Bruno Luong
1/10/13 kj
1/10/13 Steven Lord
1/10/13 kj
1/10/13 kj

© The Math Forum at NCTM 1994-2018. All Rights Reserved.