Excerpts from Carl Worth's message of Wed Aug 19 20:31:12 -0400 2009:

> [*] Totally off-topic: This is one of the things about "dynamically
> typed" languages that I've never been able to wrap my brain around. I
> really like that with static typing I can trust the compiler to help
> me be very thorough if I make a type change like this, (and catch all
> the cases before shipping any code). Instead, here, there's a hard
> task of exercising every possible code path (at run time) before we
> know if there are any type errors still lingering. I've seen some
> proponents of dynamically-typed languages argue that unit testing
> should provide the same coverage that a statically-typed compiler
> would, but I haven't seen that in practice.

The term you'll see bandied about in ruby circles/books/etc is 'duck
typing' which coming from strongly typed languages is definitely
something that takes some getting used to.  Basically, instead of
caring about the type of the object, you case about what the object
does.  If it walks like a duck and quacks like a duck, treat it like a
duck.

A very simple example is a function that expects to append data to
another object.  You could pass it a string (which uses << to append)
or an array (which uses << to push elements on the end).  If you
originally passed a string, but found performance (memory ->
realloc()) issues, you could swap the string object for an array
object and do array.join when everything is collected into array
elements.

Then, you'll see many examples where there is code like:

raise SomeException, "blah" unless someobject.respond_to?(:somemethod)

Your code doesn't care _what kind_ of object it gets as long as it
knows _how_ to talk to it.

Personally, I really like this.  Ruby isn't perfect by any stretch,
but of all the languages I've used, it's hands down the most fun to
write.

-Ben
-- 
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

GPG Key Id: 8E89F6D2; Key Server: pgp.mit.edu
Contact me to arrange for a CAcert assurance meeting.

Attachment: signature.asc
Description: PGP signature

_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk

Reply via email to