Tuesday, February 22, 2011

Working with MySQL and Ruby

Whoa, what's up SQL and MySQL?

Here's something I've recently realized about learning Ruby: I can't just learn Ruby. Ruby is going to be the thrust of what I'm learning and I'll spend the bulk of my time with it, but if my ultimate goal is to make a career change and become a full time Ruby programmer, I'll have to learn other languages as well.

This idea isn't as daunting as it might have been a month and a half ago, before I even had the seed of a desire to learn Ruby.

So here's something I've noticed about working with a bit of SQL and MySQL tonight. Computer languages share a lot of the same ideas. Sure, Ruby is more elegant than something like C++ and more modern than the Basic I learned in 9th grade, but the idea is the same. So the teeny, tiny little snippet of MySQL I wrote tonight was easier to understand than it would be if I hadn't also been working with Ruby for a month and a half or so.

I actually had to cut my database work short tonight because I couldn't get the MySQL gem to install, but I WAS able to write a program that allowed me to write to a database and retrieve information from it. Pretty cool, considering that's what I've been hot balls to learn since I cracked open Beginning Ruby.

Monday, February 21, 2011

More about Ruby, Databases and Syntax

So I was extremely lazy this weekend and only spent a couple hours working with Ruby. Awful! However, I think a little time away from actively learning caused a few things to click in my head. Imagine a pair of gears, left to their own devices after hours of meddling and tinkering, that suddenly come together and begin to move. Not smoothly, perhaps, but real motion!

It's hard to describe what clicked for me. The syntax seems to make more sense the more I work with it. While working through Beginning Ruby, I've been typing every bit of code out, then attempting to run it. It's good practice, both to get used to how Ruby is written as well as learning what will cause Ruby to throw up AND how to fix those little problems. How often do you guys do something stupid like this?

class Person
  attr_accessor :name, :age
end

fred = Preson.new
fred.name = "Fred"
fred.age = 35

puts fred.name
puts fred.age

Only to have Ruby throw up everywhere because of two little letters that got switched?

I'm guessing this transposition kind of crap is something that will haunt me FOREVER, but I'll get better at spotting it as I go along.

Also I would like to say that I wrote this bit of example code almost ENTIRELY from memory. So things are sticking. I still have a hard time believing how easy some of this is, but there's still plenty I don't really understand yet. Still, let's not get ahead of ourselves here.

Still working through Chapter 9. I just installed my_sql. How do you pronounce this, anyway? I heard a guy at the meetup a couple weeks ago call it "My Sequel" which seems better than "MY SQL" but I don't know.