The Math Forum

Search All of the Math Forum:

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

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

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

Advanced Search

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

Posts: 197
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$> kj <> writes:

>The question is how to implement this "many tiny functions" strategy

>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.zzz

function b = bar(d, e)

function z = zzz(x, y)

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, 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]

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