[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

OO style tutorials?

Paul Archer

3/8/2009 5:49:00 AM

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

18 Answers

Ian Trudel

3/8/2009 7:05:00 AM

0

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.rub... ? 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.
--
Posted via http://www.ruby-....

Phlip

3/8/2009 7:33:00 AM

0

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.

--
Phlip
http://www.zerop...

Yun Huang Yong

3/8/2009 9:28:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

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/concepts/...

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_Modelin...
[2] http://www.agilemodeling.com/artifacts/cr...





--
(__) Share what you know.
Yun Huang Yong `\------(oo) Learn what you don't.
gumby@mooh.org || (__) --'
goosmurf@yahoo.com \|/ ||w--|| \|/
--

usw wickramasinghe

3/8/2009 11:46:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

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

Saji N. Hameed

3/8/2009 1:01:00 PM

0

* 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-Wesley-Professional/dp/...

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



Robert Klemme

3/8/2009 1:34:00 PM

0

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...

Kind regards

robert

Rick DeNatale

3/8/2009 2:32:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Sun, Mar 8, 2009 at 8:00 AM, Saji N. Hameed <saji@apcc21.net> wrote:

> * 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-Wesley-Professional/dp/...
>
>
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.denh...
Twitter: http://twitter.com/Ri...
WWR: http://www.workingwithrails.com/person/9021-ric...
LinkedIn: http://www.linkedin.com/in/ri...

Jeff Schwab

3/8/2009 4:21:00 PM

0

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.

Paul Archer

3/8/2009 4:23:00 PM

0

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


On Sun, 8 Mar 2009, 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.
>
> 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
>

-lim-

3/8/2009 5:34:00 PM

0

> The GoF book has strong influences from Smalltalk and Java. =A0C++ 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).