Re: What's the Best Way?

new topic     » goto parent     » topic index » view thread      » older message » newer message

> From:  cklester
>

[snip]

> Right now, any output is automatically sent to a global
> variable, abcOutput,
> for the programmer to parse himself.
>
> It goes something like this:
>
>     abc( GET_DATA , { recID, field } )
>
> and abcOutput would contain the data returned by that command.
>
> But would it be better for me to make individual procedures/functions?
> Instead of
>     abc( GET_DATA , {recID, field} )
> I would use
>     abc_get_data( recID , field )
> or turn it into a function,
>     abcOutput = abc( GET_DATA , { recID , field } )
> or
>     abcOutput = abc_get_data( recID , field )
> Right now it has, maybe, 10 commands, and is handled like this:
>
> procedure abc( sequence command , sequence params )
>     if command = COMMAND_ONE then...
>     if command = COMMAND_TWO then...
>     etc...
> end procedure

Yuk.

>
> What's the most efficient way? I'm thinking about cross-platform
> compatibility, maintainability, extensibility, etc-bility...
>

I've had to do some things like this.  The final solution really depends on
how the commands will be used, but I think your best bet is probably to use
routine_id / call_func to access your commands.  This means turning your
procedures into functions, first off.  Then, I'd put all of your
routine_id's into a sequence:

COMMAND[1] = routine_id("Command1")
... etc

You can wrap this if you like, with one global procedure (and leave the
actual functions within your include local):

global function DataCommand( integer command, sequence params )
        return call_func( command, params )
end function

This has the nice feature of getting rid of the if..then tree you've
constructed, and it's fairly easy to see what's going on.  BTW, this is the
same type of thing David Cuny's done in win32lib with event procedures.

<plug>For another example, you can check out my matheval lib at
http://members.xoom.com/matthewlewis/projects
Pretty much everything follows this format, and made much of it work almost
like magic (at least as far as putting together all of the differnt ops was
concerned:).</plug>

Hope this helps.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu