Saturday, November 13, 2010

Thursday Rubyconf Notes

w00t! My first Rubyconf! My testimony of this great event. Today: Rubyconf's first day:

Opening Keynote by Dave Thomas

I didn't take notes on this; just listened. Dave went thru the history of his involvement w/ Ruby, the books and how it grew beyond his wildest expectations.

His last part touched me the most: find someone and mentor them into the Ruby community. His comments would have more meaning to me as the conference unfolded.

Debugging Ruby Systems by Aman Gupta

Aman described all the "heavy hitting" tools to use when the problem lies outside of using console or irb to figure out what's going on:
  • lsof
  • strace - linux only - trace system calls and signals
  • tcpdump - dump traffic on a network - use wireshark for decomposing results
  • perftools - google's performance tools
  • cpuprofiler
  • perftools.rb (available on github)
  • rack-perftools - rack middleware for prftools.rb
  • ltrace - trace library calls. Is presently unable to trace into shared libraries; ltrace/libdl will fix this.
  • gdb - the GNU debugger
What I would find out later is the attempt to integrate what these tools do in one application. But these were good; sometimes I've used one or another but it was helpful to have the entire selection explained again.

The Polite Programmer's Guide to Ruby Etiquette
by Jim Weirich, Chris Nelson, and Ed Sumerfield

Basically, how to not break others' code when you use 'method_missing' and similar powerful Ruby features.
  1. When using method_missing, delegate what you don't handle to super.
  2. Beware there are several "hook" methods:
    1. method_missing
    2. constant_missing
    3. etc
  3. When using method_missing, don't forget to handle responds_to as well.
  4. When publishing a gem, don't forget to put that gem's dependencies in the gem description file. There is now a feature in the description file to also specify additional gems depended upon only during development.
MetricFu, a code analysis tool
A static checking toolset.

There are quite a few independent software packages covering different metrics:
  • Flog reports. Measures complexity. Also top 5% complex ones.
  • RCov. code coverage. What lines in your code has been executed by tests.
  • Reek: bad naming
  • Play: copy-paste detection. Is fairly good at
  • Saikuro - cyclosomatic complexity. Covers branching complexity
  • Source - Source Control Churn.
  • Roodi: Tries to find definite code design.
That's quite a few different outputs to wade through. MetricFu organizes all output in one graph per method. Hence, MetricFu is based upon Caliper and accomplishes the "unification" of static metric output on a per method basis.

ZOMG - Why Is This Code So Slow?
Aaron Patterson put on a performance that will be a classic video to watch in coming years. In a very humorous way, he explored a Rails 3 anomaly that we experienced ourselves, a mysterious and significant ActiveRecord performance slowdown.

In telling it like a detective story, Aaron walks us through his motivations and thinking in
  1. Discovering the problem
  2. Deciding that it's worth his time to fix it.
  3. Understanding the problem
  4. Fixing the problem
Of course it was not that straightforward. Aaron realizes that understanding the problem will probably take MUCH more time than he wants to invest, so he goes through all the "standard optimization" stuff and gets some benefit. But, the fundamental problem remains the same: the speed slows down as the square of the number of terms in the query.

Finally, he breaks down and decides to work to understand the problem.

He spends 3 weeks (or was it 6) in just this exercise. An extensive part of his education comes from automated benchmarking; don't leave home without one. Once Aaron truly understands the code, he realizes some design that will have to be changed. I.e. a rewrite. So he does. At the end, all of the lost time is recovered and then some.

Along the way I "relearned" some computer engineering fundamentals and had was thoroughly entertained as well: Benchmarking. Diagrams that describe how the code is organized.

My takeaway is that Aaron reminded me that tough problems require a plan of action that almost always requires an extensive time period to study and understand the code causing the problem. This can be hard to choose when you're in a tough constrained time box. I have to continually "check my footing" before I jump to conclusions about the cause of a problem and attempt a solution before I really understand the problem.

Oh, and checkout for a great free diagramming tool.

It's Time for a Ruby Editor

This talk introduces RedCar, a recent Ruby-implemented editor. Why?
  • Integration - Syntax analysis is easier
  • Convenient - Can extend easier
  • Fun - Not as much a language curve
  • Power - API not limited by
A demo showed examples of the above.

Takeaway: very interesting. I'm still fantasizing about pairing RedCar with Rubinious as the foundation of a truly impressive Ruby IDE. ;-)

Maintaining Balance While Reducing Duplication

David Chelimsky cited chapter-and-verse about the evils of duplication code. That being said, he showed how to remove duplication thoughtfully, that is, without breaking it or making it hard to read.

The guiding principal is that removing duplication should improve code clarity, not obscure it. It therefore helps to remember that DRY calls for the removal of duplicated functionality, not just the minimization of keystrokes. This is so that functionality can be changed in once place.

Another way to look at it is that every piece of knowledge should have a signle unambiguous authoritative representation. Always consider purpose and intention.

Improving DRY means adding levels of indirection. Always make sure that the code depends on other code that is not likely to change.

Suggestions for Making your "DRY-improvements" better:
  1. Depend on things that are less likely to change.
  2. The problem is not that you have to change code in two places. The real problem is that you don't know you need to change it in two places.
  3. Duplication is not always obvious. This is especially pernicious in rspec.
  4. Duplication often results from "feature envy".
Knocking Ruby's Date and DateTime Performance Out of the Park with home_run

Jeremy Evans discusses how the real problem with Date and DateTime performance os the powerful but slow date parsing for date strings. You can improve this if you limit the parsing options.

1 comment:

  1. That's awesome! I'm glad you were able to go to this! Maybe can mentor me into the community :P