Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2009-09-10 17:57:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

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

Offline

#17 2009-09-10 18:10:23

TheEric
Plugin Author
From: Colorado & Montana.
Registered: 2004-09-17
Posts: 604
Website

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

#18 2009-09-10 19:12:45

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#19 2009-09-10 19:29:42

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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

#20 2009-09-10 21:02:44

TheEric
Plugin Author
From: Colorado & Montana.
Registered: 2004-09-17
Posts: 604
Website

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

#21 2009-09-10 21:28:33

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: rearrange class/id/name

Please benchmark that array method extensively compared to the normal method of function calls.

Offline

#22 2009-09-10 23:53:41

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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
Passing Array of Named Parameters (1,000,000 iterations)
#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

#23 2009-09-11 04:56:04

wet
Developer Emeritus
From: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,416
Website GitHub Mastodon

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

#24 2009-09-11 09:28:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,446
Website GitHub

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

Offline

#25 2009-09-11 18:14:02

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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

#26 2009-09-11 18:40:38

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: rearrange class/id/name

Why is this even being considered? It’s just plain ugly.

Offline

#27 2009-09-11 18:59:07

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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

#28 2009-09-11 19:12:21

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#29 2009-09-11 20:09:51

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

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

#30 2009-09-11 20:18:10

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

Board footer

Powered by FluxBB