Forum: Ruby How Ruby

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.
081087ca298bf0a1c5e65e5336269fcb?d=identicon&s=25 Dhushyanth Ramasamy (dash)
on 2009-01-09 07:17
Well i read the posts on "Why ruby" now I wanted to know "How Ruby":


I recently chanced upon this forum while on internet. I too have
recently taken an interest in learning Ruby. The thing is I get sort of
overwhelmed when I see any of the forum pages( in ruby-central or any
other ruby forum). It's as if I haven't learned a thing. All the talk
say for example about testing, and about something called Merb made me
introspect(This site in particular since I want to participate in Google
summer of code or at least be capable of participating:
http://rubycentral.com/projects/gsoc-2008/ideas-fo...)  - Can I
really master this language? I feel that if I do learn a language I
should be able to do anything with it and not just write maze solving
programs, algorithmic problems, or some competition challenges.

Currently I have experience only in c++ coding( I have done a crash
course in Java though, but still feel that I am not expert enough) that
too only in an IDE (the kind of old stuff which they teach at our
school). I daresay I am best in my batch but I still feel I know nothing
when I go out and look into the big bad web. I mean for example, I am
still stuck to <iostream.h> whereas I found out that it is outdated and
changed to just simply <iostream> with use of std::namespace etc. I
still use arrays and don't know about vectors and hashes. So I would not
like to repeat my mistakes when I start anew with Ruby. I just want to
be at the leading edge along with the developers. I want to be at the
forefront and not just be a simple namesake programmer who knows nothing
about the "real world".
     I would very much like to remedy this problem. This fear has raised
doubts in my head: Is programming really for me?, Will I always be a
noob?.....The thing is there isn't someone to teach you how to be an
expert. As I try to specialize in something, something comes up
which tells that you should know this before you go any further and so
forth. It's as if you need to know Java, XML, Ant, JUnit all at the same
time.
Can you suggest what I should do to remedy this? I really want to be an
expert in Ruby. Putting in the effort is no problem for me as long
as I know that I am going somewhere and am not just loitering
around.Currently I am studying Ruby through "Programming Ruby: the
pragmatic programmers guide, 2nd edition".


I do understand that people don't like long rambling posts but I needed
to get my feelings out of my system. This won't occur in future and
sorry for this awfully long post.
D1309ef77561e3cdf0ddcab60b244e52?d=identicon&s=25 Mike Stephens (aspirer)
on 2009-01-09 08:35
My view is you start out simple and straightforward. There are no Police
to arrest you if you write procedural Ruby programs. I have many Ruby
books and the impression I get is it is a complex, subtle and somewhat
arcane language. I have no intention of ever learning reflection and
that sort of thing. My long experience of IT tells me that code is a
tiny part of solving problems and that clever code is rarely preferable
to something simple and easy to understand. What I also want to avoid -
like you - is having to learn lots of things at once so my advice is
start off with raw Ruby out of the box, and only add layers as you
become comfortable with what you've already learnt. You're not in this
game to talk to clever people at conferences. You're here to build
systems that work.
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-01-09 13:03
(Received via mailing list)
Thanks Mike. I appreciated your post. I'm an awful Ruby programmer, and
write tightly organized, well documented procedural Ruby. I'm only now,
after probably 1.5 years of on and off work in the language, getting
around to writing classes. I really couldn't see why I'd want to, until
very recently. Then, thanks to some folks on this list, I "got it". I
can't wait to dive in to using classes, now.

I'm also getting into cucumber and rspec as fast as I can (most
impressive, at least to me), and I've very grateful for the clever
people working in that corner of the universe. I'm learning an awful lot
from them.

I've loved the whole experience, even at my very humble level of
involvement. It's just been fun (well, not all the time). My programs
work, and they do work FOR me (my only client).  I totally do NOT need
legitimization (not my profession), but it's still awfully nice to read
your post. You've described my attitude quite precisely.

t.

Mike Stephens wrote:
> game to talk to clever people at conferences. You're here to build
> systems that work.
>


--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-09 14:26
(Received via mailing list)
Hi --

On Fri, 9 Jan 2009, Mike Stephens wrote:

> game to talk to clever people at conferences. You're here to build
> systems that work.

At the same time, keep in mind that Ruby is optimized for programmer
enjoyment, so it in fact tries not to be arcane (though it's not
without a learning curve, of course). Also, things like reflection and
other so-called "metaprogramming" techniques in Ruby actually arise
very naturally from the basic object model and the basic idioms of the
language. It's all cut from the same cloth, which is one of the things
that make it fun and interesting.[1]

Lots of people who build systems that work also come to conferences,
where they enjoy the company and stimulation of their friends and
colleagues who have been working on other projects and have
interesting insights to share. I've co-organized around twenty
Ruby-related conferences, and attended quite a few others, and it's
been an on-going highlight of my experience as a Rubyist.

In short, I wouldn't look at either the Ruby language or the Ruby
world as a minefield of clever but shallow features and/or people. In
my 8+ years of experience with it, it's anything but.


David

[1]
http://dablog.rubypal.com/2007/1/7/meta-shmeta-lea...

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-09 14:31
(Received via mailing list)
Hi --

On Fri, 9 Jan 2009, Tom Cloyd wrote:

> Thanks Mike. I appreciated your post. I'm an awful Ruby programmer, and write
> tightly organized, well documented procedural Ruby. I'm only now, after
> probably 1.5 years of on and off work in the language, getting around to
> writing classes. I really couldn't see why I'd want to, until very recently.
> Then, thanks to some folks on this list, I "got it". I can't wait to dive in
> to using classes, now.

Dave Thomas issued a challenge in a recent keynote address, where he
suggested that when each of us writes our next Ruby program, we try to
do it without writing any classes. It's an artificial exercise, of
course, but it keeps the focus on the objects as opposed to the class
hierarchy, which is all to the good in most cases.

When I teach the Ruby language, I actually illustrate singleton
methods before I talk about classes, because I consider the dynamism
of objects (their independence from their classes) to be a more
important foundational principle of Ruby than the fact that every
object is an instance of a class. Mind you, like everyone else I write
"class Thing" more often than "def thing.something" in my own code (I
think :-) But it's still important, in my view, to get the hang of the
fact that Ruby classes are not the center of gravity.

So it sounds like you've done it in the right order :-) Keep modules
in mind, too. They're very cool, especially when you #extend objects
with them....


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
C519d578e95231d426716bf7d58b8b85?d=identicon&s=25 Stuart Ellis (Guest)
on 2009-01-09 15:26
(Received via mailing list)
On 9 Jan 2009, at 13:30, David A. Black wrote:

>
> object is an instance of a class. Mind you, like everyone else I write
> "class Thing" more often than "def thing.something" in my own code (I
> think :-) But it's still important, in my view, to get the hang of the
> fact that Ruby classes are not the center of gravity.
>
> So it sounds like you've done it in the right order :-) Keep modules
> in mind, too. They're very cool, especially when you #extend objects
> with them....

*Raises hand*

At the risk of looking very silly, could I ask you to say a bit more
about this? As a newbie, I have automatically read "object" to mean
"an instance of a defined class", and assumed that object orientation
in Ruby leads to mostly thinking in terms of classes.

Thank you,
D1309ef77561e3cdf0ddcab60b244e52?d=identicon&s=25 Mike Stephens (aspirer)
on 2009-01-09 15:37
> In short, I wouldn't look at either the Ruby language or the Ruby
> world as a minefield of clever but shallow features and/or people.

I did not intend to suggest this. However coming from a background of
Pascal-like languages, Ruby strikes me as extremely powerful and
feature-rich, but correspondingly dangerous. The variable scope rules,
for example, do seem to be conceived by someone with a sadistic turn of
mind. Matz might see it as a medium of natural expression but maybe not
everyone has his IQ.
F1938de600a3feacd015051492fdaf0f?d=identicon&s=25 LAMBEAU Bernard (Guest)
on 2009-01-09 16:23
(Received via mailing list)
Ruby allows you to install methods on objects (called singleton
methods because installed on individual objects instead of being
shared by all instances of a class):

o = Object.new
def o.sayhello
  puts "hello"
end

o.sayhello    # prints hello to the console

blambeau
081087ca298bf0a1c5e65e5336269fcb?d=identicon&s=25 Dhushyanth Ramasamy (dash)
on 2009-01-09 16:24
Mike Stephens wrote:
> My view is you start ........ You're not in this
> game to talk to clever people at conferences. You're here to build
> systems that work.

I think we are getting side-tracked here I wanted to know "how Ruby" not
"why Ruby". So apart from Mike's i daresay other replies were
distractions( no offence guys, but i think they are part of the "Why
Ruby" or completely separate discussions).
  I wanted to know a concrete study plan or a general "road to utopia"
guidance.

Thanks by the way all of you guys for your active interest. This forum
roxxxx..
C519d578e95231d426716bf7d58b8b85?d=identicon&s=25 Stuart Ellis (Guest)
on 2009-01-10 12:10
(Received via mailing list)
On 9 Jan 2009, at 15:22, LAMBEAU Bernard wrote:

>
> blambeau
>

Now I see - thanks.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-10 15:47
(Received via mailing list)
Hi --

On Sat, 10 Jan 2009, Stuart Ellis wrote:

>> end
>>
>> o.sayhello    # prints hello to the console
>>
>> blambeau
>>
>
> Now I see - thanks.

Also, you can use modules to shape the behavior of individual objects:

   module Vocal
     def sayhello
       puts "Hello"
     end
   end

   o = Object.new
   o.extend(Vocal)
   o.sayhello


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-10 15:51
(Received via mailing list)
Hi --

On Fri, 9 Jan 2009, Mike Stephens wrote:

>
>> In short, I wouldn't look at either the Ruby language or the Ruby
>> world as a minefield of clever but shallow features and/or people.
>
> I did not intend to suggest this. However coming from a background of
> Pascal-like languages, Ruby strikes me as extremely powerful and
> feature-rich, but correspondingly dangerous. The variable scope rules,
> for example, do seem to be conceived by someone with a sadistic turn of
> mind. Matz might see it as a medium of natural expression but maybe not
> everyone has his IQ.

Which rules are you thinking of? I'd be interested in hearing because
maybe I can produce an account of how they work that would make them
seem less sadistic. (I haven't picked up on that aspect of them, which
may mean I'm missing something or may mean that for some reason I've
got hold of a benign way of interacting with them.)


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-10 15:52
(Received via mailing list)
Hi --

On Sat, 10 Jan 2009, Dhushyanth Ramasamy wrote:

> guidance.
Well, if you can wait a month or two, Manning is coming out with "The
Well-Grounded Rubyist" :-)  (http://manning.com/black2 and yes, I'm
"Black2" in this case.)

> Thanks by the way all of you guys for your active interest. This forum
> roxxxx..

It does have its very nice moments, I have to say.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
D1309ef77561e3cdf0ddcab60b244e52?d=identicon&s=25 Mike Stephens (aspirer)
on 2009-01-11 15:54
 The variable scope rules,
>> for example, do seem to be conceived by someone with a sadistic turn of
>> mind.
>
> Which rules are you thinking of?

Just one example is 5.4.3 in The Ruby Programming Language (Flanagan &
Matsumoto).  This talks about whether a variable is private to a block
but it depends on this, that and the other.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-11 16:25
(Received via mailing list)
Mike Stephens wrote:

> Just one example is 5.4.3 in The Ruby Programming Language (Flanagan &
> Matsumoto).  This talks about whether a variable is private to a block
> but it depends on this, that and the other.

Generally, Ruby stays out of your way. (Thomas.)

In this situation, Ruby gets in your way if your methods are super long,
and if
you don't have unit tests.

If you have very short methods, then variable scope is much more
intuitive, and
if you test all your code (which is easy if methods are short), then you
catch
scope errors by their effects, not by mentally analyzing their design.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-11 16:40
(Received via mailing list)
Hi --

On Sun, 11 Jan 2009, Mike Stephens wrote:

> The variable scope rules,
>>> for example, do seem to be conceived by someone with a sadistic turn of
>>> mind.
>>
>> Which rules are you thinking of?
>
> Just one example is 5.4.3 in The Ruby Programming Language (Flanagan &
> Matsumoto).  This talks about whether a variable is private to a block
> but it depends on this, that and the other.

Oh, those rules :-) The good news is that the rules are pretty
well-tailored to the actual programming needs you're like to have,
which include wanting to write closures (so that the block captures
the local variables from the scope of its creation) and having
variables that are truly local to the block. It might be sadistic to
disallow either of those scenarios :-) It's been a thorny area,
though, and it's undergone a lot of change between 1.8 and 1.9.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
D1309ef77561e3cdf0ddcab60b244e52?d=identicon&s=25 Mike Stephens (aspirer)
on 2009-01-12 08:57
 The good news is that the rules are pretty
> well-tailored to the actual programming needs you're like to have,
> which include wanting to write closures (so that the block captures
> the local variables from the scope of its creation)

Now accept that I'm talking in the abstract here (I've done very little
Ruby coding), I would have thought that if you want to access data from
another piece of code, you should call a method unless that target has
been specifically declared as public or global. Ruby of course allows
you to directly access data declared as private. These are examples of
why I think Ruby is highly sophisticated and therefore has a potentially
high barrier-to-entry. and in turn why I suspect the answer for many
people is to limit yourself to a simple sub-set.
Ae16cb4f6d78e485b04ce1e821592ae5?d=identicon&s=25 Martin DeMello (Guest)
on 2009-01-12 11:07
(Received via mailing list)
On Mon, Jan 12, 2009 at 11:56 AM, Mike Stephens <rubfor@recitel.net>
wrote:
> been specifically declared as public or global. Ruby of course allows
> you to directly access data declared as private. These are examples of

Ruby does not. Try this

class A
  def initialize
    @foo = 28
  end
end

a = A.new
a.foo

What it does do is provide you with convenience methods named after
the variable *if you ask for them* via attr_reader and attr_writer or
attr_accessor.

martin
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-12 13:05
(Received via mailing list)
Hi --

On Mon, 12 Jan 2009, Mike Stephens wrote:

> why I think Ruby is highly sophisticated and therefore has a potentially
> high barrier-to-entry. and in turn why I suspect the answer for many
> people is to limit yourself to a simple sub-set.

Closures aren't about breaking privacy encapsulation. The point of
preserving the local variables in a closure is so that you can define
functions in one place and use them in another, and they can do what
they did at the point where they were defined:

   def give_me_a_counter
     n = 0
     lambda { n += 1 }
   end

   c = give_me_a_counter
   puts c.call          # 1
   puts c.call          # 2
   puts c.call          # 3
   d = give_me_a_counter
   puts d.call          # 1
   puts c.call          # 4

The variable n is local to give_me_a_counter, but the lambda it
returns isn't -- and the lambda happens to use a local variable. This
is not related to the kinds of privacy things I think you're talking
about (like instance_variable_get).


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-01-12 15:41
(Received via mailing list)
On Fri, Jan 9, 2009 at 2:30 PM, David A. Black <dblack@rubypal.com>
wrote:
> Hi --

> Dave Thomas issued a challenge in a recent keynote address, where he
> suggested that when each of us writes our next Ruby program, we try to
> do it without writing any classes.

At least he could have left a note at my blog. ;)
http://ruby-smalltalk.blogspot.com/2007/08/from-me...
But I feel honored that my ideas are not that crazy or let us say
crazy enough!!!

Cheers
R.
It is change, continuing change, inevitable change, that is the
dominant factor in society today. No sensible decision can be made any
longer without taking into account not only the world as it is, but
the world as it will be ... ~ Isaac Asimov
7a561ec0875fcbbe3066ea8fe288ec77?d=identicon&s=25 Sebastian Hungerecker (Guest)
on 2009-01-12 23:11
(Received via mailing list)
Martin DeMello wrote:
> end
>
> a = A.new
> a.foo

a.instance_variable_get(:@foo)
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-12 23:21
(Received via mailing list)
Hi --

On Tue, 13 Jan 2009, Sebastian Hungerecker wrote:

>>   end
>> end
>>
>> a = A.new
>> a.foo
>
> a.instance_variable_get(:@foo)

I wouldn't call that accessing it "directly" though :-)


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
This topic is locked and can not be replied to.