Ruby User Group??

Carl Parrish plug-devel@lists.PLUG.phoenix.az.us
Wed Mar 20 16:15:01 2002


On Wed, 2002-03-20 at 13:19, Rob Wehrli wrote:
> 
> Like:
> 	Instead of (Java-like) every time: 
>   	Form form = forms.first();
>                          while (form != form.last())
>                          {
>                            if (form.valid())
>                            {
>                              // ---- Do something
>                            }
>                            form = form.next();
>                          }
> 
>                        the Ruby way is: 
> 
>                          class Forms < Array
> 
>                            def each_form
>                              each do | form |
>                                yield form if form.valid
>                              end
>                            end
> 
>                          end
> 
>                          forms.each_form do | form |
>                            # ---- Do something
>                          end
> 
> Has any real value!  Instead of balancing braces, we're balancing ends? 
> What new benefit are we gaining from this "enhanced" syntax?  We now
> have to consider that "each" is a keyword meaning elements in an array? 
> I love "each do | form |"  Read that as "each do pipe form pipe" or is
> that supposed to be the absolute value of form?  Sorry, but I still
> don't see what makes Ruby so special.  AND the author of the LJ article
> is obviously WRONG since the code above is NOT Java-like, since Java can
> not convert (class) form to a boolean to make the while conditional
> true/false, though C can if "form" is really a pointer to a Form class.
>

I think you missed the point here that the Ruby way all of the
responsiblity of the form is in the form class. Which makes it cleaner
(at least to my eyes) code. He does tend to skip over the fact that in
Java you *can* place most of it in a method of form. But that still
doesn't seem to be as clean to me. 
 
> If we ever have an "official" development language, perhaps we should
> consider that this is the PLUG (the Linux part is hidden in there
> somewhere) developer's group and the language of Linux is C.

I said "official" in quotes because it doesn't seem that *anything* in
in PLUG is ever very ridged, however I do think it would benifit us if
we had an agreed language format for exchaining code. My view of this
group isn't to make us better at any specific language but at developing
in general. But often something is *much* easier said in code. Most of
the things I would want to talk about are OOP related and although I
love C, I don't think that OO C is very readable. 



> 
> Hopefully I haven't rained on your Ruby parade too much, but jeez, let's
> start adding up all of the truly "pragmatic" benefits of everyone having
> ANYTHING AT ALL to do with Ruby and see just what that and a 10-10-220
> call will get for us?  If you want to learn and use Ruby, fine,  go
> ahead.  Let's not nominate it for an academy award just yet.  I for one
> absolutely do not want anything to do with it.  Anyone want to guess how
> many prospective employers are looking for C programmers versus Ruby
> programmers today...tomorrow...in 10 years?
> 
Right *nobody* is looking for Ruby programmers here in the US. But then
I rarely see anyone asking for Smalltalk or Lisp these days either and
yet they still come in handy. I don't think the criteria for a good
language is that someone is hiring for it. Most projects don't ask for
XML but once I suggest it and show why they fall in love with the idea.
It's my job as the developer to make the suggestions of what tools to
use. And because of this I'm not particularly interested in becoming an
expert at any one language but would instead rather concentrate on
becoming a better *developer*. In that light I've found ruby to be
*much* easier for me to express concepts as code. But that's just been
over the last two weeks. The first time I looked at ruby I liked the
OOPness (yeah I know that's not a word) but wasn't too fond of the
syntax since it didn't really seem to feel like the other languages I
worked with. After working with it for a bit though today I am *very* 
excited about Ruby and will be for awhile. I've never used it in a
production environment so don't know how well it scales haven't done any
benchmarking so don't know how well it preforms. My recommendation is
simply as a way to convey concepts. I'm not married to the idea of using
Ruby  (though I will be routing for it). Python is almost as good. Two
years ago I was excited about java so I'm not pushing ruby per say
(though its still at the top of my list). But I think that if we define
an "official" language perhaps will have more development discussion,
which I know I for one could use. 



> I mean...take a look at the syntax.  If the "class Form" is somewhere
> previously declared, then why declare it here?  It is being declared
> FIRST here.  Is "yeild" a keyword or a method?  Probably a keyword,
> huh?  Does it mean "yeild as in giving way to something else" or does it
> mean "yeild as in producing something?"  "def each_form" what is that, a
> method declaration?  A variable declaration?  Probably a method. 
> Apparently it interacts with/upon a "form" instance.  Isn't that
> quaint.  A method declared internally to operate on its "outerself." 
> Wow...kinda like an iterator but the type is unclear?  You can keep it.


The class "Form" is being declared here

class Forms < Array

just means that Forms is a subclass of the Array Object. The keyword
yeild here is used just like CLU version. It means that everytime it
encounters it yield use it as if the method was called again. In trivial
examples it doesn't seem to have much use (after all why not simply
*call* the method again). However in code blocks, like it is here, its
very useful. In this example since each_do has an "each" call putting
yeild in the block makes the method recursive. My point is that once you
know the syntax it's really easy to look at that block of code and
"know" what it's doing unlike a lot of recursive methods where I have to
look twice. 


> 
> 	    class Song
>                def initialize(name, artist, duration)
>                  @name     = name
>                  @artist   = artist
>                  @duration = duration
>                end
>              end
> 
> Is this Visual Basic or what?

This is like saying 
  my($name) = name 
in perl

I'm always interested in feedback btw. 

Carl P.