-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To "this" or not to "this"... #57
Comments
Apparently it seems to be a pattern in Go as well: In Java, this is used for the "Builder Pattern" as well so I think Java devs would actually be familiar with this. |
Incidentally we've got a somewhat similar question even in Python context. Yes, favouring the "Builder Pattern" is the reason for returning the same object, yet one can make a case for returning a new object of the same type instead. And in environments where programmers are excused from managing memory it works out just as well. Well, not really "as well," because it will be less efficient. After all, you'll "spew" a number of unreferenced objects in the process, which means that it will trigger garbage collector more often, or burden each invocation more. I for one would argue that it's formally inappropriate, and therefore would suggest those who ask to return new objects to "take one for the team." Because it would be a nightmare for the rest of us:-) However! One can also argue that it's not like the "Builder Pattern" is universally justified, and it would be appropriate to "void" selected methods.
But it really has more "academic" value than practical, doesn't it? As for other methods, I'd be reluctant. Yes, not even To summarize. Shall we limit ourselves to "void"-ing |
In essence it boils down to following simple rule. Whenever there is assignment, first method ought to be Just in case, the reason for why there is no |
Yeah, but basically builder instance is created in-place and doesn't leak from the minimal scope. It also usually has |
And thanks for considering this issue 👍 |
Quoting @Nashatyrev in #54.
The text was updated successfully, but these errors were encountered: