Ruby on Rails Kickstart
So the first public training is over now. I've learned a couple of things. I think this was one of the most difficult trainings I've ever been through – and even though it seems better after getting some distance there was definitely a few things we could have done better. What I really learned here is that even though Ruby on Rails is easy, it may be not so easy and really helps if you have a programming experience.
In any case here are the steps we covered in the first session. The whole point was to just get a basic scaffold running. There was a time I thought it was easy. I don't anymore :-).
- Install everything - here's one way to do it on Windows - it worked on most of the machines but not all. Things to watch out for: in few cases ruby bin dir wasn't added to the path, in others Mysql wouldn't start yet in others Apache wouldn't start. Most of it were XP machines but I guess there were differences. As pretty much all of our development is done on Linux and MacOS I just have more experience with those platforms.
- What you will need - 2 command prompt windows, text editor, mysql (or any other database) and browser
-
Create a directory for your applications - on Windows type this:
cd c:\ mkdir rails cd rails
and here it is for MacOS / Linux:cd ~ mkdir rails cd rails

-
Generate the basic application structure:
rails test
You should see a bunch of lines getting generated:
As a result you should be able to see the following directory structure generated:
-
Change to the generated directory and start the server to see if we're good to go:
ruby script/server
You should see something like this - confirming that the server has been started:
Now open up a browser and navigate to http://localhost:3000. You should see this page coming up:
To stop the server you can press Ctr+C. To start it again just press arrow up which should repeat the last command (i.e. ruby script/server). -
From now on we will be using the another command line window. Leave the server running in the first window.
-
Set up the database connection. The database connection parameters are set up in config/database.yml file. On most platforms it should be geneated properly,
but on some you may have to add the host: localhost line. At the end it should look something like this
-
Now we can create a new database. Type this in the second command prompt window:
mysql -u root create database test_development; create database test_test; \q
You should see something like this:
To verify that everything is okay run rake db:migrate and you shouldn't see any error messages. If you see warning about require_gem being obsolete - it's okay. -
Now we generate some basic model:
ruby script/generate model product

-
Create a Migration
I will get to the whole migration concept in some future installments - for now just open up db/migrate/001_create_products.rb and add the following lines:
class CreateProducts < ActiveRecord::Migration def self.up create_table :products do |t| t.column :name, :string t.column :description, :text t.column :price, :numeric t.column :image_url, :string end end def self.down drop_table :products end end -
Now the hard part - run the migration. Running the migration will make the changes in the database. You will HAVE to have your database as well as database.yml properly set-up, otherwise this won't work.
rake db:migrate
If everything went well you should see something like this:
-
Create a controller.
ruby script/generate controller products
Just like always, you should see some lines informing you about the files being generated. Here are the new files that got generated:
-
Now just add this line to the generated controller so that it looks like this:
class ProductsController < ApplicationController scaffold :product end
-
And here we are :-) Navigate the browser to http://localhost:3000/products/list and you should see this:
Go ahead and click on New and add a new product:
-
Now we've got the rice (or meat and potatos if you're from that culture) - now just make it look better. We'll add a very basic layout and some basic CSS.
Both of them are from the Agile Web Development with Ruby on Rails book examples. You need to create a new file under app/views/layouts/application.rhtml and add the following to it:
Get the Style Sheet Here
And here's the end product:

And that's all. Easy or not - if you can do this you will be able to do anything. If you were not able to follow or the whole darn thing just wouldn't work - let me know where you had troubles.
The First and Second Ruby on Rails Training in Singapore
It may seem like I have nothing much to do, but I volunteered for yet another cool initiative called code::XtremeApps:: competition. It's hard to say what was the main motivation – if the chance to promote Ruby on Rails or to promote software development as such. Either way – a nice challenge around here. Programmers in Singapore are generally in a very very low standing – possibly somewhere around a construction worker :-). The general position(ing) is that programming is a low level blue collar activity facing the same fate as manufacturing and should be outsourced to India, China and only “high level” jobs like sales and project management should be done here. While there's something to it, it's a little strange when most of the people I interviewed said they didn't really like IT and they'd studied computer science to become managers.
Considering this situation I couldn't believe the tremendous response this programming competition received. All our initial estimates were left far far behind – the number of participants for the competition itself, but even more for the accompanying trainings (both Ruby on Rails and Google Gadgets). The training capacity of 120 people was surpassed in less than 48 hours. As for the competition we had to almost double the capacity and as of today there's only a few places left. The training will be this Saturday 01/09/2007 – you can have a look at the agenda here. The training is specifically targeted at the competition participants. Unfortunately, we will have only 1 day and as the competition focus is on innovation and integration we will be mostly covering mostly more advanced topics like AJAX, mash ups and media integration. As such there will be only 3 hours to cover (or discover?) actual RoR framework. I will be doing this training with Choon Keat. It's been a great pleasure working with him as he's not only a great (RoR) programmer but turned out to be very helpful, resourceful and reliable in everything that needed to be done.
The second training is of a very different nature. It's much more in-depth – and much more pragmatic, focused on development of actual business applications rather then competition prototypes. It will be a 2 days training on 15-16/09/2007 and it will provide a much more intimate hands on experience. There's more information here.
The second training has been in the making for around a year now. I started working on it around the time I hit first difficulties when working with Changi Prison and I've been using and improving parts of it on pretty much all my one – to – one trainings. After writing the article about Changi Prison I received a lot of emails asking more about the experience, how it was different from my outside trainings and mostly about my motivation for doing something like that. Strangely enough, I had a strong dejavu experience 2 weeks ago – during the competition launch at SMU. The setting couldn't have been more different – yet somehow it brought back all my memories from my first trainings in prison. When I started my presentation more than 75% of the room (including me :-) was asleep. By the time I finished I don't think there was anybody there that wouldn't want to learn more about RoR or at least try it out. And I guess that is the answer. It's the energy of the people in front of you, their questions and their thirst for more. It's the transformation they go through learning from you and it's the transformation you go through learning from them.
And as much as it is a motivation – it's a responsibility.
Corporate Trainings 1
I finished my first commercial Ruby on Rails application in October 2005 and I've been using it ever since. For most of this time, we've been one of the very very few offering Ruby on Rails in Singapore. Most of our customers are not exactly technical so they wouldn't really care even if we used Cobol :-). What they did care about was the price and delivery time. I don't know why, but writing about advantages of Ruby (and Ruby on Rails) comes very unnatural to me. It feels like saying what everybody knows. At the very minimum, most of the technical people have heard about it – whether they like it or hate it at least the don't go like “You're programming in WHAT???”
The situation seems to be turning even in this part of the world. Thanks to Ruby brigade I met a handful of Ruby on Rails programmers and a few handfuls of wannabes. After almost 2 years in isolation it was really great to see and meet Ruby programmers (other then my own trainees and employees :-). While all this was nice, what really made an impact was ever increasing demand for corporate training. More and more big companies approach me with corporate trainings. The reason is simple...as many are parts of global corporations, many of their internal systems were created elsewhere and now they need a local support. It may come as a shock that MNCs use other systems than just SAP, but it seems to be easier and way cheaper to use a few smaller, independent systems for handling a portion of daily operation.
I started my first Ruby course in April 2005 and for the past 6 months I spent roughly 40% of my time doing training. This has been a major shift for me as only as recently as 1 year back I spent around 90% programming and only 10% on other stuff. I started training in Changi prison and it's almost unbelievable how rewarding this experience has been. I cannot even describe how much the guys have changed. When I walked there the first time I sure saw the potential – around 30 guys doing (or more fighting) with every possible limitation you can think of but still determined to succeed. It may be an old truth that you will appreciate the value of something only after you've lost it but it's really valid. All of the ubiquitous things like Internet connection, access to new books, access to community support (reading the posts or posting questions) – all this is off limits in prison. And yet I didn't find any surviving broken existence in there. So many times I have wished my own employees showed half of the determination, zeal and persistence I could see in there. The more you have, the more you start taking things for granted and the more comfortable you become.
What I felt the guys needed was just better resources and some direction (IT wise). We went through some really tough time – I still remember explaining recursion for the whole Sunday, OOP, TDD and many other things. Well, none of them had any prior formal IT education. But then, maybe it was more to their advantage. Most of the time I find it much harder to work with computer science graduates than with people who never studied IT but have some logical and mathematical thinking. It's surprising how difficult it is to unlearn all the coding cowboy habits as opposed to just starting afresh. This is not to say that OOP or Ruby or design patterns or TDD or agile methodologies or anything else I do is the only way (or that it's correct at all). It's just one of the ways and the one I happened (in reality it took much more then just happen :-) to believe in – but more about that in my other blog posts. Anyway, it's really great to walk in there now. It's completely a different crowd – you see people being able to think, to analyze and to even transform all that into a working product. Sure it's not all wine and roses...but I would really like to see this kind of commitment in many other organizations I worked with.
I realized much of this when talking to people at one of the Ruby Brigade meetings. That's when I realized that I may be running quite a tight ship in regards to development principles – but so far I've really appreciated that nobody on my staff would say things like: “I do tests only when I feel like”, “I've never been into testing much”, “We do bug driven development”, “What's that 'assert' thing mean?” and many others.
To conclude with, I must say that I have always been an extremely fast learner – I've never had problem to learn anything but it's a completely different ball game to teach what you know. One thing is to look at something and understand it and a completely different one is to explain it to somebody else. And I really love it :-). And it finally gives me a reason to start working on my e-learning platform I've been planning since high school.
Top 10 Software Development Books for Beginners
This topic has been boiling inside of me for quite some time now. In fact, ever since I hired my first employee in my first job in Asia. I've been always reading a lot of books – even when I had no money I would spend Sundays in MPH or Kinokuniya :-). Even though I've had Safari Books Online subscription like forever (actually since my master's degree thesis) hardly a month goes by that I wouldn't buy a new book.
Anyway, my problem is to select a “reasonable” number of books for my new employees / trainees to read so as to give them essential (really basic and necessary) information and still not overload them to the point when the loose the sight of why they're doing it. Here I must point out that 99% of all people I've interviewed and around the same percentage of people I eventually hired had never read (and pretty much never heard of) any of my top 10 essential books. Most of those were computer science graduates from Singapore, Malaysia, Germany, India, Slovakia, Myanmar, etc.
The books to start with are especially tricky because of a different learning style for different people. Another issue is to avoid (or undo) possible bad habits. I may not be able to stress this enough...but this is realy not about book "reading". Our orientation process means working with those books daily - working out the examples, trying them in different languages and putting the concepts to work first on testing projects and later on real projects.
Put together, Top 10 that my employees / trainees have to bite through looks like this:
1) Test Driven Development by Kent Beck – this is definitely the first and the last book of software development for me. I think without this book made all the agile methodology possible and it pretty much defined way of programming today.
2) Learn To Program by Chris Pine - this is quite a recent addition – in May 2006 when it was clear that most of our development had moved from Java to Ruby, this book replaced Head First Java by Kathy Sierra and Bert Bates. It may sound a bit strange to include an actual programming book so early in the process but it sort of provides a tool or media for further learning.
3) Head First Object-Oriented Analysis and Design by Brett McLaughlin, Gary Pollice, David West - what the hack took you so long guys? This book finally filled in the spot shared by several books on OOP. Even though OOP has been a standard for more than 20 years I still find it one of the most difficult part for people to understand. I even like that the book uses Java for all the examples, because doing those examples in Ruby gives you plenty of opportunity to see Java and Ruby code side by side and to really see the differences between dynamic and static languages.
4) Head First HTML with CSS & XHTML by Elisabeth Freeman, Eric Freeman - what to say...after real hard work with book no 3 this one reads like a comic book. It's really a pleasure to read and I would make it required reading for all web designers.
5) Head First Databases – by I wish Unfortunately, this spot is still open. At this point I would need some down to earth, fun to read, easy to understand non-reference database book. Please let me know if you know of anything
6) Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson We're getting serious :-). For some of you it may seem like a long time to wait but only around this point I usually feel that my new hires are ready to not only understand but to really appreciate the beauty of rails. With rails simplicity and generators (we use custom made generators that generate pretty much everything besides the business logic) it's just way too easy to slip to monkey coding without actually understanding it.
7) Pragmatic Version Control: Using Subversion (SE) by Mike Mason Again something that universities (and many small companies) should look into. Nothing else to say...required reading.
8) Extreme Programming Explained (SE) by Kent Beck It's really hard to understand and appreciate this book without at some working experience. Everything seems so obvious and natural and yet it's so rarely done that way. At least around this part of the world. Most of the time I hear people say that Asian boss wouldn't approve of agile principle, that Asian boss wouldn't stand two people sharing a computer, but in my experience that's rarely the case. More about it in some other blog...
9. Refactoring by Martin Fowler - after having written some code, you're ready to change it. This book provides not only solutions to common code smells but it also helps you to train your nose for those smells.
10. Beyond Software Architecture: Creating and Sustaining Winning Solutions by Luke Hohmann - this may be a little different from the rest, but it very nicely sums up all the 'other' questions regarding software development and actual deployment. Even though it's not platform specific some sections would deserve a small update...but overall a very complete reference.
okay...so that's my top 10 learn to program (business applications) list. If you didn't find your favourite in there don't worry - it's most probably because this list is meant for beginers. In fact, I cannot believe how much this list changed since only year and a half ago.
what's next? My intermediate top 10 will follow soon :-)
Programming and Music
This article was inspired (if not provoked) by Dave Thomas. It was several of his latest blogs that really made me stop, take a few steps back (actually 10000 or so km dividing Singapore and Slovakia) and take a break from the constant work cycle. Our circumstances couldn't be more different – he is an accomplished writer / programmer and founder of the pragmatic cult. Yet our daily issues, things we notice couldn't be more similar.
It started with Dave's blog drawing parallels between music and programming. Having finished 12 years of musical school (and frankly not having touched a musical instrument since). I've always wondered if we could get any inspiration for teaching / learning programming from teaching music. Maybe the most appropriate would be a jazz example, as jazz is probably the most flexible yet having a strong internal structure, patters and the same tune played by different musicians or played for different audiences may turn up completely differently. Just think of different renditions of Wonderful World. The parallel here is with pretty much any “standard software solution”. I worked on more than 20 inventory control systems and all of them were different – they used the same structure and patterns but the result was completely different for national distributor carrying 120 thousands different products and for a farm producing and selling bean sprouts.
Anyway, this is not so much about the end result as it is about the process. When you start playing a musical instruments you have to practice scales, etudes and and arpeggios. Sure you'll be playing some simple tunes as you go along but your daily bread for many years will be scales, etudes and then some more scales, and yes, etudes. From time to time, to boost up your motivation and to show the parents where their money is going, you play some concert gigs. From two note polka, when you're six through some Mozart when you're twelve to some Iron Maiden covers on your graduation party. Okay, maybe not that but when we played 6 saxophones + piano rendition of Chattanooga Choo Choo graduating from “school of classical music” everyone was equally shocked.
And this is exactly what I miss in my programming trainings. The first thing you learn on a new musical instrument is playing the scales, as they give you basic touch and feel of the instrument. As the notes are always the same you can fully focus on exploring each individual note, possibly different ways of playing it and slowly you learn to transition from note to note and you're getting comfortable with the full scale of the instrument. In software development I imagine this as a collection of simple challenges covering the basics of a language. Something like the really really great book Learn to Program, just a bit more structured and with many many more practice challenges. If you programmed in other languages and you're familiar with the concepts you will need just a few hours to go through and after you're done you will know the basic building stones of the language.
Later you move to etudes. Each etude is focused around a specific riff specific transition or specific problematic move but still having some kind of melody to make the learning process less boring. The idea is to practice this one thing over and over and over until you completely internalize it. This is another thing I really miss when teaching programming. To explain the collections in ruby is very easy – if you talk really a lot then you need maybe 10 minutes. Their so easy that their usually forgotten right away. Even if my students go through several “challenges” they're usually way too few and way too simplistic to really understand and internalize the collections so that next time they need a collection they will choose the right one without even realizing it and they will write iteration loop without even knowing it. And this is true for every part of the language (any language). When learning to play saxophone I went through around 4 etudes books every year. When teaching ruby programming I have nothing. The programming etudes would do the same as the musical ones – introduce various concepts, first in isolation later with more and more context and provide a wealth of challenges and questions to solidify the knowledge.
The last part of learning is working with the real life concepts – tinkering and playing with them and as there usually isn't just one way seeing it from different perspective and different angle. This part seems to be more addressed in programming as there are several good resources – for example Dave Thomas' Code Kata or book Ruby Quiz.
This is of course not to say that there are no resources for learning at all. Of course, there's plenty of books for every possible aspect of programming. Most of them, however, are written in more exploratory/reference style that is suitable for self study and exploration of the language, than for internalizing the concepts. An exception here is Java as there is plenty of preparation books for the first certificate and they provide sufficient number of questions and challenges. The truth is that ruby may not have reached the critical mass yet and it's used by people who “know how to use it”.