File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes programming practise Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "programming practise" Watch "programming practise" New topic
Author

programming practise

shruti dighe
Greenhorn

Joined: Jan 22, 2013
Posts: 3
is allowing function to change parameters a good programming practise ? Please help me out
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Welcome to the Ranch.

I think most people find it bad practice to change the value of a parameter inside a method. That's because it makes it more difficult to understand the code in the method. Programmers generally expect that the parameter variables that are passed to the method, contain the values that we passed to the method when it was called. If, somewhere inside a method, you change the value, then it makes it harder to follow what value exactly the parameter variable has at any point in the method, making the code hard to follow.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
shruti dighe
Greenhorn

Joined: Jan 22, 2013
Posts: 3
Jesper de Jong .. Please help me select the right answer for this question

Q: Which of the following is a good programming practise
1: Declare all variables globally
2: provide comments to each statement of the program
3: function modifies its parameters
4: none of these

options 1 and 2 definitely not correct.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

shruti dighe wrote:Jesper de Jong .. Please help me select the right answer for this question

This looks like a homework question to me, and here we like you to DoYourOwnHomework (←click).

My suggestion: Post what you think the answer is, AND your reasons for choosing it. Then we might be able to help you.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
shruti dighe
Greenhorn

Joined: Jan 22, 2013
Posts: 3
function are written to perform some task .. it is obvious they will change the parameters when it comes to calculations performed inside that function. How can it be a bad programming practise then ?
in that case then all variables in java would have been declared final . and the "printstacktrace" method can always give the stack condition in case of exception..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Shruti

Parameter variables are used to hold the value passed from the calling function. Considering your question about calculated results, you can always have method local variables that holds the calculated results. Correct me if I am wrong.


Swastik
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

shruti dighe, please BeForthrightWhenCrossPostingToOtherSites <- click
http://www.java-forums.org/new-java/67999-good-programming-practise.html


luck, db
There are no new questions, but there may be new answers.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

shruti dighe wrote:function are written to perform some task .. it is obvious they will change the parameters when it comes to calculations performed inside that function...

It is? Then why does Java allow you to put the qualifier final on a parameter? I think you're confusing using values to perform a calculation, which may indeed produce a different value, and changing those values.

And you still haven't answered the question: What do you think the answer is, and why?

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: programming practise