Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Wednesday, May 21, 2008

Making TextMate really dance with PeepCode

Since I've been learning Ruby on Rails I decided to take a step back and become as proficient as possible with TextMate. For those that don't know about it, TextMate is a fantastic editor available exclusively on the Mac platform. What makes it such a great editor is not that it has a wonderful editing surface or is able to save files faster than some other tool - from that standpoint it's not really all that different than TextEdit.

What make TextMate so cool is that it provides some great extensions - called Bundles - that can help you use it much as you might an Interactive Development Environment (IDE) in a complete development package. You can either create your own Bundles with language templates and helpers or you can choose from a large array of different Bundles that are freely available for TextMate.

There is a very good Ruby on Rails bundle that actually ships with TextMate. It has a number of features that can not only make quick work of class and definition tasks but can also run many of the scripts that help you build Rails applications. It really does turn TextMate into a powerful IDE for Ruby on Rails.

The challenge is learning all of these little shortcuts. You could literally spend days doing nothing but walking through all of the menus that are provided, trying to learn how it all works. It can be a bit overwhelming and lead you to just use TextMate as a simple text editor - but that's such a waste.

PeepCode Screencasts to the rescue
Travis Jeffrey commented in one of my earlier RoR posts that I should take a look at PeepCode's screencasts to help me learn Ruby a little more quickly. What they sell at the PeepCode site is a series of screencasts that not only can help you learn Ruby on Rails but also all of the TextMate extensions. At $9 a pop I figured I would give it a try.

The TextMate screencast is nicely produced and runs through virtually all of the features of the RoR Bundle. The pace is very fast and at times it can be a challenge to keep up - when I ran through it I kept one finger near the Pause (F8) button because I was either taking quick notes or trying out the keystrokes in a TextMate window.

While this sounds like a complaint it's actually a compliment. With the pace being that quick you can learn a lot in a very short period of time. I didn't find myself losing interest in this, even though the run time on it is just over an hour long. I already feel that I'm going to be much more productive after just running through it once.

Some times you can't appreciate the power of a tool until you've seen it in action under the hands of a professional and TextMate with the RoR Bundle is one of those.

Update Your Bundle Before You Watch
I learned the hard way that the RoR Bundle that ships with TextMate is a bit dated and does not leverage all of the Rails 2.0 enhancements and as a result does not match up with the Peepcode screencast. Before you try following along with this video you will need to run through a couple of steps:
  1. If TextMate is running, close it.
  2. Visit RailsBundle.com and download the latest RoR TMBundle file.
  3. The file is compressed - opening it will result in the creation of a Ruby on Rails.tmbundle file.
  4. Open that file - you will be asked by TextMate if you want to update the bundle. Click Update.
That's it - you will now have the latest Ruby on Rails bundle and it will match up with the examples in the screencast. You will also want to make sure that the scope for TextMate - which is at the bottom status bar just to the right of the column counter - reads Ruby on Rails.

One Last Little TextMate Tip - The To Do List Bundle
Most programmers love to document things that need to be optimized or repaired by placing small comments in their code. TextMate has a Bundle called TODO that will open a small window and display an organized list of items marked with comments containing TODO, FIXME and CHANGED. You can add more of these with standard regular expressions and they will be presented in your list. You can then click on the link provided in the list and jump to that point in the code.
If you are using TextMate as a glorified text editor do yourself a huge favor and take the time to learn the extensions for your language or file type. This is one of those things that will give you a huge return on your investment.

Sunday, May 11, 2008

Finding a new way to learn Ruby on Rails

I'm about a week into my learning experience with Ruby on Rails and have encountered a few challenges and also found a couple of resources I'd like to share with you. As with most "as you go" experiences, these blog entries are a point in time picture of where I am so I haven't gotten all of this figured out just yet.

My model for learning
In recent years when I adopted a new language or development environment I would simply breeze through the documentation and especially the tutorials. I figured, what the hell, I'm a developer with over 25 years of programming experience. I'm well versed in object oriented principles, design and coding practices, etc. This won't be hard!

The reality is by simply scanning over the tutorial information I was doing myself a disservice, learning a surface level knowledge of the development model. I would pay the price when I would start to do my actual application development work, making my mistakes in my real code. I also had a bad habit of only learning the areas of the language and development model that were appropriate for me. I nearly always had an idea for a product or application I wanted to build when I started my learning experience with new development tools and I focused all my energy on the areas where I thought I could use the tool set.

In this day and age of instant information and the easy accessibility of things like FAQs and solutions for technical problems, I want to take a more disciplined approach to learning both Ruby the language and Rails the framework. I think this should work really well for learning Ruby on Rails because the framework is so targeted. I don't have to weed through information that is specific to building client side applications or learning models that were designed to service both web and Windows based applications.

Applying this to Ruby on Rails
Learning from the Agile Web Development with Rails book has actually been coming along quite well so far. I decided to stay with Rails version 2.0.2 and just suck it up. At page 67 of the current version of the book the examples start to break down. What I did was break from the book at this point and started using Sean Lynch's excellent 2.0 tutorial, which uses the same application as the book except it's updated to work with 2.0. Once I finished Sean's tutorial I had the basics of the Depot application that is used in the book and have been able to follow along much more easily.

This has actually worked out really well for me because it has kept me fully engaged in the learning process.  I'm still not completely comfortable with where code should fall in the Model-View-Controller system that Rails uses having come from the event driven code model in .Net; what's in the model and what's in the controller requires a little more thought on my part than I would like. My personal goal is to make that determination a no-brainer.

Learning Ruby vs. Learning Rails
One thing that threw me at first when coming into this technology fresh was what the difference was between Ruby and Rails. Well, Ruby is an object oriented language and Rails is a rapid application development framework that uses Ruby as the language. So do you have to learn Ruby to be truly proficient with Rails? You have to know the basics for Ruby in order to really absorb what's going on with Rails as you learn it, otherwise seeing :name, @name, @@name and just name are going to confuse the hell out of you. Class design in Rails is very easy and intuitive for me coming from a C++ / Object Pascal / C# background, though there are some very clear differences. It's the syntax that trips me up and at this point in the learning experience I'm doing a lot of "Oh, that's like... in C#".

When I bought my copy of Agile Development with Rails I bought the book everyone recommended to learn Ruby called Programming Ruby. Also referred to as the Pickaxe Book because of the picture of a Pickaxe on the cover, Dave Thomas does a nice job of walking the reader through the Ruby language. I decided that rather than go through the entire Ruby book first, I wanted to play with Rails at the same time to get excited about the environment. What I did was scan through the Ruby Tutorial in Appendix A of the Agile Development with Rails book to pick up the basics and then worked through the first 8 chapters of that book.

At this point I have a pretty good basic understanding of the Ruby language and syntax and more importantly a fairly functional application that gives me some hope that Ruby on Rails will be a good platform to build on. Now properly motivated I'm switching over to the Programming Ruby book to learn more about the Ruby language.

My goal at this point is to become proficient enough with Ruby that I start thinking inherently in that language, not translating mentally from a different language (in my case C#) and transferring that knowledge. Once I feel like I'm at that point - hopefully very soon - I'm picking the Agile book back up.

Friday, May 9, 2008

Playing with Ruby on Rails

I've had this on-again, off-again experience with Ruby on Rails. For those of you that don't know Ruby on Rails is a really simple framework and model for building Web applications very quickly and easily. This is not new news and in fact Ruby on Rails has gotten some very significant attention. As a Microsoft guy for many years I simply glanced in the direction of Rails and said "meh". I was immersed in the Microsoft development tools for so many years I wasn't willing to look very hard at things outside my .Net / Visual Studio / C# comfort zone.

My positive experience with my Mac switch led me to rethink that strategy, or at least give it a much better try than the quick glances I gave it before. I did a lot of research, found a lot of information and have found lots of controversy as to whether there is a future in Ruby on Rails. I've also found lots of evidence that some pretty large sites are using Ruby on Rails for their projects. In spite of all that I am in the early stages of really pushing it and so far I like what I see.

The initial challenge was setting up the right build environment which included a MySQL instance and several other components. I struggled with it at first because it was so difficult to deal with, hence the off-again part of the experience.  Part of the challenge was that Ruby on Rails (RoR) was in a transition from 1.2 to 2.0 and there were some significant changes to the framework. I started playing with Rails before most of the help and assistance information was updated to reflect the new 2.0 version.

A few weeks ago I came across a post on the Apple Developers site that walks through what's required to actually get Ruby on Rails 2.0 set up and running on Leopard. Turns out I was using 1.2 instructions for getting Rails up and running and the release of 2.0 switched to use SQLite3 as the default development database engine. If you have ever entertained the idea of playing with Rails and you are running Leopard, check out that two part post. It's really easy to follow along with.

One of the things that Apple did and documents in that post is allow you to use Xcode to manage your Rails project. While I found the environment to be pretty cool I liked the editing surface in TextMate, which also has pretty good support for Rails constructs and Ruby code.

In addition I went out and purchased a slew of books that I figured would help me in my education with Ruby the language and Rails the framework. I'll list some of these in later posts as I form more of an opinion on them. One word of caution though: If you just run to Amazon like I did and buy Agile Web Development with Rails you will be disappointed. Not because it's a bad book - I like the style - it's because the book's tutorial does not work with Rails 2.0. They are selling a PDF version of the new book that is supposed to come out in October that will have a tutorial that actually works. 

In the mean time if you want to give Ruby on Rails a quick spin on your Mac you should follow those Apple Developer instructions I linked to. Here are a couple more that may get you started and help get some perspective on Ruby on Rails:


Much as I have done with my Mac experience, I hope to share some of my learning process about Ruby on Rails as I go along, from the perspective of a .Net / C# / Visual Studio guy. I know I have a fair number of readers that are using Visual Studio now on their Macs so hopefully you'll get some value out of this.

Who knows though - it may be a very short series if it doesn't go well.