Code Snippet: Fibonacci with IronRuby & WPF
Posted by Ryan Baxter Thu, 26 Jul 2007 04:28:00 GMT
On Tuesday, John Lam announced the Pre-Alpha Release of IronRuby. To satisfy my curiosity, I downloaded and compiled the source code found on his blog. A simple Build.cmd file was provided and made the compilation a breeze. Rather than write another Hello World, I decided to kick the tires by writing a simple application to calculate Fibonacci numbers. I didn’t use many of the niceties that make Ruby what it is, but I did, however, uncover some oddities between Ruby and .NET types. I coded around a few of the problems only to find other features that were either broken or missing. The release was labeled “Pre-Alpha” for a reason so don’t be surprised if you have a similar experience with IronRuby.
I have to admit that I felt a bit dirty hacking together bits of the Windows Presentation Foundation (WPF) with Ruby only to achieve a single, ugly window with one text box, some words, and a button. It wouldn’t have been so bad if only I could have managed to use the .NET HorizontalAlignment enumeration with the controls on my window. Every effort I made in aligning a control caused an Exception. Defining the Orientation of my StackPanel also resulted in an Exception. Taking input was easy. Performing validation on the input was not. I could not get a string comparison to work between .NET and Ruby string types. I tried a half dozen combinations of .ToString, to_s, and Convert.ToString with no success. I gave up and wrapped my problem expression in a begin-rescue block.
begin
fibonacci_label.content = fetch_iterative_fibonacci(Convert.ToInt32(input_text_box.Text)).to_s
rescue
MessageBox.show('Please enter an integer.')
endIf Microsoft creating their own implementation of Ruby isn’t interesting enough, John Lam has said that IronRuby will be hosted at RubyForge. His reason for this is simple. John believes that Open Source developers have more experience using Subversion rather than Microsoft’s Team Foundation Server. I agree and believe this decision will only benefit IronRuby by involving the whole Ruby community. This will most likely cause those non-Microsoft developers to contribute who otherwise wouldn’t if the project were hosted at CodePlex. Check out episode 254 of .NET Rocks! for more on this and John Lam’s work on IronRuby and the Dynamic Language Runtime.
I am not disappointed with the status of this release. Since IronRuby will be open for community contribution, the code will be reviewed by many eyes and the bugs that I did encounter will be fixed quickly. The integration of IronRuby and WPF was not pleasant, but I do believe that over time the two technologies could compliment each other nicely. The power of the presentation foundation combined with Ruby’s syntax sugar will undoubtedly make for an impressive stack that could give others a run for their money. Now can I have this in Mono please?
Both an iterative and recursive solution can be found within my source. I provided both in the odd chance that somebody reading this might want to try a rudimentary O(2^n) performance test between the Ruby interpretor and IronRuby. The source code for my Fibonacci example can be downloaded from the links below.
- Posted in Code Snippets
- Meta 2 comments, permalink, rss, atom
Knowing When to Unplug
Posted by Ryan Baxter Tue, 24 Jul 2007 02:38:00 GMT
If you’re a geek like me then this may sound familiar. Like you, I work the typical 8 hour work day at my “for pay” job. At home, my second job begins. Another 4-5 hours is consumed by one of my half dozen personal projects. An additional 2 hours is devoted to reading blogs and other online technical resources and about an hour is sacrificed for e-mail. When my wife and I have a commute that’s longer than 15 minutes, she drives so that I can read. Her only request for putting up with this is that I leave one night on the weekend for her. She’s a keeper.
Needless to say, I probably spend too much time online. Sustaining this lifestyle is not easy. I can keep this up for about three months before my body starts telling me to unplug. Some of my warning signs include:
- Insomnia – How can I not be tired? It’s 4 AM? Am I the owner of a soap company?
- Increased blood pressure.
- Irritability – I don’t really notice this, but my wife tells me that I can be “grouchy”. She tends to use more colorful words.
- Exhaustion.
In the past, I’d ignore the warnings and keep working until sooner or later I’d start falling asleep everywhere. I’d come home from work and sleep on the couch, or the middle of the living room floor, or even face down on my keyboard. It didn’t phase me much until my blood pressure started going up. Six months ago I began to notice a faint buzzing in my right ear. The buzzing grew louder and became persistent. It soon turned into a sort of rhythmic pulsing. I could hear my heart beating in my ear. Weird. At this point I decided it was time to take a break.
I don’t often take vacations. At former jobs, my vacation days would often accrue and I’d be forced to use them. I’d take a day off here and there, but I never had any planned vacations. A few weeks ago my wife and I spent a weekend with some friends. I had a great time and came home feeling recharged. My wife mentioned during the trip that she hadn’t seen me smile so much in years. You may have heard this before, but take a vacation. Get a life. Visit some friends. Just a couple of days is enough. Intentionally leave all mobile devices at home and don’t bring any programming books with you.
Try going to bed one hour earlier. I know this may be hard to do, but you can start in small increments and work your way up to an hour. Is that one hour before bed really that productive anyway? This has made me less ornery and more alert at 8 AM.
Get more exercise. Twice a week my wife and I teach a children’s Taekwondo class. I can tell you that lambda expressions are not at all on my mind when people are trying to kick me in the head. I sweat buckets in the Dojung. I often wake up feeling like I got a hit by a bus, but my mind is remarkably clear.
IANAD, but I can say that these things have worked for me.
- Meta no comments, permalink, rss, atom
New Section for New Software
Posted by Ryan Baxter Fri, 20 Jul 2007 16:12:00 GMT
I’ve added a projects section on the right-hand side of the site. Projects will appear here as they either become eligible for contribution or reach release status. Each project will be given a page containing repository URLs, dependency information, and other resources. I’m also working on a separate portal for project management activities and will make an announcement when that is available. Maybe YOU can help.
If you’re itching to try your hand at Rails or have a good sense of design, then you’re welcome to join. Experience isn’t a requirement. I’ll follow up with more information soon.
By now you’ve probably glanced at the new section and noticed a project called 1024px. 1024px is the magnificent theme you see displayed here on my weblog. If you’re a Typo user and you’d like to use this theme then check out its project page for download information.
- Meta no comments, permalink, rss, atom

