Thursday, February 17, 2011

Ruby and Databases

I started digging into Chapter 9 in Beginning Ruby tonight. It's all about databases and while I never, ever thought I'd be excited about working with databases, this chapter is something I've been looking forward to for a while.

Let me tell you why.

Up until now, for all the little programs and tests I've been making, I've been inputting static variables. It's my understanding static variables have limited real-world application. I want to learn how to write code that can write, interpret and modify data and this database work is the first step to understanding that process.

So far, I've been able to get Ruby to create a new text file, write something in that file and then close it. I've learned how to open files in read or write only mode, in read AND write mode, in append mode and so on. Fascinating! But it's a bit difficult to grasp. Still, I think I've got the basics of how it works, now I just need to keep working through and figuring out what I can do with these commands.

Is there a site you can join to write and publish Ruby code for testing? Is that what Heroku is for? Anyone?

Bueller?

Tuesday, February 15, 2011

Learning about testing, debugging and optimizing Ruby code

I just finished up chapter 8 in Beginning Ruby. It was mostly about documenting, debugging, testing and optimizing code. Not the most interesting chapter, but it's still important to understand.

Writing custom exceptions is easy enough to understand. Begin and Rescue makes sense. Once again, I'm amazed at how easy Ruby is to grasp. You want Ruby to do something 100 times?

100.times do
  puts "DO WHAT NOW"
end

Maybe it's just because I've got some experience now, but this bit of code is easy to break down. I'm looking forward to the day that more complex bits of code are as easy to grasp! One step at a time.

But here's a question about optimizing code. Do you typically try to optimize as you write the code, or do you write the code and then optimize it? At first, it seemed logical to try and optimize as you write the code, because it seemed like the most efficient way to work. However, once I read further, writing code and then optimizing it seemed more efficient, since you could figure out which parts of your code need to be reworked. This way you wouldn't waste time thinking of ways to optimize code that wasn't really a problem to begin with.

Benchmarking code is another concept that made sense immediately. Since Ruby offers you the ability to do something in multiple ways, being able to figure out if one method is inefficient is important.

Next up is Chapter 9: Files and Databases. OH YEAH! Never thought I'd be so excited to learn how to call a database for information and then manipulate that information and display NEW information to the user! This is what I've been interested in since I started reading Beginning Ruby.