Code sprint: pkg.m: Difference between revisions

m
Line 35: Line 35:
== Dispatching ==
== Dispatching ==


Each action has its own set of valid modifiers and behaves accordingly. Therefore the rôle of the main function ''pkg'' is to call the right action once general sanity checks have been performed.
Each action has its own set of valid modifiers and behaves accordingly, that is the function ''pkg'' does not parse targets nor modifiers. Therefore the rôle of the main function ''pkg'' is to call the right action once general sanity checks have been performed.
 
The particular implementation of this dispatch behavior was source of some discussion.
The particular implementation of this dispatch behavior was source of some discussion.
* Using structure
* Using structure
: One way of implementing the dispatch is using structures with fieldnames equal to the action and containing a function handle. [http://agora.octave.org/snippet/5UUz/ Here is an example].
: One way of implementing the dispatch is using structures with fieldnames equal to the action and containing a function handle. [http://agora.octave.org/snippet/5UUz/ Here is an example].
: Some people do not like this because they consider it a weird use of a structure.
: Some people do not like this because they consider it a weird use of a structure.
* Using feval
* Using ''feval''
: Another way of doing it (and the implemented as of revision 2c16a852bae9 in carandraug's repository) is building a string of the function to call and use feval. [http://agora.octave.org/snippet/ozym/ Here the example]
: Another way of doing it (and the implemented as of revision 2c16a852bae9 in carandraug's repository) is building a string of the function to call and use ''feval''. [http://agora.octave.org/snippet/ozym/ Here the example]
* Using objects
* Using objects
: Where we have an ''action'' class with fields valid_modifiers and method parse_modfiers. All ''_pkg'' actions inherit the general valid_modifiers and extend them with their own, as well as overloading the parser_modifier method. This gives the maximum flexibility, but since is too much of a change we haven't code it.
: Where we have an ''action'' class with fields valid_modifiers and method parse_modfiers. All ''_pkg'' actions inherit the general valid_modifiers and extend them with their own, as well as overloading the parser_modifier method. This gives the maximum flexibility, but since is too much of a change we haven't code it.
657

edits