The class was over, and as I was going out the door one of my students, an experienced Java programmer, stopped me and voiced a complaint that I have heard many times since. Oh, he could write perfectly correct Ruby, sans semicolons and variable declarations. The problem was that something was missing. He constantly found himself falling back into his same old Java habits.
|Published (Last):||15 April 2018|
|PDF File Size:||15.47 Mb|
|ePub File Size:||13.92 Mb|
|Price:||Free* [*Free Regsitration Required]|
InfoQ talked to the author of "Eloquent Ruby", Russ Olsen, about the practical advice given in the book. Related Sponsored Content Troubleshoot performance bottlenecks and optimize your application performance with Site24x7.
Related Sponsor Enhance your end-user experience by optimizing your application performance. Get a holistic view of your application behavior with Site24x7. Russ Olsen: Surprisingly, some of the key tools for detecting less-than-ideal Ruby code are the testing tools: rspec, rcov and perhaps Test::Unit.
Along with ensuring that the code actually works - always a good thing - having good test coverage means that your code is actually testable, which pushes it towards good things like single minded classes full of small methods.
A more conventional answer would include tools like flog which will score your code for complexity, flay which looks for duplicated code and reek which looks for specific code smells. The thing with Ruby is that you can get an awful lot done with very little code, which means that many Ruby projects consist of small teams working on relatively small code bases.
InfoQ: You mention some of your influences, eg. What are some of the lessons you learned from these sources? Tips for structuring code snippets or for code organization? I see diving into the how-to books from other programming languages as just an extension of the same process: If simply learning Clojure or Smalltalk is worthwhile, then surely understanding how Clojurites or Smalltalkers deal with real problems is also going to be valuable.
In the same spirit, a lot of Ruby DSLs have no visible main program - things just seem to start themselves by magic. InfoQ: The book contains a lot of information and advice about metaprogramming. On the one hand, since LISP macros allow the programmer to transform the code before the parser sees it, LISP macros let you do some remarkable things.
Think about it: Armed with the current set of metaprogramming tools - open classes, the reflection APIs, the eval family of functions and code blocks - Ruby programmers have managed to come up with Rake, Rspec and ActiveRecord.
And, while these are all really solid bits of work, the metaprogramming behind them is not very difficult. The traditional programming constructs, things like methods and classes and variables are all there to help us make the computer do what we want the computer to do. They are all just there to help us get the job done. The difference is that some of these techniques are familiar and some - for most of us - are still shiny and new.
So how do you tell if you are over-engineering some metaprogramming solution? In exactly the same way you can tell that you are over-doing it with classes or design patterns or any of the other tools out there. You ask if the more conventional design might not work just as well and be easier for the next programmer - who might well be you - to understand.
You say to yourself, "Hey, is this the simplest thing that could work? Stay tuned! Being a working techie in the early 21st century is one of those worst of times, best of times kind of things. When I look at my list of things that I should know more about, it starts with Erlang and runs through Clojure and JQuery and node.
So when I watch a screencast or listen to a conference talk or read an article, I just want to cheer for this person who is taking the time to try and explain things to the rest of us.
Sometimes I also want to cry. Having written two books, I can tell you that explaining things is not easy. Crafting good explanations is an art in itself, one that we need to get better at it or all this great new stuff is simply going to overwhelm us.
For more info on both, please visit the publisher site.
Interview: Russ Olsen on "Eloquent Ruby"
Eloquent Ruby by Russ Olsen [PDF]