Ming the Mechanic
The NewsLog of Flemming Funch

Wednesday, December 14, 2005day link 

 Ruby on Rails
picture Ruby on Rails 1.0 was released yesterday.

Grrr, I have too little time.

I had heard about Ruby and Ruby on Rails for quite some time, but didn't get around to looking more closely before recently.

Ruby is an elegant object-oriented language created in Japan some years ago by Yukihiro Matsumoto. I had looked at it several times, but however good it sounded, there really has to be an exceptional reason for changing the language one programs in. The biggest value is usually in knowing one's tools really well, as opposed to just changing everything whenever another language or platform comes along with slightly better features.

As far as the web is concerned, I first made programs in Perl, because that was basically the obvious choice in 1995. I did shopping cart programs, chat programs, and various other things. But Perl is just too damned cryptic, and I never felt overly comfortable with it.

Then PHP started happening, and it just seemed so much more practical to be able to embed code directly into webpages, and it was more clean and straightforward. So, I switched without much hesitation. Since then I've done hundreds of thousands of lines of PHP code, and PHP has grown into the most widespread solution for coding for webpages.

I've looked at other things in-between. Like Python. More of a "real" language, in that it makes it easier to make clean and well-structured programs that are easy to maintain. But that in itself wasn't enough to switch. But then I looked at Zope, which is a fabulous content management system and development framework, which makes a lot of hard things easier, and which is supported by loads of available modules. I was excited by that, and wanted to switch all my work to Zope. But after a couple of projects, I just felt kind of stupid. If I just used the pre-packaged modules, it was a piece of cake, but in developing new stuff, I just ended up not really grasping the "Zope Way". The people developing the core stuff are obviously super-smart, but so much so that I couldn't easily follow what they were talking about. So I ended up not going any further with that.

Now, Ruby on Rails is a framework built on top of Ruby. It could have been done in other languages, but Ruby lends itself very well to the purpose. It is developed, initially single-handedly, by David Heinemeier Hansson, a young Danish developer. Who is obviously also super-smart, but who additionally has a knack for making things extremely simple, and for just doing everything right. It supports the best practices for development, it supports most things that currently are cool and happening, like Ajax, it is well structured, easy to test, easy to deploy, etc. And with Ruby on Rails you don't pride yourself on how many lines of code you've written and how long it has taken, but quite the opposite. You'll brag about having written some major application in a few weeks, with just a few thousand lines of code.

Rails is built on a fixed, but flexible structure, or pattern, rather, called MVC. Model, View, Controller. The models keep track of the data, connect with databases, validate the data, and store the business rules for the data. The controllers receive requests from the users for doing different kinds of actions. The views are templates for what is presented to the user. That's nothing really new, but it is a good way of organizing an application. One could do that in PHP, but typically one doesn't. Now, Rails enforces a certain structure. There's a set of directories where these various things are stored, and there are certain naming conventions for what they're called. That some of these things are set and known in advance is in part what makes it very simple. A Rails principle is "Convention over Configuration". If we know that the model is always found in the models directory, and that it is named to correspond to the database table, and a few other conventions, we suddenly have little need for configuration files that define where things are and what goes with what.

Another basic principle is "Don't Repeat Yourself" (DRY). Meaning, one should really only do something once. If you have a rule that says that you can not order more than 10 of a given item, there should be one and only one place to say that. Most programmers would want to follow a rule like that, but in most systems it is hard to stay true to it in practice. Not so with Rails, as there typically already is one right place to store that item, so there's no doubt about it.

The online video demos for Rails are mind-blowing. You know, like write a simple weblog program in 15 minutes. If you just want to try Ruby itself, here's a great little interactive tutorial.

Well, I haven't gotten much further than installing Ruby and Rails on my machine and going through a few tutorials. But I'm very impressed, and I think this probably will be a way I'll go.

I'm an expert at PHP programming, and I've done a number of fairly impressive things. But it tends to end up being a bit of a mess. You can do a quick thing in PHP really, really quickly. But a complex program in PHP is very complex. And after you've done it, you discover that there isn't any very good way of testing it, and things break whenever you change something. And everybody does things a little differently, so if you get the job of changing something in somebody else's program, it usually looks like a big pile of spaghetti, however cleverly it might have been written.

I just spoke with one of the people from a company I worked with for several years, developing big things in PHP. I had wondered why I hadn't heard from them for a few months. Turned out that in the meantime they had converted their whole operation to Rails, and they are extremely happy with it, and everything was much easier. That's some folks with very high-volume websites and a few dozen servers. And no wonder they don't need me any more.

Luckily Ruby and Rains are so relatively simple that one can become an expert faster than in various other arenas. Oh, it is not a complete no-brainer, either. Rails can seem a bit intimidating at first. No graphical interface or anything. You're editing text files and running command-line utilities. The productivity mainly starts when one is fluent with all the basic pieces, and one intuitively knows where things go.

Anyway, the best places to learn are the two main bibles, which are lying right here next to me. Programming Ruby and Agile Web Development with Rails. You can read them online too, for that matter.

Ruby and Rails are often connected with "agile" or "pragmatic" programming. These are keywords for modern methods of fast and flexible development which are very different from the traditional slow and linear methods. You know, traditionally one would learn to develop software according to a certain Structured Development Life Cycle (SDLC) approach, which involves copious amounts of formal proposals, specifications, etc. You know, first a committee of people would do feasibility studies, then it would go to an analyst who would make models and specs, etc. And the programmers would be told what to do, essentially. And when they discover that it isn't a great idea to do it that way, or when, later, one discovers that it wasn't really what was needed, it is a bit cumbersome to change. The Agile, Pragmatic or Extreme approach would rather be to go very light on the specs and analysis, and get down to work ASAP, but to do it very quickly, with very short incremental phases, like daily updates, and to do it, as much as possible WITH the stakeholders who need the result. Like, preferably sit down with the end users, and change stuff and show them right away. One could theoretically do that with any language, like PHP, although it isn't easy, and one would probably be crazy to hope to do that with Java or C++. But if you're working with a framework that all the way through is geared towards working like that, it comes much more naturally.

Anyway, I could sure use a 10X productivity boost. And right now Rails looks like the most likely candidate in the programming arena. Plus, I want to be cool too.
[ | 2005-12-14 15:15 | 19 comments | PermaLink ]  More >

 The Fatal Book Review
picture Stanley "Tookie" Williams was executed in St.Quentin last night. He was the founder of the Crips gang, and was convicted for having killed 4 people, even though he claimed his innocence. I can't judge whether he actually did it or not. But it is a shame because he seemed to be a reformed man who had become a great activist. The most stirring comment I read is from Doc Searls who just happened to be staying in a house overlooking St.Quentin at the time. Governor Schwarzenegger had denied clemency to Williams, in part for these reasons:
The dedication of Williams' book "Life in Prison" casts significant doubt on his personal redemption. This book was published in 1998, several years after Williams┬╣ claimed redemptive experience. Specifically, the book is dedicated to "Nelson Mandela, Angela Davis, Malcolm X, Assata Shakur, Geronimo Ji Jaga Pratt, Ramona Africa, John Africa, Leonard Peltier, Dhoruba Al-Mujahid, George Jackson, Mumia Abu-Jamal, and the countless other men, women, and youths who have to endure the hellish oppression of living behind bars." The mix of individuals on this list is curious. Most have violent pasts and some have been convicted of committing heinous murders, including the killing of law enforcement.

But the inclusion of George Jackson on this list defies reason and is a significant indicator that Williams is not reformed and that he still sees violence and lawlessness as a legitimate means to address societal problems.

There is also little mention or atonement in his writings and his plea for clemency of the countless murders committed by the Crips following the lifestyle Williams once espoused. The senseless killing that has ruined many families, particularly in African-American communities, in the name of the Crips and gang warfare is a tragedy of our modern culture. One would expect more explicit and direct reference to this byproduct of his former lifestyle in Williams┬╣ writings and apology for this tragedy, but it exists only through innuendo and inference.

Is Williams' redemption complete and sincere, or is it just a hollow promise? Stanley Williams insists he is innocent, and that he will not and should not apologize or otherwise atone for the murders of the four victims in this case. Without an apology and atonement for these senseless and brutal killings there can be no redemption. In this case, the one thing that would be the clearest indication of complete remorse and full redemption is the one thing Williams will not do.
And here's Doc's comment:
I haven't read any of Williams' books. I don't know if he has redeemed himself. And I am not a lawyer.

But it seems to me the governor is making a political judgement here, and not just a legal one; especially in respect to George Jackson, a charismatic Black Panther considered by many a martyr after he was shot in prison.

I would find the governor's clemency denial much easier to take if he had confined his remarks to the facts of the case, and said Williams should die, as the courts ordered, for the cold-blooded murder of four people. But he didn't. He gave Williams a fatal book review.

And a shallow one at that. Did the governor read past the dedications?
He's right. That's outrageous. Sent a man to his death because he mentioned a black panther favorably in the credits of his book. A fatal book review indeed.
[ | 2005-12-14 15:46 | 26 comments | PermaLink ]  More >

Main Page: ming.tv