[development] passing data is free
earnie at users.sourceforge.net
Tue Oct 9 12:26:08 UTC 2007
Quoting Earl Miles <merlin at 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
>> this excellent article which is so old that you need archive.org to
>> read it but is still valid.
>> For deeper understanding read
> 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/
More information about the development