Forum: Ruby OO style tutorials?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
75af7ee3bb02d7280a51e50e25d5e8a1?d=identicon&s=25 Paul Archer (Guest)
on 2009-03-08 06:50
(Received via mailing list)
I'm pretty new to Ruby, and while I've read (and mostly get) several
books
on Ruby, I'm having trouble with one thing: Object Oriented programming.
Don't get me wrong, I get the concepts of OO. I can construct objects
and
classes. The mechanics of it don't phase me.

I'm good with the how, I'm just a little fuzzy on the how much. To put
it
in more concrete terms: I'm writing (or, rather, I want to write) a
script
that takes incoming digital images from my camera and renames them and
puts them in a directory structure based on their date. Now, I have a
background in scripting (Bourne shell and Perl), and can see doing this
in
a purely procedural way. But I'm not sure about how to do it in an OO
way.
Do I represent each image as an object? What attributes should the
objects
have?

So the question is: Are there any tutorials or resources that go more
into
the appropriate use of OO programming, strategies for structuring
classes,
rather than the nuts and bolts of creating objects and such?

Paul Archer
0814ff69e309b033508b3c7f363236fd?d=identicon&s=25 Ian Trudel (backorder)
on 2009-03-08 08:06
Paul Archer wrote:
> I'm pretty new to Ruby, and while I've read (and mostly get) several
> books
> on Ruby, I'm having trouble with one thing: Object Oriented programming.
> Don't get me wrong, I get the concepts of OO. I can construct objects
> and
> classes. The mechanics of it don't phase me.

> So the question is: Are there any tutorials or resources that go more
> into
> the appropriate use of OO programming, strategies for structuring
> classes,
> rather than the nuts and bolts of creating objects and such?
>
> Paul Archer

Hello Paul,

Your problem seems to be obvious. It is hardly possible to grasp such
concepts without proper training. Your project feels like a good way to
get going. Why don't you just dig in by yourself and come back with more
questions? Experiment by yourself. Truthfully, if you have read several
books already, the last thing you need is yet-another-something-to-read.

Ah. The heck. Have you read yet http://www.ruby-doc.org/ ? Click on the
link "An on-line copy of the first edition of the book Programming Ruby,
by Dave Thomas."; it's a good starter.

Regards,
Ian.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-03-08 08:36
(Received via mailing list)
Paul Archer wrote:

> I'm pretty new to Ruby, and while I've read (and mostly get) several books
> on Ruby, I'm having trouble with one thing: Object Oriented programming.
> Don't get me wrong, I get the concepts of OO. I can construct objects and
> classes. The mechanics of it don't phase me.

That is "object based" programming. OO is about virtual dispatch of
methods at
object boundaries.

> I'm good with the how, I'm just a little fuzzy on the how much. To put it
> in more concrete terms: I'm writing (or, rather, I want to write) a script
> that takes incoming digital images from my camera and renames them and
> puts them in a directory structure based on their date. Now, I have a
> background in scripting (Bourne shell and Perl), and can see doing this in
> a purely procedural way. But I'm not sure about how to do it in an OO way.
> Do I represent each image as an object? What attributes should the objects
> have?

Read the books /Test-Driven Development/, /Refactoring/, and /Design
Patterns/.

Then write whatever works. When you refactor it, try to DRY the code up
-
meaning Don't Repeat Yourself.

The fewer lines of code your program has, the more likely your objects
have
merged their common behaviors into base classes, and their specific
behaviors
into derived classes.

The second link on my website, TDD, shows a long list of my various
tutorials on
OO design and implementation. I generally try to show the thought
process that
leads to emergent designs.
5bb6fed57d7460fbfc81f72b9586c3ba?d=identicon&s=25 Yun Huang Yong (Guest)
on 2009-03-08 10:30
(Received via mailing list)
At 04:48 PM 8/03/2009, Paul Archer wrote:
>So the question is: Are there any tutorials or resources that go
>more into the appropriate use of OO programming, strategies for
>structuring classes, rather than the nuts and bolts of creating
>objects and such?

My first encounter with OO programming was with Java, and I found the
Sun Java tutorial quite handy for explaining the basic ideas:
http://java.sun.com/docs/books/tutorial/java/conce...

I should also declare that I'm a pretty lousy programmer, and
throughout Uni I had difficulty understanding the need for UML[1],
CRC[2], Design Patterns and various other OO design jargon.  But
after 8 odd years working in the commercial world they began to find
their place in my world.  The understanding I came to is that there
isn't a perfect tutorial for everyone because it depends a lot on
your experience.  Stuff that made no sense to me 8 years ago (and
indeed seemed overwhelmingly complicated) makes perfect sense today.

That said I quite like CRC as a simple tool to help you think along
the right lines.

I suspect beyond that you probably want a good UML or Design Patterns
book.  I don't have any recommendations but hopefully someone else on
this thread will. :)

yun

[1] http://en.wikipedia.org/wiki/Unified_Modeling_Language
[2] http://www.agilemodeling.com/artifacts/crcModel.htm
312bab66708aab09c40c8a4176211e5b?d=identicon&s=25 Udayanga Wickramasinghe (usw)
on 2009-03-08 12:48
(Received via mailing list)
Hi Paul,
I too agree with Ian. Obvious reason might be lack of experience in
these OO
design concepts . OO is not about creating classes and objects but how
you
apply it in real world scenarios efficiently. In my personal opinion i
do
not  recommend you to use a Ruby Language book  as a gateway for
grasping OO
,coz  it might be  more concentrating on Ruby rather than OO. I prefer ,
you
use a good introductory book  such as 'Head First Object-Oriented
Analysis
and Design' which would give you a great understanding to polish off
your OO
concepts..

Regards
Udayanga
621080472679266b8e9b81aff4800398?d=identicon&s=25 Saji N. Hameed (Guest)
on 2009-03-08 14:02
(Received via mailing list)
* Paul Archer <paul@paularcher.org> [2009-03-08 14:48:36 +0900]:

> So the question is: Are there any tutorials or resources that go more
> into the appropriate use of OO programming, strategies for structuring
> classes, rather than the nuts and bolts of creating objects and such?
>

Design Patterns in Ruby by Russ Olsen is what I would recommend reading

http://www.amazon.com/Design-Patterns-Ruby-Addison...

saji
--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705      saji@apcc21.net
KOREA
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-03-08 14:35
(Received via mailing list)
On 08.03.2009 10:28, Yun Huang Yong wrote:
> I should also declare that I'm a pretty lousy programmer, and
> throughout Uni I had difficulty understanding the need for UML[1],
> CRC[2], Design Patterns and various other OO design jargon.  But
> after 8 odd years working in the commercial world they began to find
> their place in my world.  The understanding I came to is that there
> isn't a perfect tutorial for everyone because it depends a lot on
> your experience.  Stuff that made no sense to me 8 years ago (and
> indeed seemed overwhelmingly complicated) makes perfect sense today.

Took me some time, too.  My first OO program was horrible and I believe
it took at least a year until I managed to grasp it - at least half way.

> That said I quite like CRC as a simple tool to help you think along
> the right lines.

I also believe that CRC is a good tool because it is quite simple and
keeps you focused on important points.  I'd say though that it still
takes a bit more to craft a good OO application.  But CRC is very useful
as it will also help to not lump too much functionality into a single
class.

> I suspect beyond that you probably want a good UML or Design Patterns
> book.  I don't have any recommendations but hopefully someone else on
> this thread will. :)

I always recommend "Object Oriented Software Construction" by Bertrand
Meyer.  It is not exactly a tutorial but rather an encyclopedia where
you can look up whatever OO term you encounter somewhere else.  Meyer
really has a profound understanding of all the different aspects of OO
and ways in which it can be used.

http://archive.eiffel.com/doc/oosc/page.html

Kind regards

  robert
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-03-08 15:35
(Received via mailing list)
On Sun, Mar 8, 2009 at 8:00 AM, Saji N. Hameed <saji@apcc21.net> wrote:

> http://www.amazon.com/Design-Patterns-Ruby-Addison...
>
>
I'll give that a hearty second. Russ does a very good job of teaching OO
design from a Ruby perspective.


I strongly believe that although there might be a few universal truths,
most
good OO design needs to take the characteristics of the language into
account.  If you learn OO from a Java tutorial, you're going to speak
Ruby
with a Java accent.  Object Oriented Software Construction will leave
you
with an Eiffel accent.  The Gang of Four Design Patterns book, although
it
purports to be "language neutral" at least for the popular OO languages
back
in 1995, is strongly influenced by C++.

Russ' book is noteworthy because, although it's inspired by the GOF
book, it
points out how the choice of language is a real factor in the choice and
expression of design pattern languages.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
75af7ee3bb02d7280a51e50e25d5e8a1?d=identicon&s=25 Paul Archer (Guest)
on 2009-03-08 17:25
(Received via mailing list)
Thanks very much to all that responded. I'm frankly a bit overwhelmed by
both the quantity and quality of responses. I feel a bit like the singer
in The Police's "Message In A Bottle": "Woke up this morning/don't
believe
what I saw/Hundred million bottles washed up on my shore."

@Ian: You're probably right, I need to dig in and get started. It's not
that I'm a perfectionist, exactly--but I have this "I've got to do it
right the first time" mentality that I need to get past.

@Phlip: I guess thinking of it as refactoring, rather than just "redoing
my poor first attempt", that'll help. (See above about wanting to do it
right the first time.) And thanks for pointing me to your website.

@Yun: What's CRC?

@Udayanga: thanks, I'll check out the "Head First" book.

@Saji & Rick: And the "Design Patterns" book, too.

@Robert: The OO Encyclopedia looks like a good reference. (Might even
find
out what CRC is. 8-)

@Paul: So get to work.

thanks, all!

Paul
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-03-08 17:26
(Received via mailing list)
Rick DeNatale wrote:

> I strongly believe that although there might be a few universal truths, most
> good OO design needs to take the characteristics of the language into
> account.  If you learn OO from a Java tutorial, you're going to speak Ruby
> with a Java accent.

Very true, and I'm glad to see this point made.

> Object Oriented Software Construction will leave you
> with an Eiffel accent.  The Gang of Four Design Patterns book, although it
> purports to be "language neutral" at least for the popular OO languages back
> in 1995, is strongly influenced by C++.

???

The GoF book has strong influences from Smalltalk and Java.  C++ OO is a
completely different beast.  The GoF don't even mention templates, nor
static polymorphism.

Most self-proclaimed "pure OO" schools of thought represent only
Smalltalk-style OO, based heavily on runtime indirection.  UML only
supports templates as a kind of necessary evil, and still lacks any
support for concepts (where "concept" is a technical term, with a
specific meaning in C++).  The GoF book is in this vein.

Bare C++ has far less support for OO at runtime than (say) Ruby, but
dramatically better support at compile-time.  For example, whereas
multiple inheritance is kind of a dark art in most OO schools of
thought, C++ has wonderful support for it, and deals very cleanly with
reconvergent inheritance hierarchies ("diamonds").  If you come from a
OO background, and want to learn C++, the best way is to temporarily
forget everything you thought you knew about OO.

Btw, a related topic came up today in comp.lang.c++, about translating
GoF terminology to C++.  I mentioned an example that fits, IMO, the
decorator pattern:  An output iterator performs a given operation on
each output value, then passes the result to another, underlying
iterator.  In GoF terminology, Component, the ConcreteComponents,
Decorator, and the ConcreteDecorators are all "classes."  In the C++
implementation, though, Component is the OutputIterator concept, the
ConcreteComponents are the specific types of the underlying iterators,
the Decorator is a template (parameterized by ConcreteComponent and by
the operation to be performed on output values), and all
ConcreteDecorators are instantiations of the template.
87ef5d1e14b148eb596433bc17ffe690?d=identicon&s=25 Leo (Guest)
on 2009-03-08 18:38
(Received via mailing list)
> The GoF book has strong influences from Smalltalk and Java.  C++ OO is a
> completely different beast.

He probably assumed a strong c++ influence because many/most examples
are in c++. IIRC (but I could be wrong of course) the book (1994)
doesn't mention Java (1996).
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-03-08 18:50
(Received via mailing list)
> The GoF book has strong influences from Smalltalk and Java.  C++ OO is a
> completely different beast.

Is that why GoF was published in '94, before Java was released (in '95),
and has
C++ examples?
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-03-08 19:01
(Received via mailing list)
Phlip wrote:
>> The GoF book has strong influences from Smalltalk and Java.  C++ OO is a
>> completely different beast.
>
> Is that why GoF was published in '94, before Java was released (in '95),
> and has C++ examples?

My apologies.  Kindly replace "Java" with "attempts to layer static
typing onto SmallTalk."
0814ff69e309b033508b3c7f363236fd?d=identicon&s=25 Ian Trudel (backorder)
on 2009-03-09 04:54
Paul Archer wrote:
> @Ian: You're probably right, I need to dig in and get started. It's not
> that I'm a perfectionist, exactly--but I have this "I've got to do it
> right the first time" mentality that I need to get past.

I do understand your point. And it's not a bad thing at all. You should
however just keep in mind to balance passive and active learning. It's
also a great opportunity to write few lines of code and then go back to
your books, and repeat the process. It's a good way to bind practical
and theoretical knowledge together. It will lit light bulbs in your head
while helping you to better grasp other concepts, that you're currently
reading on. This process will also allow you to focus on weaker areas
(theoretical or practical), which you understand more or less. Isn't it
a wonderful way to learn? :)


> @Yun: What's CRC?

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



Well, keep us posted.

Ian.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-03-09 09:14
(Received via mailing list)
2009/3/8 Rick DeNatale <rick.denatale@gmail.com>:
> Object Oriented Software Construction will leave you
> with an Eiffel accent.

I would not necessarily say so.  It just happens that Eiffel is the
language which has the richest zoo of inheritance options (including
private inheritance, i.e. without maintaining "is a" relationship)
that I know.  And Bertrand Meyer not only presents concepts but
verbosely explains them. So I'd say you can understand them
independent of language.  It may be though that you benefit most from
this book if you have some OO background already.

Kind regards

robert
D1cdfae31cefbf74601e23114f823a06?d=identicon&s=25 Albert Oliver (Guest)
on 2009-03-09 12:50
(Received via mailing list)
Paul Archer wrote:

> @Yun: What's CRC?

Maybe these links are useful:
http://c2.com/doc/oopsla89/paper.html
http://c2.com/cgi/wiki?CrcCard
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-03-09 22:04
(Received via mailing list)
On Sun, Mar 8, 2009 at 1:34 PM, Leo <minilith@gmail.com> wrote:

> > The GoF book has strong influences from Smalltalk and Java.  C++ OO is a
> > completely different beast.
>
> He probably assumed a strong c++ influence because many/most examples
> are in c++. IIRC (but I could be wrong of course) the book (1994)
> doesn't mention Java (1996).
>
> No, I didn't assume, I knew because I know all four authors (or knew, since
John V. is no longer with us). And there's not nearly as much Smalltalk
influence as there should be, Ralph Johnson admitted as much when he
autographed my copy.

As for not using things like templates etc. in C++, I don't know whether
or
not those features were commonly available if at all when the book was
written.


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
149379873fe2cb70e550c6bff8fedd0c?d=identicon&s=25 Jeff Schwab (Guest)
on 2009-03-09 22:42
(Received via mailing list)
Rick DeNatale wrote:

> As for not using things like templates etc. in C++, I don't know whether or
> not those features were commonly available if at all when the book was
> written.

They were.  See also:
http://www.amazon.com/Scientific-Engineering-Intro...

Anyway, the point I wanted to make was that the GoF book presents a very
different take on OOP from modern C++.
68dd816484963684577c021b73ba1cfb?d=identicon&s=25 Bob Deeds (Guest)
on 2009-03-10 03:03
(Received via mailing list)
How do I unsubscribe?
1d53b088a989e069b94597c282eebbbc?d=identicon&s=25 Simon Krahnke (Guest)
on 2009-03-12 21:35
(Received via mailing list)
* Paul Archer <paul@paularcher.org> (2009-03-08) schrieb:

> I'm good with the how, I'm just a little fuzzy on the how much. To put it
> in more concrete terms: I'm writing (or, rather, I want to write) a script
> that takes incoming digital images from my camera

That's a file, right?

> and renames them an puts them in a directory structure based on their
> date. Now, I have a background in scripting (Bourne shell and Perl),
> and can see doing this in a purely procedural way.

I don't see a reason to do it any other way. One might create some OOP
concepts for doing that, but that would be more code than the simple
loop of the "procedural" way.

It's a too simple task for learning OOP. Just use objects when you see
the need for it.

mfg,                          simon .... l
This topic is locked and can not be replied to.