From: Wayne Vucenic Date: 2001-07-20T10:14:41+09:00 Subject: [ruby-talk:18156] Re: Looking for Ruby programming exercises Hi Chris, Thanks for the reply! >> > Seriously, I can think of any number of 'toy' programming problems. >> > >> > Like the "bottles of beer" thing just posted, or maybe an iterator that >> > iterates through the days of week - the list is endless. One of the ways I judge a good exercise is by the ratio of: (effort to think of the solution) / (length of solution) It's particularly fun to work hard on a problem, but then finally see, by using just the right features of the language, how to write a short and straightforward solution. (The exact opposite end of the spectrum for me is having to process some data that's very non-orthogonal and full of special cases, where there doesn't seem to be any way to process it except by writing (often simple) code to handle each and every one of the numerous special cases. In this case there isn't much real brainpower-type effort, but the solution may still be large.) ABitCSoL> Iterators and blocks I'd have to say was the Ruby concept I had the hardest ABitCSoL> time wrapping my head around, and I'm still pretty sure I only have a basic ABitCSoL> grasp of what's happening. ABitCSoL> I think perhaps also I'm a little bit short on common Ruby idioms - what ABitCSoL> are some examples of iterators or blocks being elegantly used to solve a ABitCSoL> particular problem? ABitCSoL> That's about it really, thankfully much of Ruby is blissfully ABitCSoL> straightforward :) I'm especially interested in exercises using features of Ruby that aren't found in some other programming languages. Someone once commented on the tendency to write programs in a new programming language that look like your last programming language, and exercises involving these new features seem to be a good way to avoid this. One of these features is closures. Years ago a friend who was an expert Scheme programmer told me that there were problems he could solve easily with closures that would be very difficult to do in a language without closures. (But he didn't give me any examples.) Also, it seems that Ruby's elegant structure of classes, metaclasses, singleton methods, being able to add methods to existing classes, the fact that class definitions are executable code, etc., etc. should enable really elegant solutions to certain problems. It's just that I don't yet know what those problems are. Thanks, Wayne