For every programmer there comes a time when he copies and pastes code from some external source into his project, guesses what's wrong, and blindly hacks away at it until it starts working. He has no idea why or how it works because he doesn't fully understand the code. This is common for beginners, but experienced programmers are sometimes caught doing the same thing. The result is ugly code which will cause problems throughout the entire project. It will continue to break with every related change - and he doesn't know why.
Take a look at the code you wrote (or copied and pasted) this past week. Do you understand every line? What is actually going on behind the scenes? If you do not understand every single line, I encourage you to research what that piece of code is doing.
Learn the Language
If the line you don't understand has some Ruby syntax that you aren't familiar with, break out that Ruby book and research it. Here are some common areas that beginners struggle with because they don't understand that particular Ruby feature:
Last edited by ryanb (2006-09-02 18:24:34)
Offline
Thanks Ryan - thats good advice for people new to programming and it applies to every language - Ruby/JS/CSS/PHP etc...
Offline
shadow wrote:
Thanks Ryan - thats good advice for people new to programming and it applies to every language - Ruby/JS/CSS/PHP etc...
Indeed.
I think it's a trap we've all fallen into at one point or another, thinkingn it will be quicker to get things done. In the end all it does is slow us down, though, because we don't learn anything from it.
This is something I'm really trying to avoid with RoR and instead I'm just picking through writing my code one line at a time and loving it. It's fun to make all of those little discoveries for yourself, particulalry in RoR because of the way the language/framework works.
Offline
Check out "Ruby for Rails" by David Black for developing a deeper understanding of your code:
http://tinyurl.com/j8qke
Offline
I can recommend the book (Ruby for Rails) too. I've read it myself some weeks ago.
Offline
I know in Rails we're not supposed to need debuggers cuz we write such beautiful code, but your post points out the fact that we often aren't working with our own code. If you're struggling with what a certain code path does, consider ruby-debug. It's far better for code path inspection than breakpointer because you can step and examine state, then step some more. I still tail the logs as my primary methodology, but when I get really-really stuck, this is the best tool I've seen for Ruby.
http://www.datanoise.com/articles/2006/ … ruby-debug
Sorry, no GUI...
Offline
Sweet article! Ill have to try this since i'm starting RoR
Offline