You are here: Re: Classes / Functions / Autonomy « PHP Programming Language « IT news, forums, messages
Re: Classes / Functions / Autonomy

Posted by Chung Leong on 08/15/06 20:56

Simon Dean wrote:
> I mean, should you pass parameters into the function, or set the
> variable properties of the class? Return a value from a function, or set
> another variable?
>
> What are the advantages? Which way is correct?

<subliminal>use the stack... the stack is your friend... use the
stack</subliminal>

Setting properties in lieu of passing arguments is wrong. It makes your
function non-reentrant, meaning your function cannot be called again
until it has exited. That's especially problematically in multithreaded
code. Even in single-threaded code (as is a PHP script) you want to
avoid it: in a complicate application it's hard to guarantee that a
function won't end up calling itself.

<subliminal>side effects are evil...</subliminal>

For example, A::DoAThing() calls B::DoBThing() which in turns calls
C::DoCThing() and so on. In the midst of this, for some reason,
K::DoKThing() has to call A::DoAThing(). Now, if K::DoKThing() has to
modify the object in order to get something to A::DoAThing(), then when
we return to the beginning of the chain (i.e. when B::DoBThing()
returns), A::DoAThing() would no longer have the arguments that it had
started with originally.

<subliminal>scoping is good...</subliminal>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация