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

Fix statement about evaluation strategy of methods #1425

Merged
merged 2 commits into from
Jul 12, 2016

Conversation

rstammer
Copy link
Contributor

@rstammer rstammer commented Jul 11, 2016

After investigating this question, I'm convinced that Ruby does not use call-by-reference, as stated in the section "To Ruby From C and C++" . It is using call-by-value as evaluation strategy for methods in canonical terminology.

See this blogpost or this stackoverflow discussion for deeper discussions on that question.

Obviously this information causes some confusion. For example, the wikipedia article on evaluation strategies referenced the ruby-lang documentation as a proof that Ruby does use call-by-reference:

whereas in the Ruby community, they say that Ruby is call-by-reference

That's why I'd suggest changing the information contained on the mentioned section.

Translations

I added the fix for German and English version, but since I'm not able to serve verified suggestions for the other languages, maybe the lang maintainers could assist?

Edit (stomar): relevant commits are bcb8d63 and e641ece.

Thanks!

@stomar
Copy link
Contributor

stomar commented Jul 11, 2016

Note that the cited blog post has syntactically wrong code examples, which does not inspire confidence...

Can someone provide a more "official" view point (ruby core)?

@rstammer
Copy link
Contributor Author

rstammer commented Jul 11, 2016

Maybe this answer of the mentioned stackoverflow discussion does contribute to the trustworthiness, because it quotes the O'Reilly book "The Ruby Programming Language".

@stomar
Copy link
Contributor

stomar commented Jul 12, 2016

Great, that's exactly the kind of reference I had in mind :)

Here the quote from Flanagan/Matsumoto as given on stackoverflow:

[from 3.8.1: Object References]

When you pass an object to a method in Ruby, it is an object reference that is passed to the method. It is not the object itself, and it is not a reference to the reference to the object. Another way to say this is that method arguments are passed by value rather than by reference, but that the values passed are object references.

Because object references are passed to methods, methods can use those references to modify the underlying object. These modifications are then visible when the method returns.

@@ -81,8 +81,8 @@ Unlike C, in Ruby,...
* There’s no `#define`. Just use constants instead.
* All variables live on the heap. Further, you don’t need to free them
yourself—the garbage collector takes care of that.
* Arguments to methods (i.e. functions) are passed by reference, not by
value.
* Arguments to methods (i.e. functions) are passed by value, whereas the
Copy link
Contributor

@stomar stomar Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whereas -> where

@stomar
Copy link
Contributor

stomar commented Jul 12, 2016

@neumanrq wrote

Obviously this information causes some confusion. For example, the wikipedia article on evaluation strategies referenced the ruby-lang documentation as a proof that Ruby does use call-by-reference

I think you misunderstood the Wikipedia article. It clearly states that Ruby does not use "call by reference" but what they term "call by sharing" (i.e. call by value where the value is a reference); the paragraph you have cited only makes a statement about the used terminology:

However, the term "call by sharing" is not in common use; the terminology is inconsistent across different sources. For example, in the Java community, they say that Java is call by value, whereas in the Ruby community, they say that Ruby is call-by-reference, even though the two languages exhibit the same semantics.

I have no idea what the predominantly used terminology in the community is, though.

@rstammer
Copy link
Contributor Author

rstammer commented Jul 12, 2016

I think you misunderstood the Wikipedia article. It clearly states that Ruby does not use "call by reference" but what they term "call by sharing" (i.e. call by value where the value is a reference); the paragraph you have cited only makes a statement about the used terminology:

Oh, yes, you're right, my bad. I fully agree to the wikipedia article argumentation on call-by-sharing and the article points that out correct.

But the issue here remains: I still disagree to the statement

whereas in the Ruby community, they say that Ruby is call-by-reference

This statement was underlined by quoting ruby-lang documentation. That was the reason to make this proposal.

I fixed the wording due to your suggestion.

@stomar stomar merged commit bcb8d63 into ruby:master Jul 12, 2016
@rstammer rstammer deleted the fix/hint_on_evaluation_strategy branch July 12, 2016 12:56
@stomar stomar changed the title Fix hint on evaluation strategy of methods Fix statement about evaluation strategy of methods Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants