Skip to content

The Goodness Of Regular Expressions

September 8, 2012

This morning I have continued to work my way through the Programming Ruby book. Once again, I find myself learning about concepts that I’ve only grazed in the past.

According to Programming Ruby, on page 24, here is the definition of a regular expression:

A regular expression is simply a way of specifying a pattern of characters to be matched in a string. In Ruby, you typically create a regular expression by writing a pattern between slash characters(/pattern/). And, Ruby being Ruby, regular expressions are objects and can be manipulated as such.

This concept was awesome to discover. I remember watching Ryan Bates one time in a particular Railscasts episode, and I was totally confused when he used all of these special characters to validate a form to ensure that the user was typing a valid email address in a particular field. I remember thinking, “How in the world could someone just know that pattern and be able to remember it?” It honestly looked like Greek to me.

Well, now I see that he was using character classes (space, tab, newline, etc) stored in a regular expression to match against what was entered in the form by the user. If the format of what the user entered matched the regular expression stored in the model, then the form input was accepted. If it didn’t match, then a validation error was thrown.

I felt like such a noob as I was working through this today. I mean, I’ve been working in Rails off and on for about two years now. How could I not know this? Once again, this is an example of jumping in feet first into a powerful (but complicated) framework without having a solid foundation in the language of that framework. I heard Michael Hartl say in a video once that you don’t have to be strong in Ruby to write Rails applications. I really respect Michael Hartl and I love his tutorials, but I have to strongly disagree with him on this point. I can honestly tell you that the more I learn about Ruby, the more I have those “Aha!” moments about Rails.

I think competent Ruby programmers take Rails for granted sometimes when they are dealing with beginners. What I mean is that Rails is such an opinionated framework that it’s easy for Ruby programmers to dive in, accept the convention over configuration nature of Rails, and produce some great applications without the headache of managing a lot of overhead. However, someone new to programming won’t have the tools necessary to either understand or leverage the power of Rails. Sure, anyone can do what I did and Google away to figure out how accomplish certain tasks. However, I can say with confidence that if someone doesn’t have a strong foundation in Ruby, then they won’t have the ability to create great applications on their own in Rails. There will always be that “brick wall” that you can’t seem to get beyond as you develop your application.

I’m so glad that I’m putting in the time and effort to go back and really learn Ruby. I’m already so much further along in my understanding of Rails than I was even a couple of weeks ago when I started this blog.

That’s all for now. Until next time.


From → Ruby

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: