Skip to content

Instantly share code, notes, and snippets.

@robertpateii
Last active January 1, 2016 18:19
Show Gist options
  • Save robertpateii/8182958 to your computer and use it in GitHub Desktop.
Save robertpateii/8182958 to your computer and use it in GitHub Desktop.
When passing an object into a function, should the function bother returning a value or just update the object by reference?
// Populates with some data from the API.
ProductInfo productInfo = parseApiReply(apiResponse);
// Need to update some empty fields after doing some logic on the data from the API.
// I've been following the general guideline of always return a value so I write this:
productInfo = addUserInfo(productInfo, userID);
// But is it pointless to set visitorSerialInfo there since we can update it by reference in?
// I could just do this:
addUserInfo(productInfo, userID);
// Which is best in this case, and why?
// Of course, I could create two more objects and combine them,
// but that seems like overkill. addUserInfo will just be 6 lines
// or so and will update only 3 fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment