All About Ruby


Ruby Magick

Today I have a much better grasp of Rails and the magick seems to fade away. And this is great. Rails generates a lot of excitement at the moment, and excitement leads to hype, when people who try to play the “magick” card, attributing it with “human-like” behaviour and popularizing a perception that Rails does everything for you.

The screencaps might be impressive, but frankly with right PHP libraries you would be able to get the same results just as easily. The best presentation on Rails is here, it was done way before all the Rails hype started (you can even see that there are about 20-30 people in the room). It is a bit long (2 hors!), but David (the Rails author) answers most of the questions - what made him move from PHP to Ruby, what MVC methodology means in Rails, and also codes an example, which just does not

And this brings me to a point - you should not expect Rails to be easy, you should expect to get into it first.

Also, I am not sure I like the thing about plural / singular (in Rails you enter it in singular, like “Book” when you name an object, and in database you have a table called “books”, because you see, it is a collection of book, the objects. And Rails goes one way further - mouse become “mice”, and so on. I am not sure that this is that useful for programmers, you could just as well have Book the object and Book the database table name. But I guess thisk quirky feature is something to put you in the mood for starting thinking about the object/database relationship, and it’s also a great soundbyte.

In the video presentation I mentioned, somebody asked a good question - “can Ruby be considered to develop a Bank System?” And this is a good question - for people to start looking into Ruby means a great amount of investment. If the language is not a proven concept or if the support is lacking, Rails can become just another fluke - an overhyped technology. And the answer to this would be that nobody knows yet - the critical mass of Ruby programmers is not there yet, so anything can happen. Ruby (and Rails) can become the next Linux or Apache - an industry standard robust technology with commercially available support. It can become an object-oriented PHP alternative. Or it can become Coldfusion - taking up a relatively small niche.

From what I saw in the last couple of days, both Ruby and Rails have a lot of potential. One thing Rails should be very good for is for rapid development of mini projects (3-4 people for 1-3 months). But mini does not mean bad - the flagship Rails project is a good looking project collab tool Basecamp. One of the best features that will be great for Web 2.0 start-ups and fans is the built-in support for Ajax in Rails.

I am still not sure about the learning curve for Ruby and Rails - if the time investment is not serious, even if the future of Rails and Ruby is not certain, you still will not waste it - learning about Ajax, Object Oriented Programming and Model-View-Controller methodology will not go unnoticed.


Model-View-Controller in PHP

Actually, if you are not interested in Ruby and want to try out MVC framework in PHP, you can check out these projects: Zoop Framework or a Rails clone: PHP on Trax.


Model-View-Controller in Ruby on Rails

Ruby on Rails uses a development framework called Model-View-Controller. I was not really aware of it until today, but basically it is a separation between several components of the application. Once again, Wikipedia is a great source for this kind of information - Model-View-Controller. In order to start working with Ruby on Rails, a grasp of concept is required.

As I understand it, Model takes care of the database connections, View is somewhat easy - is basically an HTML template with Ruby code in-line, and Controller stores events, that are mostly user-induced (so, for example user hitting a Submit button on the HTML form). It also looks like Controller and View are used to store most of the logic of the application, while Model in Ruby on Rails is mostly transparent, and SQL calls are based on specific rules defined by Rails.

I still cannot fully understand the reason for this separation, and will need to get my hands dirty coding, before I can see the benefits of this. One benefit that was mentioned was a modified version of a well-known separation of content from presentation (CMS, Blog templates, Skin engines). In the case of M-V-C framework, we are able to separate View from Controller and Model, making it less painful to introduce GUI changes, while leaving the core “engine” without changes. 


Ruby on Rails: Choice of IDE

To make sure you know what the IDE is, here is the definition from Wikipedia:

IDE (An integrated development environment) normally consist of a source code editor, a compiler and/or interpreter, build-automation tools, and (usually) a debugger. Sometimes a version control system and various tools to simplify the construction of a GUI are integrated as well. Many modern IDEs also integrate a class browser, an object inspector and a class hierarchy diagram, for use with object oriented software development. (read more).

To be frank, I did not straight away start thinking that I necessarily need an IDE for my Ruby on Rails programming. For the last 2 years I spent a lot of time coding PHP in my text editor (it is actually a plug-in for my trusted old Norton Commander clone, FAR Manager). But I suddenly remembered that when I started programming in PHP, I really missed the IDE environment of my early programming days, with powerful debug, meaningful error messages and contextual help. So, this time with Ruby, I want to make sure that I use the IDE from day-1.

The choice of an IDE is not an easy one. If you want to go with the easiest choice and just use the editor that David Heinemeier Hansson (the crteator of RoR) used in his screencaps, most likely you will be out of luck, as the name of this product is TextMate, and while it looks quite cool, it’s only available for Mac OS X. If you have a Windows PC like me, you will have to get something else. The most popular options are UltraEdit (looks like the color schema is not too good), FreeRide (a bit unstable - it crashed on me when I clicked “Help” ;), but it comes with InstantRails, so no harm in trying it out, given that it was developed especially for Ruby), SciTE (it looks a bit dull for my taste) or RadRails (which looks and sounds great - it was built for RoR specifically. However, some people reported it as a bit buggy).

I have decided to try out RadRails and if there are no major suprirses, will stick to it.


Ruby on Rails: Take-1

I downloaded two (1,2) great presentations yesterday. Although they looked more like a David Blaine commercial (in that everything was going fast, but you were not able to catch up with the on-screen magic), they gave the idea of what RoR is all about. And I really liked what I saw. I actually liked the Flickr presentation better, because it also showed that RoR is great for AJAX projects, which is something many people are trying to do.

Now, I still did not start doing anything with RoR, and I found out yesterday that I need two things to start:

1. Learn Ruby (and this I will continue doing later today with either this book (a weird one, with foxes, quirky style and illustrations, but might be easier to swallow ;) ) or this one (somewhat more formal). One thing I understood when I was trying to get into RoR yesterday, is that I do not feel Ruby well enough (well, I just started digging it yesterday), to be able to jump into RoR. You should also not forget that Ruby on Rails is a framework, basically a package built on Ruby. And Ruby (as I wrote before) is a well-respected and well known language, and being a new language for you it provides challenges - a basic knowledge of notations, philosophy and methods is a requirement.

2. Find a suitable IDE. This topic has proven quite complex, so it requires a separate post.

(to be continued)


First Ruby code

Ok, I cannot do much with Ruby now, so I’ve decided just to run ruby.exe and play with it for a bit. There were a couple of methods I learned from the interactive tutorial I did, and just for fun I entered this:

k = [1, 10, 5]
k.sort
k.sort.reverse
k.to_s

I have to say, this is really cool. (If you did not finish the tutorial - first line defines the array, second line presents a sorted array, third presents a sorted and reversed array, the last - an array converted to a string). As Ruby is an object-oriented language, everything is done using methods, and this is the most intuitive implementation of methods I have ever seen.

An ability to get the instant response to your line of code is also something that I missed with PHP, when I would spend several minutes to find stupid errors, when if I had an instant console, I would be able to catch them much easier.

Now I need to read up on Ruby methods and will probably take some time watching video presentations of Ruby on Rails.


First run of InstantRails

I have downloaded v1.0 Preview 8 of InstantRails (there was also a release candidate version but the link is giving me a 404). After unzipping, you just need to run instantrails.exe in the home directory. There are 2 indicators - MySQL and Apache. Apache gave me trouble, giving an error: “Apache cannot be runned : another Web server use the Web port”.

(For your info: I have Windows 2000 SP3 and all the latest patches + Norton Firewall + dLink router with firewall enabled)

First you need to check if you have IIS enabled and running and will need to stop that. Here is how you do that on Windows 2000 / XP:

* Right click My Computer
* Left click Manage
* Expand Services and Applications. Check if Internet Information Service is there.
* If it is then expand it. Expand Websites. Left click on Default Website
* Then Right click Default Websit and if STOP is available to click on then IIS is running on the port InstantRails wants to use. (taken from here)

I knew that I had no IIS running, so I had to go to Configure -> Apache in InstantRails, search for the following in the httpd.conf file:

#
# Port: The port to which the standalone server listens.  Certain firewall
# products must be configured before Apache can listen to a specific port.
# Other running httpd servers will also interfere with this port.  Disable
# all firewall, security, and other services if you encounter problems.
# To help diagnose problems use the Windows NT command NETSTAT -a
#
Port 80

and change “Port 80″ to “Port 3000″, then save the config file. After that, I hit Apache button in the InstantRails main window and it started. Norton Firewall gave me a warning about apache.exe accessing internet, and I gave it full rights (not sure if this is secure, but I want to start trying out Ruby already!).

Voila, everything is running. I access 127.0.0.1 and it gives me a “Coming Soon!” message. Now, I know that Apache is working. So the set up was quite painless. Let’s do some test coding! ;)


First impressions

The first impression of Ruby on Rails is that it is a great framework, but because it is just now starting to gain attention (yes, there are already 2 books at O’Reily’s, but those guys work fast) there are lots of bugs and annoyances, that are just not there when you use an established framework like LAMP:

  • Not enough information. I remember how difficult it was to get any kind of understandable information on HTML when the only resource was W3C. The same happened with CSS. I became familiar with PHP at a later stage, when there were hundreds of dedicated resources already and was impressed how virtually any question or problem can easily be googled and answered in seconds. This is of course not the disadvantage of the framework, but a disadvantage of the first-mover.
  • Hosting options are extremely limited. For PHP there are thousands reliable hosters. I am not sure how my hosting provider will react if I ask him to provide me with a Ruby on Rails virtual host. (Is it possible, has it been done?)
  • Limited number of building blocks. There are thousands of GPL and free projects and code snippets that you can use with your PHP project. This means that most of the time you are not writing projects from scratch, but rather modify existing code - this often makes delivery extremely rapid. I am not sure if the same is available for Rails.

Ruby on rails

I am not the fastest to react to new tech and gadgets. So it was only this week that I finally decided to spend some time on understanding what Ruby on Rails (RoR) is all about (this Wikipedia article sums it up nicely) . So, in simple words, ROR is a framework which allows you to develop web applications much faster than usual (some authors already claim it’s 10 times faster than Java).

I am not the one easily sold, because more than often ease of use means limited flexibility. So I did more digging and found out that Ruby, the language on which RoR is built is a modern, powerful language. There is a great interactive tutorial, that literally made me fall in love with Ruby - Ruby interactive tutorial.

I did not try out RoR yet, but decided to go with the InstantRails package, that basically allows you to run Apache, MySQL, Ruby and Rails with no need to install and configure any of those applications.

A good article that shows the potential of Ruby on Rails is this one.

Ok, so I will need to install the InstantRails to my home PC (Windows 2000) and let’s see how it goes. I am excited.