On Fri, May 20, 2011 at 7:58 PM, Michael Sokol <mikaa123 / gmail.com> wrote:
> My question is, what kind of mental model do you use when you program in
> Ruby? How do you think about objects? Do you see them as elements carrying
> with them their own methods, bundled with their data?

I don't think too much in that direction.  I start with thinking about
what main artifacts a program needs to have in terms of functionality.
 I try to do CRC - at least mentally.  After that is settled I think
about what public interface serves a class's purpose best (along the
lines of abstract data type).  Only then eventually (i.e. when coding)
I think about how these methods are implemented.  Of course, in
practice there can be more iterations of this and one class might
still be in the interface stage while another is implemented already.

http://en.wikipedia.org/wiki/Class-Responsibility-Collaboration_card
http://en.wikipedia.org/wiki/Abstract_data_type

> How about the flow of the program: Whenever there's a method call, do you
> picture the method to be inside the receiver - just like it would be in a
> real-life object -, or since you know that in the underlying implementation
> the method is stored in the class, you just think about a procedure call
> with a self variable being the receiver?

That's not a distinction I consciously make.   An object responds to a
message - whether that behavior is defined in its class or in the
instance itself doesn't really matter.

> Do you think using the OOP abstraction without knowing the internals can be
> harmful? My case for that (even if I tend not to believe so) would be that
> someone might be tempted to think that during an object instanciation, all
> the instance variables AND methods gets duplicated for this particular
> instance, which isn't the case - yet, that's what the abstraction pushes us
> to believe.

It's the other way round: worrying about internals too early is
harmful.  Whether that means thinking about how a class is implemented
or how the underlying object model works doesn't matter.  Both are
irrelevant most of the time when designing an application.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/