Wednesday, February 24, 2010

Creating UI's with Ruby

I began with Ruby years ago by writing scripts to help me test a web app. I used WATIR for that. I will likely write more about Watir another time.

It took me a while to figure out how to write and structure the scripts using whatever examples I found online. It wasn't until I read Brian Marick's "Everyday Scripting with Ruby" that I really understood how to structure a ruby program. Excellent book by the way - I highly recommend it!

Over the years I accumulated quite the army of command-line programs/scripts and one thing I've wanted to do was figure out how to put a pretty UI/front-end on some of these scripts.

Apparently with Ruby, you have a few different options - TK, FXRuby, Shoes, etc.

I decided to settle on FXRuby since it's the only one that happens to be supported out-of-the-box with a clean Ruby install. (Watch, I bet they'll remove it from a future distribution/release now that I've said that.)

FXRuby is kind of neat. The main home page has some good documentation and examples to help get you started.

I was able to easily create some simple apps, but then it gets kind of tough. Working with FXRuby reminds me of the time I took a course in Japanese, some 20 years ago. Nice language. I picked up the alphabets, sentence structure and syntaxes and some of the vocabulary. I got the basics but just couldn't piece together big sentences/conversations. It just got too complicated for me. I suppose if I'd gone to Japan or had more opportunity to practice that it would have gotten easier, but I didn't and it didn't.

FXRuby's like that. Looks simple on the surface, but make no mistake, you need to know how to program to piece together a working app! The examples are helpful, but what I want to do is somehow always a bit more complicated than the available examples. Sigh. If only it were easier to pull together a UI for such a friendly programming language.

I discovered foxGUIb a few days ago. That tool really helped me figure out the relationships between the various layout styles and elements to bring together a UI. Unfortunately, I don't think I can use the code it generated, so I now have a pretty prototype with no working code underneath.

Oh well. Here's hoping that with practice it will get easier to do this sort of thing. I've browsed all of the available GUI toolkits and they're all the same to me. They start off with easy, Ruby'ishly-simple examples that try to hook you - then "WHAM!", insert programming jargon, hooks, classes and structures and "voila! there you go." Easy as 1, 2, googolplex.

Ruby I like. All of the available toolkits to help you build UI's still seem very programmerish to me. Not cool.

5 Chapters of O’Reilly’s Ruby Best Practices – Free!

Came across a tweet today:
zeljkofilipin 5 Chapters of O’Reilly’s #Ruby Best Practices – Free! http://bit.ly/aFhTcE

Of course, I followed the link and discovered the RubyInside web site... and that yes, O'Reilly has made the first 5 chapters of 'Ruby Best Practices' available in PDF form online for free.

I browsed them. Boring. Way to suck the life and passion out of a fun and cool programming language.

I've collected a bunch of Ruby ebooks in PDF and CHM (Windows help file) format in my travels over the last few years. I haven't read a single one of them. Or rather, the benefit (for me) is in helping me do a quick electronic search through the text to see if there's something that will help me with whatever current programming problem I'm working on.

I have a few books (sorry environmentalists, but I still prefer paper) that I use for reference and have a few that I still plan to read, but in general I've learnt programming by doing it. Which is to say that I don't really know how to program so much as do creative and well-documented hacking. ;)

I've got more to learn, but only as much as I need to learn to complete whatever projects I'm working on. I'm not a programmer by trade so I will defer to the experts when I need to get some real work done. God bless online forums! =)

Cheers!