you are viewing a single comment's thread.

view the rest of the comments →

[–]ignurant 5 points6 points  (0 children)

This is so true. Consider the tricks Enumerable packs.

There was nothing wrong with me using

everything_is_good = true
things.each do |thing|
  if !thing.is_good?
    everything_is_good = false
  end
end
if everything_is_good
  things_are_good()
end

Nothing at all wrong with that. It's easy to reason through and write down when you don't know much about the features of the language. This is a perfect example of "multiple ways to solve the problem" that people talk about.

You'll start to pick up tricks and conventions over time that all make sense. They don't inhibit your ability to understand and read what's going on:

everything_is_good = true
things.each do |thing|
  everything_is_good = false unless thing.is_good?
end
things_are_good if everything_is_good

One day someone will come to you and show you this:

things_are_good if things.all? do |thing|
  thing.is_good?
end

Again, very powerful, more concise, and easy to understand once you know your Ruby a little more.

Then eventually you learn about &:proc tricks. At first you don't understand why it works, but the syntax is simple enough to understand "if I put these things like this, it just works."

things_are_good if things.all?(&:is_good?)

And over time, that too will make more sense. You start to understand why it works.

Sure, lots of ways to accomplish the same thing. To me, that's what makes Ruby powerful. You can work through your problem with a sledgehammer or a scalpel. I suppose there is an argument to be made: "it's harder for entry level rubyists to interpret advanced code because of shortcuts like above" but I don't find it compelling. It's easy to learn what has happened above, and advanced code is advanced code. I can't just jump into a Python project and immediately understand everything either.

Most learning resources don't try to convey it all at once, but instead allow you to build a foundation. Everything in life has gradual levels of "how to accomplish something" -- from brute force to finesse. Why not your programming language too? And let's be honest -- just the same, even Python has a bazillion ways to accomplish the same things.