News for hackers. Stuff that matters.
Re:Ruby is beautiful (but I'm moving to Python) by axod on Sunday November 28, 2010 @05:13PM (#1948500)
I haven't studied OOP extensively in a strict setting, but I would have said that in the OO world, a property is completely separate to a method.

For example,

  class flower
  property color
  property numberOfPetals
  method pluckPetal()
  method water()
A property defines data about an object, and a method defines something you can 'do' with the object.

Could you give some pointers to the OOP principle that blurs the line between these two?

Re:Ruby is beautiful (but I'm moving to Python) by adambyrtek on Sunday November 28, 2010 @05:54PM (#1948623)
It's called the Uniform Access Principle, as I've already mentioned in a separate comment. Getting back to your example, it is not very useful without mentioning a language under examination. There is no single definition of OOP, and every language implements in a slightly different way.

There are languages where UAP is enforced by the syntax (eg. Eiffel, Smalltalk, Ruby) and languages where it's a matter of convention. But even in the latter it's considered a good practice to keep properties private and encapsulate them with accessors. Some even have dedicated features that help with that (auto-properties in C#, properties in Python).

Re:Ruby is beautiful (but I'm moving to Python) by masklinn on Monday November 29, 2010 @02:31AM (#1949693)
> I haven't studied OOP extensively in a strict setting, but I would have said that in the OO world, a property is completely separate to a method.

There is absolutely no reason for that, and the grandparent of all things object-oriented (Smalltalk) very strongly disagrees with you: everything is a message, and there are no properties.

> A property defines data about an object, and a method defines something you can 'do' with the object.

A getter method is a property and a method. Properties are irrelevant, access should be uniform, the implementation details of an object (whether a "property" provides direct access to internal data or not) is of no concern to the user of the object.

A property is nothing more than a method whose contract is "give me some data"

Re:Ruby is beautiful (but I'm moving to Python) by axod on Monday November 29, 2010 @04:27AM (#1949841)
That's a fine answer, and some people may find that a helpful way to organize programs.

However, for me, and the CPU, we treat code execution differently to data access.

Re:Ruby is beautiful (but I'm moving to Python) by philwelch on Monday November 29, 2010 @01:03PM (#1951128)
There's OOP qua Smalltalk/Kay, and then there's OOP qua Java. You're describing OOP qua Java, which is an ugly type of OOP designed for certain performance advantages.
Re:Ruby is beautiful (but I'm moving to Python) by axod on Monday November 29, 2010 @02:29PM (#1951457)
Don't be ridiculous.

1. It's not ugly

2. It's how CPUs work

3. It's how most people think

Re:Ruby is beautiful (but I'm moving to Python) by philwelch on Monday November 29, 2010 @03:02PM (#1951579)
1. By ugly, I mean less mathematically elegant. In Ruby, you say "paul.foo" and get foo from Paul. How Paul gets foo for you is up to Paul. Simple.

2. If you want a programming language that maps closely to how CPU's work, Ruby's definitely not for you. Assembly and C are for you.

3. I can't speak for most people. What I can say is that I can think in C and I can think in Ruby, and it doesn't seem difficult for me.