You are here: Re: which language allows you to change an argument's value? « PHP Programming Language « IT news, forums, messages
Re: which language allows you to change an argument's value?

Posted by Daniel Pitts on 09/30/07 17:12

On Sep 30, 3:47 am, Summercool <Summercooln...@gmail.com> wrote:
> I wonder which language allows you to change an argument's value?
> like:
>
> foo(&a) {
> a = 3
>
> }
>
> n = 1
> print n
>
> foo(n) # passing in n, not &n
> print n
>
> and now n will be 3. I think C++ and PHP can let you do that, using
> their reference (alias) mechanism. And C, Python, and Ruby probably
> won't let you do that. What about Java and Perl?
>
> is there any way to prevent a function from changing the argument's
> value?
>
> isn't "what i pass in, the function can modify it" not a desireable
> behavior if i am NOT passing in the address of my argument? For one
> thing, if we use a module, and call some functions in that module, and
> the module's author made some changes to his code, then we have no way
> of knowing what we pass in could get changed. Of course, if it is in
> Java, Python, and Ruby, and we pass in a reference to object (not C+
> +'s meaning of alias reference), so the object can get changed, but
> that can be expected, vs passing in n, when n = 1. Even when it is
> Ruby, when everything is an object, passing n in when n = 1 won't ever
> make n become 3. Is there a way to prevent it from happening in the
> languages that allows it?

Some would say that in truely good OO design, the state should be
protected by the object (not the constness of the reference to the
object)

 

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

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