Sunday, June 10, 2012

Discovering Ruby-on-Rails

I remember the days I wanted to build something and created couple of websites from scratch using PHP and MySQL. I also remember that my free-time endeavour turning into a full-time struggle and the day everything went south due to an SQL-injection attack (never really thought of website security until that point.) Even at that time I knew about Ruby on Rails, but just because I didn't want to learn yet another language, I didn't pursue it. Recently I had to learn Ruby-on-Rails for a webdesign project and came to realize how stupid I was in the past!

I believe Ruby became famous thanks to Ruby-on-Rails and I can really understand why. Ruby-on-Rails (RoR) is simply wonderful! Including the time for learning the fundamentals of Ruby and RoR, you can create a complete website within a week or two. It requires your database tables to be setup in a particular way, but once these tables are in place, you don't even have to worry about SQL queries anymore. Also avoided are the possibiliy of me creating stupid security holes asking for an SQL-injection attack. I also like the concepts of layout and partials that let me to structure the visual design of a website. RoR is much different than content management systems; while RoR argumentally makes publishing content as easy as a CMS does, it also let you have a complete control over your design.

So if you are planning to build a website, please consider RoR. The best documentation for RoR is found here.

Saturday, June 9, 2012

Discovering Ruby

As far as spripting languages are concerned, I have been a Python guy for a long time. Then my work required me to learn Ruby and it's been a strange experience. It is said that one of the primary concept in Ruby design is the principle of least astonishment. But, in my learning experience, there was no shortage for astonishments. Ruby provides a lot of shorthands to make the programming much more concise and natural language-like and, in my opinion, this also confuses the programmers coming to the Ruby from other languages. For a simple example, I can point out that, in Ruby, return keyword is optional; whatever value returned by the last statement of a method will be the method's return value.

It took me only a few hours to learn Python (still more weeks to master it.) I see Python as the best mixture of C and Java – for example, if you want to open a file in Python, it follows C's style (a simple open() statement, compared to Java's nested stream opening), but for classes like strings, lists, and dictionaries, it favors Java style. If you know C/C++ and Java, learning Python is a breeze. But, learning Ruby reminded me of learning Perl; while it was simple enough, some Ruby-specific syntax kept me puzzled for stretches of time. For example the ||= operator, which is generally used to assign default values.

One problem I had with Python was that it is space-sensitive (or indentation-sensitive.) While it makes Python source codes super-readable, it creates confusion and bugs when you copy-paste stuffs from one area to another. With Ruby, I happily forgo that problem. Ruby also has many other nice features, like blocks. In summary, once you have got used to its rough edges, Ruby will be real sparkly in your hand.