Skip to content
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

Document System.write/print(object) return value #1128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PureFox48
Copy link
Contributor

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.

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.
@mhermier
Copy link
Contributor

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.

@PureFox48
Copy link
Contributor Author

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.

@mhermier
Copy link
Contributor

mhermier commented Dec 26, 2022 via email

@PureFox48
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants