From mboxrd@z Thu Jan 1 00:00:00 1970 From: bwalton@artsci.utoronto.ca (Ben Walton) Date: Wed, 19 Aug 2009 22:57:25 -0400 Subject: [sup-talk] In next: thread-view-mode labelling No method join for Set In-Reply-To: <1250727630-sup-3112@yoom.home.cworth.org> References: <1250714501-sup-3033@chigamba> <1250727630-sup-3112@yoom.home.cworth.org> Message-ID: <1250734085-sup-2162@ntdws12.chass.utoronto.ca> 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. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: not available URL: