Last active
January 1, 2016 18:19
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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