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



kj
Posts:
197
Registered:
8/17/09


Re: how to implement the "many tiny functions" paradigm?
Posted:
Jan 10, 2013 4:10 PM


In <kcn6p7$m1r$1@newscl01ah.mathworks.com> "Steven_Lord" <slord@mathworks.com> writes:
>Depending on what you're doing, there are three possibilities that you may >want to explore.
>If all these "tiny functions" are only used by your application, and your >tests will live in the same directory, make your helpers private functions.
>http://www.mathworks.com/help/matlab/matlab_prog/privatefunctions.html
>If they are used by many files in different directories, or if your tests >must live in a different directory, consider putting your helpers in a >package directory.
>http://www.mathworks.com/help/matlab/matlab_oop/scopingclasseswithpackages.html
>While this documentation is in the objectoriented section of the >documentation, packages are not limited to use only with MATLAB classdef >files. You can store plain functions in a package and use them as such.
>A third, somewhat "hacky" way to test many small subfunctions in your main >file is to have a syntax that causes the main function to return a struct >array whose fields contain function handles to the subfunctions. Your tests >can then invoke the subfunctions using those function handles even though >the subfunctions are not in scope. As long as the subfunction was in scope >when the function handle was _created_ it doesn't matter if the subfunction >is out of scope when the function handle is _executed._
>http://www.mathworks.com/help/matlab/matlab_prog/applicationsoffunctionhandles.html#brf_1tn1
Thanks, that's very useful info. (I got to admit I loved the last one, hacky as it may be.)



