Sunday, December 17, 2006

The development environment

Get a Mac
I started working on the first apps with a Windows machine. It was OK, I could get going, but none of the tools suited me. I rationalized that if I was going to go on this Rails trip, getting there would be half the fun at least. So I was going to ride in style. I got a 15" Mac Book Pro, a 24" LCD and I was ready to rock.

Software
Next comes the software to use. I started with Locomotive and TextMate, but Locomotive pretty soon starts making you look too newbie. I was getting ready for downloading the source and installing. At first I was aprehensive because I am all about focus, and the thought of spending valuable time in sys admin setup instead of Rails learning was dangerously derailing me. So I stuck it out with Locomotive until I got an app going. And I did.

Lesson learned

But given what I know now, I would have been served best by downloading the source and compiling it. I would have started with the setup I have today. And that is:

- Ruby 1.8.5
- Rails 1.1.6 (or edge rails if I feel like playing around)
- Mongrel
- MySQL
- Terminal (mulitple windows -- more on this later)
- TextMate

TextMate is nice in that you have nice syntax coloring and other items. I do not like the slow search, but I am getting to the point where I do not need to constantly search across files -- less code refactoring :).

Terminal
Given that there is really no IDE environment for Rails yet (not one that suits me anyway), you end up having to rely on the Terminal window quite a bit. Whenever I am coding I have four windows up:

- script/console
- web server console (mongrel)
- breakpointer
- development.log tail -f

The script/console is huge for newbies. And I continue to use. Basically, you get the Rails environment in a console and can test things out to see what is returned, etc. A big one for newbies is the object.methods method. Also object.class. Between those two methods you stop pulling your hair out as to why something does not work. Maybe you have the wrong object, maybe that object does not support the method you wanted.
Anyway, I can not say enough about the script/console. Have it running always.

web server console is nice to have. I would not run mongrel in hidden mode. Warnings, some mailers, and other activity shows up. The warnings are good as they help you quickly see something that you might want to clean up in your code.

breakpointer
When everything else breaks :) use breakpoint() in your code, hit the web page URL and watch for irb to kick in in the breakpointer window. There again you can evaluate variables by typing them (no IDE remember), or you can put several breakpoint()s in your code and press control-D to move to the next breakpoint. Then you can evaluate more variables as you move through the code. By evaluate, I mean, type the variable or object.method on the irb screen and see what comes back. Even the object.class, or object.methods gives you an indication if you used the wrong object to begin with.

development.log
by tailing the development log, you get to see what is actually being sent to the SQL server. It is interesting to watch how Rails translates the stuff you enter into SQL. Sometimes, you pass conditions that you think are OK, but forgot the previous filters you might have put on the object. Anyway, it is another debugging tool and another way for you to learn what is happening behind the scenes.


That is it for the development environment. You need a good dev environment and a whole library of books. I am not kidding when I said I bought them all. I even found a couple of books on Amazon that are not yet out but I ordered anyway. Nothing like reading Ruby and Rails from different authors' perspectives. But books review and opinions will be my next topic.

No comments: