IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Not sure i'd use a dictionary
I'm prone to believing that you shouldn't try to fight the capabilities of a language. I'd think that creating hashes on the fly would be somewhat expensive, though as you know, sending a ton of parameters over is also expensive.

You mention creating wrapper functions but does PHP support function overloading - i.e. the function is named the same but it has variants that take different types and numbers of parameters. If so, at least you avoid the problem of namespace pollution.

The other alternative is to use objects to encapsulate the logic - instead of the swiss army knife of dictionaries. Create a class that has all the various parameters sert to defaults. Set up some getter/setter functions to allow you to alter the defaults. Pass the object to the function. Or better yet, have the function be an encapsulated method of the object.
New That last suggestion...
Huge parameter lists are a good sign of an API gone bad. The functions are *too* versatile.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Problem with overloading
Say you have a function with three required parameters and three optional ones. You call it three times, each with a different one of the optional parameters. Each time you have four parameters, and positional doesn't work to identify the fourth.

I wrestled with the same thing as Wade, and came up with a hybrid: positional for the required parameters, and an array at the end for optinal ones.

eg:
function clsDB( $db_server, $db_name, $options ){\n    if( $options['debug_level'] > 0 ){\n        $debug_level = $options['debug_level'];\n    }\n    if( $options['test_mode'] > 0 ){\n        $test_mode = $options['debug_level'];\n    }\n    etc ...\n}

===

Implicitly condoning stupidity since 2001.
New To be honest, I don't know.
But it's unlikely that ad-hoc hashes are expensive in PHP. I believe this because lists and hash-tables are the same thing in PHP. If the types were separate, like they are in practically every other language, then, yes, I might agree with you.

PHP doesn't have function overloading. There is some experimental support for objects, but I've not used it and the documentation isn't clear.

Using an object would work for some of those functions. It's true I hadn't thought of that but I don't automatically think in objects. The downside is that it would make the calling code more verbose. This could probably be mitigated somewhat with some sub-classes and clever defaults, though.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Python cookbook example + discussion:
[link|http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68424|http://aspn.activest...thon/Recipe/68424]
"There's a set of rules that anything that was in the world when you were born is normal and natural. Anything invented between when you were 15 and 35 is new and revolutionary and exciting, and you'll probably get a career in it. Anything invented after you're 35 is against the natural order of things."

Douglas Adams
New Interesting. Some good ideas there.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

     Positional parameters vs. Named parameters. - (static) - (30)
         Is it possible to ... - (jbrabeck)
         Not sure i'd use a dictionary - (ChrisR) - (5)
             That last suggestion... - (admin)
             Problem with overloading - (drewk)
             To be honest, I don't know. - (static)
             Python cookbook example + discussion: - (FuManChu) - (1)
                 Interesting. Some good ideas there. -NT - (static)
         A technique - (tuberculosis) - (4)
             That's pretty much what I'm trying to do. - (static) - (3)
                 Best Advice: Be merciless in your refactoring. - (tuberculosis) - (2)
                     Re: Best Advice: Be merciless in your refactoring. - (deSitter) - (1)
                         Its like cleaning house - (tuberculosis)
         May be you have a class trying to get born - (Arkadiy)
         Can't say without code - (JayMehaffey) - (2)
             Define 'better' :-) [+ some examples] - (static) - (1)
                 Re: Define 'better' :-) [+ some examples] - (JayMehaffey)
         another solution - (tablizer) - (11)
             No, it's not. - (static) - (10)
                 That is more syntax - (tablizer) - (9)
                     OT: Bryce... - (folkert) - (1)
                         OT: I don't have access to receipt. On biz travel - (tablizer)
                     Also more limited - (JimWeirich) - (6)
                         There be XML -NT - (Arkadiy) - (1)
                             but XML "solves" the problem by not having variables -NT - (tablizer)
                         minor issues IMO - (tablizer) - (3)
                             I should have known. - (static)
                             Re: minor issues IMO - (JimWeirich) - (1)
                                 difference in style - (tablizer)
         I generally lean towards the hash solution - (ben_tilly) - (1)
             That's a good idea. - (static)

Unless I missed it, I don't think that they had Barbie in mind as one of the 4 horsemen.
197 ms