Showing posts with label learning Ruby. Show all posts
Showing posts with label learning Ruby. Show all posts

Thursday, September 04, 2008

Ruby and V8

Summer is drawing to a close and many of the things which have distracted me from my blog are becoming less pressing, so it's about time for me to crank this back up — we'll have to see how well I keep up with it. Of course, there are a lot of exciting things on the horizon that are prompting me to write. One of the biggest is the release of V8, the JavaScript VM that's part of Google's Chrome. Over on the Strongtalk list, David Griswold wrote:
I still think it or some derivative will quickly become the dominant dynamic language VM, for the following reasons:
  • Given who the developers are, and with Google behind it, it will be the fastest JavaScript VM for a long time to come.
  • For the same reason, it will be reliable and secure (as much as it can be, anyway; nothing is perfect).
  • It will be supported on the three major platforms (Windows, Linux, Mac).
  • It can be used with other browsers, so I'm sure it will be ported to Firefox (if only as an option). Some or all of the other browsers may also adopt it, given that it will have a very hard-to-overcome performance advantage (these sorts of VMs can't be pulled out of a hat). Although MS and maybe Safari may have too much of a Not Invented Here problem with it, as well as standards war issues.
  • those things, plus the other architectural advantages it brings, will make it a primary target for serious web app development, esp. Google apps.
  • So it will be ubiquitous
So it will be an irresistible platform for other dynamic languages, even if they could theoretically run a bit faster on a custom VM. Remember it will still be a lot easier to run other dynamic languages on JavaScript than it is to run them on Java, since at least JavaScript is fully dynamic, unlike Java.
I'm not the language guru that David is, but I not ready agree with him yet. While JRuby is showing good progress at creating a fast, stable Ruby implementation on top of a non-native VM, I don't think we've seen what a native, tuned VM for Ruby can really do. I'm also not sure we'll ever see Ruby's community turn away from their own VM (be it Rubinius or the 1.9 VM) for the 'standard implementation'. This doesn't mean that V8 is without value to the Ruby community though. Again, David Griswold:
The V8 development team has multiple members of the original Animorphic team; it is headed by Lars Bak, who was the technical lead for both Strongtalk and the HotSpot Java VM (as well as a huge contributor to the original Self VM). I think that you will find that V8 has a lot of the creamy goodness of the Strongtalk and Self VMs, with many big architectural improvements:
  • open source
  • will run (eventually) on Windows, Linux, and Mac
  • dynamically JITs to native code
  • can run completely independently from the browser
  • generates hidden classes behind the scenes, since javascript doesn't have them (very reminiscent of the 'maps' used in the Self VM).
  • is multi-threaded from the ground up, with the ability to share VM overhead between different OS processes.
  • has even smaller object headers than in Strongtalk, making small object overhead even smaller
  • kick-ass compacting, non-conservative garbage collector
Whether Ruby ends up on V8 or not, I'm guessing that some of V8 will end up in Ruby.

Wednesday, January 23, 2008

RubyZone, RailsSpace, and Ruby DVDs

dZone has recently introduced a set of ‘zones’ with original content, forums, and other things about specific topics to compliment their social bookmarking site. One of these is the RubyZone. I’ve been asked to work as a ‘Zone Leader’ there, writing new material and helping build the community. Even before I’d gotten there someone else had written some material, a review of the book RailsSpace: Building a Social Networking Website with Ruby on Rails.

Since there are a lot of people who can do a better job of reviewing Rails books, I’ve been trying to stick to pure Ruby (or other non-Rails) books recently. But I feel like I should point out something about this book. Addison-Wesley is moving their Professional Ruby Series beyond books and ‘digital shortcuts’ and into video with the release of their RailsSpace Ruby on Rails Tutorial

I’ve lent a copy of this to a friend from church who’s just getting started with Rails. Every week now, he comes up to me and tells me how wonderful Rails is and how excited he is to be working with it. The DVD contains over 5 hours of video spanning 15 tutorial sessions. Judging from my friend’s response, I’d say that this video is a great way to get started with Rails.

Thursday, January 17, 2008

Interview with Sander Land, Developer of charlie

Sander Land recently released charlie a Ruby library for using genetic algorithms. Since the initial release, he’s made several updates, and posted some performance information for charlie on Jruby 1.1 RC1. I was intrigued by the activity, and asked Sander to join me for a quick interview.


Why the name ‘charlie’?

Sander It’s a reference to Charles Darwin. The name was originally the project’s code name, and it just stuck.

Everything I know about genetic algorithms, I learned from wikipedia. I’m guessing a lot of other people are in the same boat. Maybe you could help us all out. What are genetic algorithms?

Sander Wikipedia is not a bad place to start:

“A genetic algorithm (GA) is a search technique used in computing to find exact or approximate solutions to optimization and search problems. Genetic algorithms are a particular class of evolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance, mutation, selection, and crossover.”

The basic idea is that you have a population of solutions, and some kind of fitness ranking. You select solutions such that those with higher fitness (on average) get more children. This makes the solution converge towards some local or global optimum. Crossover and mutation are used to generate more variation in the solutions, so it can explore new parts of the search space.

There are a lot of ways to do selection, crossover and mutation. The basic idea behind charlie is to make it easy to choose these parts, and to be able to compare several of these strategies to see which works the best.

Ok, so what are they good for?

Sander As wikipedia says “optimization and search problems”. That is, any time you need to optimize something or when you can restate your problem as optimizing something. Examples are finding a shortest cycle through a graph, or finding the airplane wing with the most lift.

A big advantage of GA over other optimization algorithms is that you only need a simple representation of your solution (usually an array of floats or a bitstring) and a fitness function which returns a higher value for better solutions. There’s no need for calculating derivatives or knowing specialized algorithms for each problem.

So, is delta1 a good example of the space that GAs play in?

Sander It’s not a typical example, but it’s probably possible:

  1. Take a bitstring of length (# of lines in original file) as your genotype. Use zero/one at position i to mean “solution does (not) include line i”.
  2. Take 1/(# of ones) as the fitness value, but assign a value of 0 to uninteresting files.
  3. Initialize all your initial solutions to all ones.

The problem is hard to solve with GA because you’re forcing the uninteresting files to have a fitness value of zero. There is no way to tell ‘how uninteresting’ the file is. This makes step (3) a necessity, instead of being able to use the standard random initialization, because otherwise you would most likely start with a population of uninteresting files and no way to determine which are the better solutions. It also has a negative effect on the convergence of the algorithm, because every small mistake, even when combined with an improvement somewhere else, is going to result in an fitness of zero.

To get back to my earlier, more typical, examples:

  • All cycles through a graph will have some length.
  • All wing designs will have some lift force. This could be negative, but even in that case you can tell ‘how wrong’ the solution is.

What needs did you have that made you write charlie?

Sander I had used GAs a few times, using a ~250 line Ruby script which was rather messy (think global variables with a hash of several procs of 5+ lines each). I wanted to make a library which was a lot cleaner and easier to use, but without restricting what genotype/selection/crossover/mutation I could use. I also wanted to learn more about genetic algorithms and genetic programming, and thought writing a library would be a nice way to do this.

Finally, when using a GA to solve a problem there was always the question “which settings are the best?”. Most settings work reasonably well, and it can be hard to determine whether some are actually better, or just ‘lucky’ the single time you tried them. Hence the focus on benchmarks to answer these questions.

What books/websites would you recommend for learning more about genetic algorithms?

Sander This website has some basic info and a lot of links to news articles, tutorials, etc.

A simple google search for “genetic algorithms tutorial” will also give some decent results, but reading a book is probably the best way to learn more about GA.

Some of the examples included with charlie are from “Evolutionary Computation for Modeling and Optimization” by Daniel Ashlock. He has the book on his website.

Is Ruby really a good language to do things like this in?

Sander I think so. Ruby certainly makes it easy.

As for performance issues, the fitness function is often the bottleneck for more complex problems. Because you always need to implement this function yourself, it is easy to increase performance by writing this in a lower level language.

Another issue is parallelization. This is not yet implemented anywhere, but I have something planned for multiple parallelly evolving populations (multi-deme GA). I’m not sure how difficult it will be to do this.

Wikipedia talks about a number of programming methods related to genetic algorithms, do you see charlie growing to encompass any of these, or do we need to look for other libraries (and other developers)?

Sander Some of those programming methods, like Evolution strategies and Evolutionary programming are very similar to GA, and sometimes even nearly indistinguishable, so they are easy to fit in a GA framework. A basic form of Genetic programming is already implemented, as there is a tree-based genotype. I definitely plan to extend charlie to encompass more GP techniques, and to try some selection and crossover techniques more common to ES and EP.

I currently don’t have any plans for extending the library to methods that are not similar to GA.

What have you learned about Ruby while writing charlie?

Sander Not much, actually. I’ve been programming in Ruby for more than two years now, and picked up most of the metaprogramming skills needed for this library from reading blog posts and making ruby quizzes.

However, with this being my first ‘large’ project, I’ve learned how to use rdoc, rake, hoe and other tools.

How did you end up picking up Ruby as a programming language?

Sander I was looking for a new programming language, because using C++ or PHP for everything was inconvenient. I first tried python, which was interesting, but somehow not interesting enough to make me stop searching. A few days later I tried Ruby. With the pickaxe included in the installer it was easy to learn and I liked its consistency. Within a week I joined the ruby-talk mailing list, and made Ruby my language of choice.

You were one of the first people to post benchmarks for JRuby 1.1 RC1. How much work did it take to get charlie running on JRuby?

Sander No work at all, all my tests succeeded on the first try. Again, great job JRuby team.

Does charlie run on Rubinius or 1.9 yet?

Sander Ruby 1.9: Yes, as of version 0.6.0 there is partial support, and the recently released version 0.7.0 has full support. This required a few workarounds, since there is still a rather nasty bug in 1.9 which makes superclass lookups fail in some cases. (note: The bug is reported here.)

Rubinius: Just tried it. Over 50% of the tests fail, so I guess that’s a no. But Rubinius’ performance is probably still too low to seriously consider using it for this kind of application.

What’s the coolest thing that someone’s used charlie for thus far?

Sander I don’t know! Except for you mailing me for the interview, and some people telling me they were going to check the library out, there has been no feedback at all.

What plans do you have for charlie?

Sander I have some additional features planned, like extra crossovers and genotypes for 2D arrays. I also plan to learn more about genetic algorithms and genetic programming, and include more features in the library as I learn about these things.

1Delta assists you in minimizing “interesting” files subject to a test of their interestingness. A common such situation is when attempting to isolate a small failure-inducing substring of a large input that causes your program to exhibit a bug’

Tuesday, December 18, 2007

Satish Talim'sNew Ruby Class, and an Interview

Satish Talim has announced another round of his beginning Ruby class, which is great news for the Ruby community. I wanted to learn a little bit more about this opportunity, so I tooks some time to interview three former particpants: Marcos Souza, Chris Porter, and Michael Uplawski. Here’s what they had to say:


How did you hear about Satish’s Ruby class?

Michael I have been a fan of Paul Lutus’ Web-Site for a long time, but until recently had ignored his Ruby-pages. As I was looking for a way to turn programming into a hobby once more and to gain back a bit of the fun, I finally read Mr. Lutus’ recommendations, then plaughed rather aimlessly through the web. At the time, I was experimenting with, then disappointed by the language ‘D’. The appearance of Satish’s site and the way, he introduced to the course made me rest longer than just a few minutes.

Eventually I thought I could give Ruby a try. I checked back on Paul Lutus’ page, but there is no mention of rubylearning.com. So it was rather accidental, that I was finally glued to Satish’s class.

Chris I saw it announced on a blog, Ruby inside.

Marcos I have a previous experience on a web class in the past, so when I came to Ruby, googled with “free ruby course” and find it on the first line (lucky me!)

What made you decide to sign up for it?

Marcos First, I try the web tutorial and like the objective and direct style, then the next interest become a PDF version of it. To get it we need to sign up …

I read the eBook version and do all the exercises just in one month.

Then I start a review process with the class.

Chris I had been meaning to learn Ruby after seeing some great screencasts on Ruby and also Rails. I thought about just reading Pickaxe but when I saw this I thought it would be a interesting to try a different approach. I liked the idea of having a course structure and a teacher to ask questions to so I thought I’d give it ago.

Michael The idea of learning the basics without being pressed to arrive at some specific objective convinced me. I was about 70% certain, that I would break up after a few days (which I do now, but this is due to different conditions and I will be back in January, latest).

Tell me how the class works.

Chris Each week or so Satish posts a new lesson which comprises a couple of pages of his online tutorial, a short review of that material and a couple of problems. You work through the tutorial and post your solutions and any questions in the thread. Usually there is discussion amongst the group about certain issues or grey areas and people post their own problems or links to other pages on the web.

Marcos That’s the best part: each one propose different answers, we agree, disagree, discuss, and refactor some code… That is really cool. And we learn a lot this way.

Michael When I signed-in most of the lessons had already been published. I just read Satish’s tutorial, most of the time online on the web but sometimes also the PDF-version. There are assigments, a few scattered on the pages and the final assignement, you have to solve at the end of a lesson. The solutions are published on the rubylearning.com Forum, where Satish arranged for one thread per lesson. You just attach your new solutions to those, already published.

You get additional insight by reading the code of the other participants. Questions are asked right on the spot if they concern the current lesson or result from the code fragments published.

Whoever can, will contribute to clarifying the points at issue, but discussions may deviate. Satish himself gives hints to either solve a problem or to improve the code, that we handed in. Frequently references to other sources on the web are made, where an individual aspect of Ruby might be dealt in detail.

What was the most important thing you learned from it?

Michael Ruby is fun. It is a language, that you can use for fun. Why this is so, I can guess and maybe derive through my experience with using C/C++ and Java. Ruby, as any other “new” language, combines the comforts of more established languages and lacks some of their defects.

Marcos In fact I confirm that this is the best way to learn something. To get the best results you just need one action be: PARTICIPATIVE

Chris I learned that there is always a better way of doing things, especially in Ruby ! People would post solutions to problems and others would add their own solutions or improvements. It’s tempting to write Ruby just as you would in your previous languages but you can often find a simpler or more elegant solution if you utilise some of the unique language features.

Are there any books or tools you learned about because of the class that you just can’t live without today?

Chris I love noobkit: http://www.noobkit.com/ and made good use of Aptana. I got some good recommendations for books but I haven’t read them yet.

Marcos I’m reading Ruby By Example (by Kevin Baird), a brief overview exercise.

MichaelI have not bought any book on Ruby, yet. In contrast to what was said somewhere else, the bookshelves in our shops are not crammed with literature on Ruby. I have learned from bad experience, that I need to touch a book and gallop through some pages, before I buy it. Recommendations from the web are nice to pick a few from the bunch, if there were any…

It sounds like you all liked the interactive parts of the class. Where there parts you didn’t like?

Michael This is a rather inconvenient question. I never thought about it and rather took the course as something coming along unexpectedly, put another way: a completely positive experience by nature… Would I like parts of it improved or changed (if you don’t mind)? Part of the quality, which we find in the forums, we achieve by meeting on the same level of (un-)experience. Good ideas and sometimes downright /solutions/ are really developping in the community or in private but may always be inspired by the discussion, be they amateurish all the same.

It would be an improvement, if we could collect these solutions or situations, which occured in the forum and have someone present us one immaculate piece of code, as used occasionally by the masters of Ruby, themselves.

Chris Well it’s hard to criticise a free course but .. ! I would have preferred it if more or less everyone was on the same lesson at once. That might have made some of the discussion livelier though I understand that people should go at their own pace. Satish usually covered everything in the lessons in a remarkably concise way, one or two maybe could have been a bit longer.

Marcos The common forum format admits participants create topics, lots on the same subject… Sometimes it makes difficult to locate information. I think the new format could fix this.

If Satish were to announce a new class for 2008, would you rather see him put together a more advanced Ruby class or an introductory class for some other language (which one)?

Chris I think an advance class would be great and the same format would work well for Rails too.

Marcos I will focus on Rails next year… If Satish include a “basic Rails class” I’m IN for sure!

Michael Two questions, really, maybe three.

1. Languages: Python, D, Ada95 (what, if not my own favourites).

2. Advanced Ruby class: Of course, I would like to plunge deeper into the topics which have always been facinating: Sockets, general hardware-control, implementing and combining a few Design-Patterns in Ruby..,

3. Would I like to see: NO. Satish did a great job with the introductory and the beginning advanced lessons on the language-core. There is but one authority, who can decide about how this work could or should be extended: Satish Talim. I am a little afraid, that adding too much contents or attaching completely new topics to his teaching-project will have it deviate in the end. As you address me directly with this interview: I want to learn Ruby. Full stop. That is why I came to rubylearning.com in the first place. I do not want the ambience of the site altered. Everybody else will have a different opinion. Mine is this.

Why would you recommend someone else take the class?

Michael If you are looking for a way to just learn Ruby, I can tell you, that Satish Talim is a great teacher. Chosing his free (like in free) course to learn the basics, is a most intelligent move. See, I did it. ;-)

Chris Definitely, it’s good to be able to talk with other learners as you go and Satish’s tutorials always cover the topics in a concise and easy to understand way. I think I learned more quickly and understood it better than had I done it on my own.

Marcos Just that. I really think that is the best way to learn.