Re: More than one values returned?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Nobbe wrote:
> On Mon, Feb 18, 2008 at 9:06 PM, Nick Stinemates <nick@xxxxxxxxxxxxxx
> <mailto:nick@xxxxxxxxxxxxxx>> wrote:
>
>     Thats a good example, and a good reason for passing values by
>     Reference
>     instead of by Value.
>
>     I have found, however, that if I ever need to return /multiple/
>     values,
>     it's usually because of bad design and/or the lack of proper
>     encapsulation.
>
>
> and this is what i was responding to earlier, nick, although you didnt
> criticize
> pass-by-reference directly you essentially said use of it indicates
> bad design,
> which i disagree with.
> check my post where i show a method with a boolean return value that has a
> pass-by-reference parameter to return data; that is a perfectly
> reasonable use
> case for pass-by-reference and it does not indicate bad design.  nor
> would it, if
> there were more pass-by-reference parameters in that method.
If I said passing by reference was a bad design, C/C++ programmers all
over the world would call me an idiot. Coming from a C background, I
would definitely agree with them.
Passing by reference and returning an array of objects out of
convenience, I think, are completely separate.

As for that specific quote, I don't see how it criticizes by reference
arguments. If you took it that way, I can only assure you I will (try
to) speak more coherently ;)
>
> and here is another reason you might have to return more than on value
> from a
> method; a function needs to return data of different types.  now php
> is loosely
> typed, so packaging these into an array is a joke, but in other
> languages, that
> are strongly typed, its not quite that simple.  any way, when i think
> about a method
> returning  a class, what if for whatever reason, a method were to
> return objects of
> 2 classes ?  do you then create another class just for the purpose of
> packaging those
> 2 objects for this method to return a single value?
Of course, it _always_ depends. This is why in all of this argument i
said it was an *indication* not 100% of the time.

My only argument is, if you need 2 classes, or 2 sets of data, and
you'll need it in more than 1 place (ever) then it would be in your
interest to group them.

Let's take, for example, the getGroup method I've been using. If I make
a change to the update() method (in an extreme example, adding a
parameter to it that wasn't there before,) I am going to have to go back
through all of my code, and ensure it's being used properly. Instead, if
I had a Group object that managed bulk operations on Users, I would only
need to update 1 area, and the maintenance on the client code decreases
drastically.


> well ill let you be the judge of that, but i would probly toss them in
> a small array, or,
> depending on the scenario, use pass-by-reference, especially if i
> wanted to return
> a boolean value from the method ;)
>
> -nathan
If it calls for passing and object or 2 by reference, I think that's great.

-- 
==================
Nick Stinemates (nick@xxxxxxxxxxxxxx)
http://nick.stinemates.org

AIM: Nick Stinemates
MSN: nickstinemates@xxxxxxxxxxx
Yahoo: nickstinemates@xxxxxxxxx
==================

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux