[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

OO Paradigm and Ruby Exercises for a Beginner

Picklegnome

7/26/2006 7:35:00 PM

I am at a loss for where to begin here, so I'll jump in.

I have worked with several languages, and Ruby is the first one I've
really felt good about. I picked up the Pickaxe book and read through it.
While I get confused at times when "shortcuts" are used (there seem to be a
half-dozen valid ways to do almost anything, with various amounts of
verbosity and code needed - I am used to using explicit "return" statements,
for example) I haven't had much trouble understanding the syntax.
However, I find that I am running into roadblocks when I attempt to
program anything remotely complex. I've looked at many of the exercises in
Chris Pine's _Learn to Program_ and I don't find these too difficult,
especially since they seem to be focused around syntax. I suspect my
frustration is with the object oriented paradigm. I have a superficial
understanding of Classes and Objects and such, and I understand why OO is
useful. However, I am befuddled by much of the code that I read. While it is
possible that I am simply not proficient at algorithm design and am unable
to follow algorithms that are designed by others, I suspect that it is more
deeply rooted in my lack of "getting" OO.

I've got no idea what resources might be used to overcome this problem, and
I am not even certain of my diagnosis. However, I would appreciate any
suggestions, resources, or help that you could offer me, because I am
excited about Ruby and eager to get past this blockage.

Thanks,
Picklegnome


P.S. I apologize for not using my real name; I understand this to be bad
etiquette. As I am a minor, my parents feel I am "at risk" and have asked me
to keep all such information private. I hope not to offend by following
their instruction.

15 Answers

Kevin Clark

7/26/2006 7:50:00 PM

0

gnome,
Do you have any example code for a program you're working on or a
place we can look at code that confuses you?

--
Kevin Clark
http://gl...

S Wayne

7/26/2006 7:56:00 PM

0

Don't worry, one of the challenges of learning OO is 'getting it.' I
always thought it was harder for us old timers who learned non-OO
programming first. Some people say that OO is a mindset, but once you
get it, it is a pretty natural way to think. Afterall, the world is
full of 'objects.'

http://java.sun.com/docs/books/tutorial/java/concepts/o... has
a good tutorial on understanding objects at Sun.

http://www.aonaware.co... has an interesting tutorial on object
oriented programming, that does a pretty good job of describing what
objects and classes are.

Picklegnome

7/26/2006 8:21:00 PM

0

One of the Ruby Quizzes that prompted my post was the "Space Merchant" quiz
at http://rubyquiz.com/q... . I understood very little of the code in
the setup.
On the other hand, Ruby Quiz #12, "Scrabble Stems", at
http://rubyquiz.com/q... was one that I understood most of. Line 14
(starting with "uniques.each do..." was the first sequence of code that
confused me in any way. I understand all of the basic manipulations (with
only one or two consecutive operations) but when it gets to something like
Line 14 or 21 (result = STEMS.delete...) I get lost.

Thanks,
Picklegnome


On 7/26/06 1:49 PM, in article
f53e6950607261249r7459c0bem26d6473afdabbf5f@mail.gmail.com, "Kevin Clark"
<kevin.clark@gmail.com> wrote:

> gnome,
> Do you have any example code for a program you're working on or a
> place we can look at code that confuses you?

Hal E. Fulton

7/26/2006 8:28:00 PM

0

Picklegnome wrote:

[snip]

> useful. However, I am befuddled by much of the code that I read. While it is
> possible that I am simply not proficient at algorithm design and am unable
> to follow algorithms that are designed by others, I suspect that it is more
> deeply rooted in my lack of "getting" OO.
>
> I've got no idea what resources might be used to overcome this problem, and
> I am not even certain of my diagnosis. However, I would appreciate any
> suggestions, resources, or help that you could offer me, because I am
> excited about Ruby and eager to get past this blockage.

Hmm, I could refer you to chapter 1 of _The Ruby Way_ (soon to be in
a 2nd edition). But read it in the library first, don't spend your money
on something you might not use.

Chapter 1 of Damian Conway's _Object Oriented Perl_ is also good.

I also enjoyed the discussion in Bertrand Meyer's book _Object Oriented
Software Construction_. That's where I learned OO myself in 1990.

>
> P.S. I apologize for not using my real name; I understand this to be bad
> etiquette. As I am a minor, my parents feel I am "at risk" and have asked me
> to keep all such information private. I hope not to offend by following
> their instruction.

What?! Picklegnome isn't your real name??

Seriously, anyone who complains about a minor not giving his real
full name is an idiot (or worse). No one here could possibly be
offended.

Your parents are probably being over-cautious. Shows like _60 Minutes_
and _Dateline_ love to talk about Internet predators, but the frequency
is probably greatly overestimated. However IMO you're obligated to obey
your parents. I'm old-fashioned that way.

OT: In an age where millions of college graduates can't write a simple
English paragraph, thanks for writing an intelligent and articulate
email.


Cheers,
Hal


"Times are bad. Children no longer obey their parents, and everyone is
writing a book." -- Marcus Tullius Cicero

Chad Perrin

7/26/2006 11:00:00 PM

0

On Thu, Jul 27, 2006 at 05:28:01AM +0900, Hal Fulton wrote:
>
> Hmm, I could refer you to chapter 1 of _The Ruby Way_ (soon to be in
> a 2nd edition). But read it in the library first, don't spend your money
> on something you might not use.

I've seen references to this book a number of times, and heard good
things about it. What, exactly, is its approach and "theme"? For
instance, the Pickaxe is in general a progression from simple
programming concepts with Ruby to more complex constructions, Why's
(Poignant) Guide is a very entertaining approach to very beginner-level
programming, some books teach beginning programming and "just happen" to
use a given language as its example language, Damian Conway's Object
Oriented Perl is specifically about OOP with Perl, there are books
specifically teaching use of Perl for CGI programming, Agile Web
Development with Rails is, of course, about use of Rails (with Ruby
instruction as a side-effect of that), and so on. The Ruby Way is a
great-sounding title, but it doesn't tell me as explicitly what it's
teaching as (for instance) Learning Perl Objects, References, and
Modules described what the book contained (before they changed the name
to Intermediate Perl).


> >
> >P.S. I apologize for not using my real name; I understand this to be bad
> >etiquette. As I am a minor, my parents feel I am "at risk" and have asked
> >me
> >to keep all such information private. I hope not to offend by following
> >their instruction.
>
> What?! Picklegnome isn't your real name??
>
> Seriously, anyone who complains about a minor not giving his real
> full name is an idiot (or worse). No one here could possibly be
> offended.

I fully understand a desire for privacy, whether parentally mandated or
arising from personal preference. Just don't engage in sock-puppet
activities (assuming a second identity for deceptive purposes) and the
like, and I'm sure you'll get by just fine. In other words, Hal's
right. Don't sweat it.


>
> OT: In an age where millions of college graduates can't write a simple
> English paragraph, thanks for writing an intelligent and articulate
> email.

Ditto! In addition, thanks for asking a question that should probably
be asked more often. I've seen two or three nontrivial efforts at a
Ruby instructional text of some sort that start out with statements like
"I was planning to write a book about object-oriented Ruby that started
with objects and just explained everything form the perspective of using
OOP in a way that would be comprehensible and quickly learned by
programming newbies, but it was too hard, so I started with variables in
the normal imperative/procedural style instead." That drives me up the
wall. I'm no Ruby expert, but I have some familiarity, and what I know
so far has quickly indicated to me that probably the best way to get
someone up to speed quickly on OOP with Ruby from a standing start would
be to teach OOP in a largely transparent manner, so that you're doing
OOP without realizing it for a while. OOP has become such a ubiquitous
and important part of the programming landscape that it makes sense to
teach OOP first, when the alternative is strictly procedural code, for
most purposes. Why hasn't this been done (as far as I'm aware) with
Ruby as the example language?

Yes, I'd do it myself, if I knew more Ruby than I do thus far. Some
day, I suppose, I will -- if it hasn't been done by the time I'm ready.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham

Hal E. Fulton

7/26/2006 11:48:00 PM

0

Chad Perrin wrote:
>
> I've seen references to this book a number of times, and heard good
> things about it. What, exactly, is its approach and "theme"?

Well, the first chapter is different: It's an overview of OOP in general
and Ruby in particular.

The rest of the chapters, for the most part, attempt to answer "how-to"
questions. These range from the trivial ("How do I find the legnth of
a string?") to the monumental ("How do I write a web app?").

It also serves as a kind of "inverted reference" by being
topic-oriented. Things are arranged by topic, not alphabetically.
Thus you'll see the String methods upcase, downcase, casecmp, and
capitalize all discussed together (with maybe a little regex stuff
thrown in).

Some of the design principles were:
- nothing is too small to be included (people's
opinions differ about what is "obvious" or
"trivial")
- cover almost all the core and standard libs
- things that are "missing" from the core and
standard libs are often coded
- it strives for good Ruby style, sometimes
with flaws
- examples are given whenever possible/practical
- it has a CS flavor rather than a corporate one
- it emphasizes principles rather than drop-in
usable code (though that is often there too)
- it gives pointers to outside info when possible
- it gives little tidbits outside its main topic,
for flavor

The first edition had nine chapters and 350+ code
fragments. Many of the chapters in the 2nd ed are
split up and rearranged, and the appendices are
gone. The 2nd ed will have 22 chapters -- how
many code fragments, I'm not sure. The new one is
significantly larger, more up to date, and generally
more accurate.

It's supposed to be available in early November.

Does that help?


> Ditto! In addition, thanks for asking a question that should probably
> be asked more often. I've seen two or three nontrivial efforts at a
> Ruby instructional text of some sort that start out with statements like
> "I was planning to write a book about object-oriented Ruby that started
> with objects and just explained everything form the perspective of using
> OOP in a way that would be comprehensible and quickly learned by
> programming newbies, but it was too hard, so I started with variables in
> the normal imperative/procedural style instead." That drives me up the
> wall. I'm no Ruby expert, but I have some familiarity, and what I know
> so far has quickly indicated to me that probably the best way to get
> someone up to speed quickly on OOP with Ruby from a standing start would
> be to teach OOP in a largely transparent manner, so that you're doing
> OOP without realizing it for a while. OOP has become such a ubiquitous
> and important part of the programming landscape that it makes sense to
> teach OOP first, when the alternative is strictly procedural code, for
> most purposes. Why hasn't this been done (as far as I'm aware) with
> Ruby as the example language?
>
> Yes, I'd do it myself, if I knew more Ruby than I do thus far. Some
> day, I suppose, I will -- if it hasn't been done by the time I'm ready.

I've thought about this, but I think it can only be taken so far.

In explaining OOP, you sort of have to understand what P is before you
grasp what OO is. Maybe we should use the French abbreviation, POO. :)


Hal




Chad Perrin

7/27/2006 12:02:00 AM

0

On Thu, Jul 27, 2006 at 08:48:19AM +0900, Hal Fulton wrote:
> Chad Perrin wrote:
> >
> >I've seen references to this book a number of times, and heard good
> >things about it. What, exactly, is its approach and "theme"?
>
> Well, the first chapter is different: It's an overview of OOP in general
> and Ruby in particular.

Excellent!


>

[ snip a bunch of exposition ]

>
> Does that help?

Wonderful! It's going on my list of must-haves, forthwith -- though I
may wait for 2nd Ed to come out before buying it. Is there a
free/online version available to get me started?


>

[ sip a bunch of dithering by yours truly ]

>
> I've thought about this, but I think it can only be taken so far.
>
> In explaining OOP, you sort of have to understand what P is before you
> grasp what OO is. Maybe we should use the French abbreviation, POO. :)

I'm not sure I agree with that. In fact, I'm pretty sure I don't. If
programming is taught in a strictly object-oriented manner from line
one, the student can progress as a programmer via the OOP instruction,
rather than needing to be a competent programmer first. I think that,
at most, perhaps a handful of pages (four to six, maybe) need to be
spent on "What is a variable?" before getting into object oriented
programming in earnest, and even at that point OOP techniques can be
used where appropriate.

I'm just tired of seeing people say they were going to do an
OOP-complete beginning programmer's tutorial, but gave up, and did a
procedural tutorial with cursory mentions of OOP concepts just for
color. Dammit.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley

James Britt

7/27/2006 12:15:00 AM

0

Hal Fulton wrote:
> Picklegnome wrote:
>
> [snip]
>
>> useful. However, I am befuddled by much of the code that I read. While
>> it is
>> possible that I am simply not proficient at algorithm design and am
>> unable
>> to follow algorithms that are designed by others, I suspect that it is
>> more
>> deeply rooted in my lack of "getting" OO.
>>
>> I've got no idea what resources might be used to overcome this
>> problem, and
>> I am not even certain of my diagnosis. However, I would appreciate any
>> suggestions, resources, or help that you could offer me, because I am
>> excited about Ruby and eager to get past this blockage.
>
>
> Hmm, I could refer you to chapter 1 of _The Ruby Way_ (soon to be in
> a 2nd edition). But read it in the library first, don't spend your money
> on something you might not use.
>
> Chapter 1 of Damian Conway's _Object Oriented Perl_ is also good.
>
> I also enjoyed the discussion in Bertrand Meyer's book _Object Oriented
> Software Construction_. That's where I learned OO myself in 1990.


I liked Rebecca Wirfs-Brock's Designing Object-Oriented Software. It
does a good job of explaining how to think about objects in terms of
roles, responsibility, and collaboration.

http://www.wirfs-brock.com/Design...

It tends to be kinda pricey, so add it to your library list. (But buy
Hal's book when the new edition comes out.)


--
James Britt

"In Ruby, no one cares who your parents were, all they care
about is if you know what you are talking about."
- Logan Capaldo

Gene Tani

7/27/2006 1:35:00 AM

0


Hal Fulton wrote:

> The first edition had nine chapters and 350+ code
> fragments. Many of the chapters in the 2nd ed are
> split up and rearranged, and the appendices are
> gone. The 2nd ed will have 22 chapters -- how
> many code fragments, I'm not sure. The new one is
> significantly larger, more up to date, and generally
> more accurate.
>
> It's supposed to be available in early November.
>

Rough cut today (i think)

http://safari.oreilly.com/...


meadori

7/27/2006 1:54:00 AM

0

Picklegnome,

I am happy to hear of your enthusiasm for Ruby and programming.

Others have mentioned good books, so I will spare from adding to the list.
The bit of advice I can given is simple: just program a lot. You can
read web pages and books all day long, but some things you just won't
get until you come across them on your own.

When I first started to get serious about programming I would read a
lot of code. A lot the time I would get confused and wonder why
someone did this or that. To the point were it was distracting me from
really learning. I finally just started to code a lot and after a
while I would come up with similiar solutions. Then I would think
back, "Huh, that's why they did that."

Don't get me wrong studying and reading are definitely great for
learning new ideas and the way others think about things. My point is
that you have to be trying to program and solve problems on your own
for it to be most effective.

Best of luck!

--Meador

On 7/26/06, Picklegnome <picklegnome@nerdshack.com> wrote:
> I am at a loss for where to begin here, so I'll jump in.
>
> I have worked with several languages, and Ruby is the first one I've
> really felt good about. I picked up the Pickaxe book and read through it.
> While I get confused at times when "shortcuts" are used (there seem to be a
> half-dozen valid ways to do almost anything, with various amounts of
> verbosity and code needed - I am used to using explicit "return" statements,
> for example) I haven't had much trouble understanding the syntax.
> However, I find that I am running into roadblocks when I attempt to
> program anything remotely complex. I've looked at many of the exercises in
> Chris Pine's _Learn to Program_ and I don't find these too difficult,
> especially since they seem to be focused around syntax. I suspect my
> frustration is with the object oriented paradigm. I have a superficial
> understanding of Classes and Objects and such, and I understand why OO is
> useful. However, I am befuddled by much of the code that I read. While it is
> possible that I am simply not proficient at algorithm design and am unable
> to follow algorithms that are designed by others, I suspect that it is more
> deeply rooted in my lack of "getting" OO.
>
> I've got no idea what resources might be used to overcome this problem, and
> I am not even certain of my diagnosis. However, I would appreciate any
> suggestions, resources, or help that you could offer me, because I am
> excited about Ruby and eager to get past this blockage.
>
> Thanks,
> Picklegnome
>
>
> P.S. I apologize for not using my real name; I understand this to be bad
> etiquette. As I am a minor, my parents feel I am "at risk" and have asked me
> to keep all such information private. I hope not to offend by following
> their instruction.
>
>
>