Why you think “attr helpers” are bad?
If they don’t exist I might have typo like:
class Cat
def size
@sizee
end
def size=(v)
@sise = v
end
end
Any good way to avoid typo (slient mistakes) without using “attr helpers”?
Why you think “attr helpers” are bad?
If they don’t exist I might have typo like:
class Cat
def size
@sizee
end
def size=(v)
@sise = v
end
end
Any good way to avoid typo (slient mistakes) without using “attr helpers”?
Attribute helpers don’t help avoid making typos. Typos can always happen.
Writing out methods for setting and getting makes your code very intent-clarifying which I find important.
The problem with attribute helpers is that I see many people add them in and not use them, or using them in places where private methods should be used. It would be better to use direct access to instance variables rather than create attr helpers for them - and I’ve seen too many people abuse this feature.
I like the helpers - I think people are more likely to make mistakes without them as there’s a lot more typing to do.
And you can make the attr_ private. That people don’t seems like more of social issue then a technical one.
Do you happen to be a Python developer?
Haha no
For example defining and calling static methods in classes:
Ruby 2.x
class RubyTwo
def self.some_static_method()
RubyTwo.call_some_static_method
end
end
Ruby 3.x
class RubyThree
def static.some_static_method()
static.call_some_static_method_of_the_same_class
end
end
and some more. In my opinion and on many new learners, it is confusing to use self for defining static methods, but calling dynamic methods with self as well.
Some Speed Improvements
Full Concurrency Power