Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:43:45+00:00 2026-05-28T13:43:45+00:00

In the following code, is it really bad practice for updateWithContex to return the

  • 0

In the following code, is it really bad practice for updateWithContex to return the same object it took as a parameter?

class SomeClass{
   Foo updateWithContex(Foo foo){
       foo.setAppId(i);
       foo.setXId(index);
       //.....
       return foo;
   }
}

class Foo{

    public void setAppId(int appId)
    {
       //
    }
    public void setXId(int appId)
    {
        //
    }
    public void changeState(X x)
    {
       //
    }
}

In C++ , I have seen code like this:

 BigObject&
   fastTransform( BigObject& myBO )
   {
      // When entering fastTransform(), myBO is the same object as the function
      // argument provided by the user. -> No copy-constructor is executed.
      // Transform myBO in some way
      return myBO;   // Transformed myBO is returned to the user.
   }

Is this also wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:43:47+00:00Added an answer on May 28, 2026 at 1:43 pm

    Returning an object will suggest to users of your API that the passed in object will not be changed and a new modified object returned instead. To make it clear that this is not the case I would suggest changing the return type to void.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to accept bad server certificates: ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
The following code got me really puzzled. class class AVLTree { private: struct AVLNode
Is the following code bad practice? try //Try Overall Operation { try //Try section
I'm really stuck on why the following code block 1 result in output 1
Boy, this one is really weird. I expect the following code to print 1990,
Code that is untestable really annoys me. The following things make oo-code untestable: global
The following code illustrates an object literal being assigned, but with no semicolon afterwards:
this time, I'm facing a really weird problem. I've the following code: $xml =
first let me say I know the following code will be considered bad practices..
I am really bad explaining but I'll try. Suppose I have with the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.