I know I'm just the new guy, but if there's a huge number of options, say a system where there is an account number assigned to people that they use through a universal login and from that login get sent to different data or email or to porn or to whatever their account # dictates, what about utilizing a database or hash? The database server/system can handle a larger number of options than a hash in memory but either one can be your case/if engine. Please bear with me, just using general programming terms as I use several diff ones and I'm sure this can be done in different languages..
Example with database:
table login {
acct bigint,
function char(30),
[...]
}
sql = "SELECT function FROM login WHERE acct=" _
& someCondition
rs = runSQL(sql)
eval(rs["function"])
--
That's the general gist of it - you store the function call in a table and reference that table by the somecondition. So if condition a calls function bob, and condition a0e calls function frank, it can all be handled to the limits of the database (depending on your systems, could be millions->billions of conditions and functions). if indexed properly, pretty quick (how does google find stuff in the middle of billions of web pages in 0.09 seconds)?
This would be the lookup table in one sense.
-------
Example using hash: (no, not hashish)
janet = array(
bob=>'function1()';
frank=>'function12()';
)
eval(janet[someCondition])
--
This is essentially another lookup table that is faster than the database query as it just accesses local memory but is limited by that local memory. It is similar to the case statement, but you do have to add a little more error handling logic into that (mainly to cover the Else functionality). But these are cool because you can populate them from a database table or by hand in another function or include file or whatever and have it somewhat dynamic, yet easily so.
As you can tell, I do like databases, especially for managing large datasets. But hashes can be setup without using a database, just comes into code management which can be done with files or functions or just one big phat
hash table (woo-hoo!).
as a side note: what would make the
if, if, if, else much faster than how it was written is with
if, else if, else if, else then it's a one time comparison instead of repetitive comparisons.
AndyC wrote:
 |
jsrfc58 wrote:
That is what I was wondering about...if you could create some type of "lookup table" where you would go directly from your incoming condition straight to a function (for instance) instead of testing against a large set of "if" statements individually (or something like that). You know, back in the olden days...they used to have this statement, ON-GOTO, where you could write ON x goto 100, 200, 300, 400...okay, I'll shut up now. |
Inheritance and Virtual Functions...
You know it makes sense.
