Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2009-09-10 14:35:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: rearrange class/id/name

redbot wrote:

Don’t know if this will bloat the code too much

Yes it might, though if this idea does take off, it’ll only be temporary(ish) for a year or three until the old functions can be phased out! Plus I spose it’s not for all functions, only those where the useful options have been tacked on at the end.

Last edited by Bloke (2009-09-10 14:38:12)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#14 2009-09-10 16:11:34

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

Re: rearrange class/id/name

Throw a deprecated warning from the very start, so people are immediately urged to upgrade stuff.
Keeping both functions for 3 years is way too long. One or 2 releases should be enough (assuming 2 releases per year).

Or… introduce the new function at the end of a minor release series (4.2.9 or so) and remove the old function when moving to the next major release.

Offline

#15 2009-09-10 17:19:42

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 ;)

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'))

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
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.

Txp Builders – finely-crafted code, design and Txp

Offline

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

TheEric
Plugin Author
From: Wyoming
Registered: 2004-09-17
Posts: 566

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: Wyoming
Registered: 2004-09-17
Posts: 566

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: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website 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: 11,454
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.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB