-
Notifications
You must be signed in to change notification settings - Fork 584
Document System.write/print(object) return value #1128
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
Conversation
Although `System.Write(object)` and `System.print(object)` both return their arguments, which is useful for method chaining etc., this isn't documented. The aim of this PR is therefore to remedy that.
Is there really a use of chaining with these methods, since it possibly produce surprising chain of methods? I mean outputting to stream should succeed or fail. In the fancier case, it should provide a fluent interface, not chain to the passed argument.
In addition, that behavior is not consistent with other printing/writing methods.
TBH, I didn't even realize these methods returned anything until I read something @munificent said in this old Hacker News item:
I have the opposite feeling (possibly because Wren doesn't have implicit returns). Since library calls are expressions, they may as well return something useful when possible.
For example IO.print() returns its argument. That's handy for debugging the result of an intermediate expression. Say you've got:
someMethod(anotherOne(arg))
And something weird is going on. Giving IO.print() a return value lets you inject it in the middle:
someMethod(IO.print(anotherOne(arg)))
without having to hoist the subexpression out.
So, the use case is perhaps method injection for debugging purposes rather than method chaining and that makes sense to me.
Although I have some sympathy with what you're saying - i certainly didn't expect these methods to return anything - the fact remains that this facility has been there for at least 8 years and, as people may be using it and there is an argument for doing so from Bob himself, we can't just remove it now.
Perhaps we should just leave it undocumented though I'll wait and see what @ruby0x1 thinks before withdrawing the PR.
Although
System.Write(object)
andSystem.print(object)
both return their arguments, which is useful for method chaining etc., this isn't documented. The aim of this PR is therefore to remedy that.