Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: rearrange class/id/name
artagesw wrote:
Just pass a single array param to all functions:
Never knew you could do that: way cool. Then is there any need for change?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Online
Re: rearrange class/id/name
There would be with the above. I was thinking, perhaps a compatibility plugin that has old function names and their relative reassignments? That way it can be used/disposed of when needed/not-needed.
Offline
Re: rearrange class/id/name
artagesw wrote:
Love Python, but no need to switch to achieve this. ;) Just pass a single array param to all functions:
myfunc(array('class'=>'myClass', 'id'=>'myiD', 'name'=>'myName'))
Can you point us to the relevant part of PHP documentation where this is explained, because as far as I know, that only works for the TXP taghandler functions if you call them directly from PHP code.
Offline
Re: rearrange class/id/name
I don’t mean to imply any magic here. The function definitions would all need to change and the function code would need to do an extract operation or access the parameter array manually to get at the args. This would be a major change, would break plugins, etc. But it would remove all parameter ordering issues going forward. I’m not advocating either way. Just throwing it out there that there is a way to (sort of) emulate named parameters in PHP.
Offline
Re: rearrange class/id/name
I think the array option is best. e.g., function myFunction(array) { extract(array); } would alleviate all ordering issues with the functions. And if you were to offer a compatibility plugin/file that assigned older functions to newer functions, it would be ideal.
Offline
Re: rearrange class/id/name
Please benchmark that array method extensively compared to the normal method of function calls.
Offline
Re: rearrange class/id/name
Benchmarks on my system. Tested calling a simple function that assigns all its arguments to local variables. Tested functions with 1, 2, 5, and 10 arguments. Each independent test consisted of 1,000,000 consecutive function calls. Results below. Short story, using arrays is between 2.5 and 3.5 times slower.
Passing Individual Parameters (1,000,000 iterations)| #Args | Total Time (seconds) | Calls per Sec. | Penalty |
|---|---|---|---|
| 1 | 0.0390 | 2,564,102 | n/a |
| 2 | 0.0628 | 1,592,356 | n/a |
| 5 | 0.1203 | 831,255 | n/a |
| 10 | 0.1314 | 761,035 | n/a |
| #Args | Total Time (seconds) | Calls per Sec. | Penalty |
|---|---|---|---|
| 1 | 0.1211 | 825,763 | 3.1x |
| 2 | 0.1711 | 584,453 | 2.7x |
| 5 | 0.2906 | 344,115 | 2.4x |
| 10 | 0.4491 | 222,667 | 3.4x |
Last edited by artagesw (2009-09-10 23:54:37)
Offline
Re: rearrange class/id/name
Has anyone tried to just add a bit of phpdoc to document the functions’ signatures plus a code-hinting IDE as the widely accepted option of perusing an API? IMHO, we are derailing into a prototypical bikeshed colour discussion here.
Offline
Re: rearrange class/id/name
artagesw wrote:
using arrays is between 2.5 and 3.5 times slower
Ouch! Not worth it then but thanks for testing it.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Online
Re: rearrange class/id/name
Actually, I don’t think there would be any significant performance impact. There would need to be tens of thousands of such calls per page before the difference would become noticeable, I would think.
Offline
Re: rearrange class/id/name
Why is this even being considered? It’s just plain ugly.
Offline
Re: rearrange class/id/name
ruud wrote:
Perhaps this calls for a more drastic change. Let’s drop PHP and switch to Python so we can use named parameters in function calls ;)
Offline
Re: rearrange class/id/name
Yeah, Python supports it natively. PHP does not. Let’s not pretend that it does.
PS. note the smiley on that original comment.
Last edited by ruud (2009-09-11 20:12:19)
Offline
Re: rearrange class/id/name
Yes, I know. Just pointing out that you were the one who opened the can of worms! ;) You also requested a benchmark, which I provided. So perhaps you have contributed to the perception that this is being actively considered. Personally, I think there are far more important things to spend our time on.
Offline
Re: rearrange class/id/name
If PHP had native support for named parameters in function calls, this may have been possible:
some_function('type', 'class', id='id')
That’s shorter and looks cleaner than this:
some_function(array('type' => 'type', 'class' => 'class', 'id' => 'id'))
Which is even longer than what we have now:
some_function('type', 'class', '', '', '', '', '', id)
Check the bottom of the can of worms. The “best before” date has expired. Let’s get rid of it or at least put the lid back on, because it’s getting smelly ;)
[and you’re right. I shouldn’t have asked for a benchmark and there are more important things]
Offline