• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Odd programming style

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
E.g.

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.

Regards,

Pho
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the last comment but if you really want to use an object use Integer
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rusty,

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.

e.g.



Imagine now if I follow my colleague's recommendation



I encapsulated the switch inside SomeObject.

Comments?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pho,

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?
 
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic