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

Odd programming style

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 782

My colleague commented that I have an odd programming style.
I was doing pass by reference to a method instead of returning the value directly.

He says I should just return the int and then the program would do whatever it wants. I prefer to return an object, then let the object have behaviour to react to the return value. What do you think? Bricks & bouquets welcomed.


Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
I am not sure what you mean. Everything is pass by value, not reference.

If the calling method only needs an int from another object, why not pass just that? It is not like any manipulations of the value outside the object that returned the int can affect the int inside the object. If you need the whole object, then go ahead. Perhaps I am misunderstanding you, but IMO, it comes down to the specific situation, like most things.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I agree with the last comment but if you really want to use an object use Integer
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 782


Thanks for the clarification on the pass by value concept.

To clarify what I want to do. I pass in the object and the method will set the int type via accessor methods. That int member is mutable. Then once the method returns, I call a method to tell the object to perform the necessary handling.


Imagine now if I follow my colleague's recommendation

I encapsulated the switch inside SomeObject.

Jim Toy

Joined: Oct 17, 2002
Posts: 14

Just to make sure I undertand what you are trying to do.

1) Create an object
2) Pass the newly created object to doSomething so that its values are set

3) Do the logic

I hope I am on the right track so far.

1) Does doSomething need to know things about SomeObject to do its job?
2) Does doSomething return a value that ONLY SomeObject could care about?
3) Are the operations in the switch statement only valid for SomeObject?
I agree. Here's the link:
subject: Odd programming style
It's not a secret anymore!