3 ms·
Well, as you say, you work on a large Ruby codebase, so I apologize if the following comes off as condescending. I don't follow this first bit, though. You sa
by jfarmer 13y ago
Well, as you say, you work on a large Ruby codebase, so I apologize if the following comes off as condescending. I don't follow this first bit, though.
You say, "Ruby's allowing you to elide parentheses means you can't assume that a property is a property or a function."
There's no such "thing" as a property in Ruby, yeah? Everything+ is an object and objects respond to methods. IMO this is one of the places where Ruby is not being magical. attr_reader and friends are built on top of this to give programmer's a convenient shorthand way of defining boilerplate getters and setters when you need them.
In this regard Ruby is more homoiconic. "getters" and "setters" are just plain ol' methods!
It'd be much more confusing, IMO, if there were now two types of "things" that could be attached to an object: methods and properties/attributes. You'd have to develop a separate convention, syntactic or otherwise, for information hiding, e.g., how would private properties work? You're now in a funny situation where one kind of variable (instance variables) might differ from other kinds of variables in a dimension other than scope.
Python's answer is "neither properties nor methods are ever really private" which is internally consistent but very un-Ruby.
+: I know this isn't literally true. Methods aren't objects, for example, and there are plenty of keywords like case, when, if, etc. which are neither methods nor objects but units of pure syntax.