passing data is free
To quote one of the most experienced Drupal developer: "The menu item array includes a copy of the whole node for example on node pages. Well, obviously that might be useful for some help stuff, but most of the time it is not required, so why pass on this data in all cases?" Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want. Not for the first time I urge fellow developers to read http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-coun... this excellent article which is so old that you need archive.org to read it but is still valid. For deeper understanding read http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/pro...
Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want.
How much difference is there in this between PHP4 and PHP5?
On Monday 08 October 2007, Sean Robertson wrote:
Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want.
How much difference is there in this between PHP4 and PHP5?
This much: http://www.php.net/manual/en/migration5.php The change in the way objects are passed is the only BC break that is not trivial to handle if you take care to do so, and Drupal has taken very good care to do so. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
Karoly Negyesi wrote:
To quote one of the most experienced Drupal developer:
"The menu item array includes a copy of the whole node for example on node pages. Well, obviously that might be useful for some help stuff, but most of the time it is not required, so why pass on this data in all cases?"
Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want.
Not for the first time I urge fellow developers to read http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-coun... this excellent article which is so old that you need archive.org to read it but is still valid.
For deeper understanding read http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/pro...
More importantly, this is one of the biggest reasons that people might choose an OO paradigm over a procedural paradigm. With an object oriented model, data tends to stick together; in the procedural model, you get issues like this one, where you find yourself passing data you may or may not need.
Earl Miles wrote:
Karoly Negyesi wrote:
Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want. More importantly, this is one of the biggest reasons that people might choose an OO paradigm over a procedural paradigm. With an object oriented model, data tends to stick together; in the procedural model, you get issues like this one, where you find yourself passing data you may or may not need. I have no desire to start up the OO debate. So I'll make one statement then stop.
With an OO language, data might be passed around, it is just handled by the language. For example, in many (some/all?) C++ compilers, it is the first argument on the stack, and the compiler/language simply handles dereferencing it. You can simulate some aspects of OO code without an OO language. What you can't easily do is overloading. But data encapsulation and function naming can be handled with good programming and naming conventions. I said I wouldn't start up the debate, so I'll leave it there. BTW, I probably started using C++ within 1-2 years of it's release, so I like OO languages, and have some experience with them. -- Doug Green douggreen@douggreenconsulting.com 904-583-3342 Bringing Ideas to Life with Software Artistry and Invention...
Quoting Earl Miles <merlin@logrus.com>:
Karoly Negyesi wrote:
To quote one of the most experienced Drupal developer:
"The menu item array includes a copy of the whole node for example on node pages. Well, obviously that might be useful for some help stuff, but most of the time it is not required, so why pass on this data in all cases?"
Why not? Passing data around is basically free. You are not copying the data, you are creating a reference, deep copy only happens if you modify the passed in argument (PHP5 only deep copies an object if you instruct it with clone()). So do not hesitate to pass around as many data as you want.
Not for the first time I urge fellow developers to read http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-coun... this excellent article which is so old that you need archive.org to read it but is still valid.
For deeper understanding read http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/pro...
More importantly, this is one of the biggest reasons that people might choose an OO paradigm over a procedural paradigm. With an object oriented model, data tends to stick together; in the procedural model, you get issues like this one, where you find yourself passing data you may or may not need.
I think Karoly's point is that with improvements of PHP 5 we can count on the data stack only being copied if there is a change to the data. This has nothing to do with OO vs procedural. It has to do with the operation of the script engine upon the data structures and the passing of the data to the functions, be it in OO or procedural. Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
I think Karoly's point is that with improvements of PHP 5 we can count on the data stack only being copied if there is a change to the data.
I think you have not read my letter or any of the articles I linked to and even failed to check their date, the Zend article is from 2000. That's PHP 4 you wanted to say not PHP 5.
participants (6)
-
Doug Green -
Earl Miles -
Earnie Boyd -
Karoly Negyesi -
Larry Garfield -
Sean Robertson