users
[Top] [All Lists]

RE: [cinjug-users] IDE Warning - Parameter value should not be assigned

To: <users@xxxxxxxxxx>
Subject: RE: [cinjug-users] IDE Warning - Parameter value should not be assigned
From: "Forsythe, Brian" <Brian.Forsythe@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Aug 2006 13:16:39 -0400
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <6a216ba20608020750v496e606eh72da2bd5deb9f907@mail.gmail.com>
Thread-index: Aca2Q05HOpRy0CIoSumVrizFJ00mSQAFBxmL
Thread-topic: [cinjug-users] IDE Warning - Parameter value should not be assigned
I'd argue that the first and foremost reason for not re-assigning parameter 
values is because it's ambiguous and misleading, not because of side-effects.  
If you've an operation that accepts something as a parameter and then needs to 
modify that value, you probably haven't thought it through.  Of course, there 
are some obvious utility-type operations which are exceptions (something that 
updates values in a Collection, frex).
 
Regards,
BRiaN

________________________________

From: Edward Sumerfield [mailto:esumerfd@xxxxxxxxx]
Sent: Wed 8/2/2006 10:50 AM
To: users@xxxxxxxxxx
Subject: [cinjug-users] IDE Warning - Parameter value should not be assigned


Is the warning "The parameter value should not be assigned" still valid in Java?

    public void getFoo(int a_value, Object a_object)
    {
        a_value += 1;                     // WARNING
        a_object = new Object();     // WARNING 
    }

It has always been good programming practice to avoid assigning parameters 
because in C/C++ you might be setting a pointer that the caller would not know 
had changed.

In java it is not possible set the object references that are passed in and the 
primitive types are passed by value so what is the danger? 

I propose that the old bad practive rule be revoked in the light of better 
languages?

-- 
Ed


<Prev in Thread] Current Thread [Next in Thread>