[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

My Ruby talk @ work..

Stephen Waits

3/8/2006 11:00:00 PM

I just finished my "Learn Ruby" talk for the programmers here at work.
(Game programmers, strong in C/C++).

I flew through a massive amount of stuff.. leaving continuations and
metaprogramming on the table for another day. I managed to get it done
just over my goal of 90 minutes (maybe 100).


I found that the programmers who'd worked in dynamic languages
previously, through a University course or otherwise, followed along
pretty well. Those without that experience dazed out once we got into
things like lambdas.

Overall though, I'm satisfied.

I did my presentation in HTML generated from ERB. I just set my browser
to full-screen -- it worked pretty well. I've posted both the ERB and
HTML files at: http://www.waits.net/~swaits/Lear...

I'd very much like to improve the document, so any feedback is
appreciated. It also might be useful to others in my situation
(teaching Ruby to programmers).

--Steve



15 Answers

Ara.T.Howard

3/9/2006 12:02:00 AM

0

Jeff

3/9/2006 12:38:00 AM

0

Stephen Waits wrote:
> I'd very much like to improve the document, so any feedback is
> appreciated. It also might be useful to others in my situation
> (teaching Ruby to programmers).
>
> --Steve

Looks great, Steve. Thanks for publicizing it.

I'm wondering, how much confusion was there over symbols? Were the
dynamic-language folks more comfortable with symbols than the others?
This is one thing I sometimes find is hard to explain to someone who is
new to Ruby.

Jeff
www.softiesonrails.com

--
Posted via http://www.ruby-....


Stephen Waits

3/9/2006 12:45:00 AM

0

ara.t.howard@noaa.gov wrote:
>
> very nice. i'm stealing your template. ;-)

Excellent! Maybe we could bundle it into a "Ruby Tutorial Kit"?

--Steve




Stephen Waits

3/9/2006 12:49:00 AM

0

Jeff Cohen wrote:
>
> Looks great, Steve. Thanks for publicizing it.

Thanks.

> I'm wondering, how much confusion was there over symbols? Were the
> dynamic-language folks more comfortable with symbols than the others?
> This is one thing I sometimes find is hard to explain to someone who is
> new to Ruby.

I explained it to them that as a programmer we'd basically use symbols
very similarly to how we use enums in C/C++. I showed how they're
commonly used as keys in hashes.

I explained that each symbol has a unique ID, and that Ruby uses symbols
to look stuff up within its own system. I believe I had given them
several ".send(:symbol)" examples at that point.

I showed them :symbol.to_i, and :symbol.class too.

I *think* they understood it. I didn't notice any difference between
the dynamic experienced and the rest.

--Steve



Jeff

3/9/2006 1:35:00 AM

0

Stephen Waits wrote:
> I explained that each symbol has a unique ID, and that Ruby uses symbols
> to look stuff up within its own system. I believe I had given them
> several ".send(:symbol)" examples at that point.

And it's much better than the "it's an immutable string" explanation,
which I've found to be just a rats nest of problems.

Enums are another good analogy. But in C++/C# enums are typed so you
know the client gave you a valid value. The only way I can see to
enforce this in Ruby is to create a constant array of the valid symbols
and then make sure what they passed me is in the array:

class HockeyGear

BuyableGear = [ :stick, :helmet, :skates ]

def self.buy_something(gear)
if (!BuyableGear.include?(gear))
return nil
end

# let them buy something...
end

end

HockeyGear.buy_something(:soccer_ball) # returns nil


Somehow I feel this is pretty un-rubylike, to have to have that if
statement in front of every method. Any idea if there's a more
ruby-like way to have enum-like behavior?

Thanks
Jeff

--
Posted via http://www.ruby-....


Logan Capaldo

3/9/2006 1:53:00 AM

0


On Mar 8, 2006, at 8:34 PM, Jeff Cohen wrote:

> Stephen Waits wrote:
>> I explained that each symbol has a unique ID, and that Ruby uses
>> symbols
>> to look stuff up within its own system. I believe I had given them
>> several ".send(:symbol)" examples at that point.
>
> And it's much better than the "it's an immutable string" explanation,
> which I've found to be just a rats nest of problems.
>
> Enums are another good analogy. But in C++/C# enums are typed so you
> know the client gave you a valid value. The only way I can see to
> enforce this in Ruby is to create a constant array of the valid
> symbols
> and then make sure what they passed me is in the array:
>
>

Enums are typed in C++, to a certain extent (better than C anyway),
but if the lhs is an int well...


> Somehow I feel this is pretty un-rubylike, to have to have that if
> statement in front of every method. Any idea if there's a more
> ruby-like way to have enum-like behavior?
>
> Thanks
> Jeff
>
> --
> Posted via http://www.ruby-....
>

The idiom I usually use is:
class HockeyGear
Stick = Object.new
Helmet = Object.new
...etc...
end

Of course other than the aesthtics of looking like an enum
(HockeyGear::Stick) in the source code there's no advantage over
symbols. On the other hand, if someone is passing you an enum, it
probably means any one of the enums is valid, so you should be
checking all of them anyway, and throw an exception in the else
clause. Checking whether an object is of the right type isn't very
ruby-like anyway.





Mark Volkmann

3/9/2006 3:03:00 AM

0

On 3/8/06, Stephen Waits <steve@waits.net> wrote:
> I just finished my "Learn Ruby" talk for the programmers here at work.
> (Game programmers, strong in C/C++).
>
> I flew through a massive amount of stuff.. leaving continuations and
> metaprogramming on the table for another day. I managed to get it done
> just over my goal of 90 minutes (maybe 100).
>
>
> I found that the programmers who'd worked in dynamic languages
> previously, through a University course or otherwise, followed along
> pretty well. Those without that experience dazed out once we got into
> things like lambdas.
>
> Overall though, I'm satisfied.
>
> I did my presentation in HTML generated from ERB. I just set my browser
> to full-screen -- it worked pretty well. I've posted both the ERB and
> HTML files at: http://www.waits.net/~swaits/Lear...
>
> I'd very much like to improve the document, so any feedback is
> appreciated. It also might be useful to others in my situation
> (teaching Ruby to programmers).

I like the way you mixed in a little mixin humor.

"Little Miss Mixins, you are a skanky friend-with-benefits."

--
R. Mark Volkmann
Partner, Object Computing, Inc.


Dave Burt

3/9/2006 3:03:00 AM

0

Stephen Waits wrote:
>I just finished my "Learn Ruby" talk for the programmers here at work.
>(Game programmers, strong in C/C++).
> ...
> I'd very much like to improve the document, so any feedback is
> appreciated. It also might be useful to others in my situation (teaching
> Ruby to programmers).

Your section on control structures is a little broken. You have "loop do ...
end while ...". The while condition will only be evaluated once (so it's
equivalent to "if"), and if true "loop" will repeat the block forever. What
did you intend this example to do?

Cheers,
Dave


Stephen Waits

3/9/2006 4:11:00 AM

0


On Mar 8, 2006, at 7:03 PM, Mark Volkmann wrote:

> I like the way you mixed in a little mixin humor.
>
> "Little Miss Mixins, you are a skanky friend-with-benefits."

Thanks.. I do like the Mixin. :)

--Steve



Stephen Waits

3/9/2006 4:16:00 AM

0


On Mar 8, 2006, at 7:03 PM, Dave Burt wrote:

> Your section on control structures is a little broken. You have
> "loop do ...
> end while ...". The while condition will only be evaluated once (so
> it's
> equivalent to "if"), and if true "loop" will repeat the block
> forever. What
> did you intend this example to do?

Oh yikes! It's just a poor example and it's what I get for working
on this in the wee hours of the morning.

I updated it. Thanks for catching that Dave!

--Steve