-
Notifications
You must be signed in to change notification settings - Fork 218
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
Suggests reduce vs inject, but they're the same method #37
Comments
I think it was @rafaelsales who did this. Both are not combining the elements? This part here? http://best-ruby.com/idiomatic_ruby/combine_elements_in_collection.html |
It's very unclear in the example that |
It's unclear just as in ruby documentation: http://ruby-doc.org/core-2.2.3/Enumerable.html Both words also has 6 letters. Why? Have you seen the examples? Why? Because the different names help understand the intention of the code. |
Idiomatic ruby doesn't necessarily mean semantic or good practice. I guess this book should figure out which it cares more about: Idiomatic or semantic. |
The language makes available both reduce and inject words and clearly states different examples for each of them. |
Are we looking at different examples? They look the same to me. |
They are not. Compare the examples in the book with the examples in ruby doc. Basically you won't find the use of |
Oh, you're comparing the Best Ruby book vs the Documenation. Yes, of course, that's my point. Best Ruby suggests there's a difference implicitly where as there is zero difference in the documentation. |
@krainboltgreene I think I got your point. You are saying we are not making the BEST or at least a better idiomatic approach, we are just saying inject and reduce can do the same thing. |
Another point of view can be: How can I combine two elements? I can use inject and reduce and those are idiomatic ruby codes. I think, at the beginning this was the point and right now I think you are asking us what is the BEST or even the most idiomatic ruby code. I don't know the answer, what do you think? Probably we should define what is idiomatic ruby. I can combine two or more elements in collections using a non-idiomatic ruby code, but If I use inject OR reduce, I will use an idiomatic ruby code. |
In this section: "idiomatic ruby code", we should create a sort of idiomatic ruby code, it means: I can do this thing using a non-idiomatic ruby code, BUT I can also use some approaches in the language and that will look more idiomatic ruby, but it does not mean this is the best approach OR this is the BEST idiomatic ruby code. What do you guys think? |
@krainboltgreene Why the documentation uses |
Largely because documentation is boring and cruby core documentation has a huge amount of hoops to jump through, so Copy/Paste becomes the most efficient solution.
Because it probably appeared obvious to the writer.
Probably the same reason we have For what it's worth I would just talk about |
The chapter on combining objects suggests that reduce and inject are different methods for different tasks.
The text was updated successfully, but these errors were encountered: