How I Started to Learn Ruby – Part II


<?php
  session_start();
?>

Where we left off… I had just started to learn PHP/MySQL to run my own online registration system for a couple of camps that I was working at.

I had just enough tools to do some real damage, and, it, was, awesome!

I really couldn’t believe that I used to spend my time building tables of data by hand!┬áReusable┬ádata, real templates, dynamic interaction; with a little time I could do it all.

Keep in mind, if I wanted to insert a row into a campers table in my database, I had to do this:


$query = sprintf("INSERT INTO campers (account_username, account_password, camper_email, camper_lastname, camper_firstname, overnightday, camper_address_street, camper_address_city, camper_address_state, camper_address_zip, camper_primaryphone, camper_secondaryphone, camper_mothername, camper_fathername, camper_highschool, camper_highschool_address_city, camper_highschool_address_state, camper_height, camper_weight, camper_age, camper_grade, camper_position, camper_insuranceco, camper_insuranceco_address, camper_insuranceco_policy, camper_insuranceco_group, camper_insuranceco_id, campfee, deposit1, deposit1date, totalpaid, totaldue, onlinecamper, shuttle, camper_canceled) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
        mysql_real_escape_string($account_username),
        $account_password,
        mysql_real_escape_string($camper_email),
        mysql_real_escape_string($camper_lastname),
        mysql_real_escape_string($camper_firstname),
        $overnightday,
        mysql_real_escape_string($camper_address_street),
        mysql_real_escape_string($camper_address_city),
        mysql_real_escape_string($camper_address_state),
        mysql_real_escape_string($camper_address_zip),
        mysql_real_escape_string($camper_primaryphone),
        mysql_real_escape_string($camper_secondaryphone),
        mysql_real_escape_string($camper_mothername),
        mysql_real_escape_string($camper_fathername),
        mysql_real_escape_string($camper_highschool),
        mysql_real_escape_string($camper_highschool_address_city),
        mysql_real_escape_string($camper_highschool_address_state),
        mysql_real_escape_string($camper_height),
        mysql_real_escape_string($camper_weight),
        mysql_real_escape_string($camper_age),
        mysql_real_escape_string($camper_grade),
        mysql_real_escape_string($camper_position),
        mysql_real_escape_string($camper_insuranceco),
        mysql_real_escape_string($camper_insuranceco_address),
        mysql_real_escape_string($camper_insuranceco_policy),
        mysql_real_escape_string($camper_insuranceco_group),
        mysql_real_escape_string($camper_insuranceco_id),
        $campfee,
        $deposit1,
        $deposit1date,
        $totalpaid,
        $totaldue,
        $onlinecamper,
        $shuttle,
        $camper_canceled);
$result = mysql_query($query);

As you can imagine, managing data like this without stored procedures, without an ORM can be incredibly time consuming, monotonous and error prone. Spread this among even a very small application, and I was right back ready to call it quits.

Again, this wasn’t fun any more. I went from solving real problems to pulling my hair out for an hour until I noticed that I misspelled “camper,” forgot a comma, or some stupid mistake.

A Light From Above

By this point, I had bought a second book trying to make sure I was processing payments properly. In the book there were a couple of pages mentioning “frameworks.” This sounded like JUST what I needed!

I had messed around with PEAR a little bit, but never found it to be much help. I didn’t really care for the packaging system you had to install, and to be honest really had no idea how to use it properly. These mystical “frameworks,” however, seemed like they could be a big help.

After reading up a little bit more, I had narrowed the choices down to 2: CakePHP and the Zend Framework.

I went through the basic tutorials for both to see which would work best for me, and it basically came down to 2 things:

  1. The basic CakePHP tutorials all seemed to be about building a blog. As I went through, it felt almost like doing a WordPress installation.
  2. Zend was heavily involved in the development of PHP.

If you couldn’t guess, I went with the Zend Framework. (By the way, I do now know that CakePHP is MUCH more than a blogging machine).

Adapters, Authorization, ACL, ORMS and….. MVC

I have to say, the Zend Framework really taught me a ton about the web. I started to REALLY learn about public directories, permissions, access control, mapping objects to database rows, and on, and on, and on.

Once again, I was able to shake myself from a rut by learning something new and becoming much more productive (you may notice a pattern here).

On I went, building multiple apps with the Zend Framework that were much more efficient, and I felt much more confident in their ability to perform tasks properly.

Along the way, I had also started to pick up this decades old patter, MVC. I still didn’t really “get” it, but it did help me separate my data, and have some form of organization in my projects.

Life was good.

And One Video Changed Me Forever

One odd day, I realized that I may have counted out CakePHP too soon, so I went to read a couple of other peoples’ reviews. Along the way, I saw that CakePHP was often being compared to something I hadn’t heard of before, Ruby on Rails.

Of course, I had to see this for myself, so off I went to their website. There I saw the original, Build a Blog Engine in 15 Minutes video.

After watching this video, I HAD NO IDEA WHAT WAS GOING ON.

Matrix Terminal

I saw this guy, DHH yell, “whoops” as he whipped together an application. I was watching text fly by like the Matrix, and felt completely overwhelmed.

That day I went back to my safe home of PHP and the very helpful Zend Framework. Work continued for some time, but I never forgot about that video…