{ |one, step, back| } 75 to 84 of 193 articles Syndicate: full/short

RubyConf.new(2005) (Friday)   14 Oct 05
[ print link all ]

Conference Introduction

David Allen Black welcomed us to the conference and gave us some background on the conference hotel. Evidently the hotel was quite the Hollywood get-away spot for a number of years. A lot of our rooms are named for Hollywood stars (I’m staying in the Joan Crawford room).

Top to Bottom Testing (Francis Hwang)

Some really cool ideas on testing. Francis talked about MockFS and mocking in Lafcadio. He emphasizes the importance of testing and making is easy (so programmers will write them) and fast (so programmers will run them).

The question/answer period brought up the whole mock vs stub nomenclature. There was also a lot of discussion on the use of mock databases.

Francis talked about the ability to redefine the standard File and Dir constants to point to the mock file system versions. During lunch I mentioned the Constant Injection technique I used in my OSCON 2005 dependency injection talk.

open-uri: easy to use and extensible virtual file system (Akira Tanaka)

open-uri replaces the standard open method and will automatically use the HTTP protocol to grab web pages and present them as regular file reads. RubyGems uses open-uri for some of its work.

Tanaka also explored some design principles for building APIs and applied them to the open-uri library. He then briefly talked about how to tie into the open-uri Virtual File System (VFS).

JRuby (Charles Oliver Nutter)

I’m really excited about JRuby on many levels. If nothing else, it lowers the barrier to those exclusive Java oriented development organizations. After a rather long dormant period, JRuby development has really kicked off. Charles walked through some current implementation issues and talked a bit about the future directions.

JRuby’s new “stackless” implementation looks very interesting. I’m wondering if using some of the same techniques in the standard C Ruby implementation would make continuations better/faster.

YARV Progress Report (SASADA Koichi)

Koichi started his presentation with his usual humor using some “insider” Ruby jokes (and some “insider” Japanese humor … RubyMa!)

Most of the presentation dealt with many of the techniques used by YARV to be the fastest Ruby VM possible.

Best quote of the slides:

“Dynamicity is your friend, but my ENEMY

MetaRuby: Reimplementing Ruby in Ruby (Eric Hodel)

MetaRuby is an interesting implementation of Ruby written entirely in Ruby. Coupling this with the Ruby2C project will (should) give you the ability to write almost the entire Ruby system in ruby and yet get comparable performance to a C based system.

Eric shared some about some of the strange implementation issues they ran into as they implemented the C code as Ruby code.

Supper

Up next after supper … the round table with Matz


comments

Innovative Identification   28 Sep 05
[ print link all ]

Dick Hardt’s OSCON 2005 keynote talked about how to identify yourself online. Here’s an IRC conversation the ensued after I accidently issued a sudo command on a friend’s system, one that is monitored very closely by the sysadmin.

[22:35] <paulv>    matthew immediately declared that we were already cracked. :)
[22:35] <matthew>  yeah, it's all good.  Although, can you prove you're Jim?
[22:35] <jweirich> yes
[22:35] <jweirich> ask me a Ruby question
[22:35] <paulv>    implement the Y-combinator!
[22:35] <matthew>  heh
[22:35] <paulv>    then I'll believe.
[22:36] <jweirich> p proc { |le|
[22:36] <jweirich>   proc { |f| f.call(f) } \
[22:36] <jweirich>   .call ( proc { |f|
[22:36] <jweirich>            le.call (proc { |x| f.call(f).call(x) }) })
[22:36] <jweirich> }.call(proc { |recurse|
[22:36] <jweirich>   proc { |n|
[22:36] <jweirich>     if n == 0 then
[22:36] <jweirich>       1
[22:36] <jweirich>     else
[22:36] <jweirich>       n * recurse.call (n-1)
[22:36] <jweirich>     end
[22:36] <jweirich>   }
[22:36] <jweirich> }).call(5)  
[22:37] <matthew>  wow.  This is better than gpg keys.
[22:37] <matthew>  I hope you had that laying around 
[22:37] <jweirich> nah, did it from memory ;)
[22:37] <paulv>    this *is* better than GPG keys.

(and for those that missed the winking smiley, no, I did not do this from memory)

Update

I see that Dick Hardt’s OSCON 2005 presentation on Identity 2.0 is available at http://www.identity20.com/media/OSCON2005. This is worth seeing.


comments

Today's One Liner   18 Sep 05
[ print link all ]

I don’t usually talk must about one-liners, but here’s one I used today.

ARGF and inject ... Two Great Tastes that Taste Great Together

Consider the following ruby one-lineer

ruby -e 'p ARGF.inject(0) { |sum, line| line.split[1].to_i + sum }'

Breaking it down, it …

  • Iterates over each line of standard input (ARGF.inject(0))
  • Splits the line into colums (line.split)
  • Selects the second column ([1])
  • Converts the second column to an integer (.to_i)
  • Adds to to the running subtotal (+ sum)
  • And prints the final sum (p)

In short, it sums up the numbers in the second column of a text file.

Cool. Now combine it with another one-liner …

lynx -dump http://gems.rubyforge.org/stats.html \
  | ruby -e 'p ARGF.inject(0) { |s,t| t.split[1].to_i + s }'

And you get the result …

1005821

... which is the number of gems served by RubyForge to date.

Over 1 million gems served :)


comments

David Geary Wows the Crowd with Rails   21 Aug 05
[ print link all ]

Here’s a story of one of those perfect presentation moments ... inspite of the horror of a demo failing minutes before the presentation starts.

David describes a recent presentation at the Salt Lake City No Fluff, Just Stuff symposium where a live rails demo leaves the crowd speechless.


comments

CSS Builder   19 Aug 05
[ print link all ]

Ruby Everywhere! Scott Baron has a cool idea that puts Ruby in yet other piece of the web framework.

CSS Builder

Scott was thinking about the problem of redundancy in a CSS style sheet (e.g. repeating the colors of a color scheme a zillion times throughout the file).

His solution? A builder-like CSS constructor. Yes! Ruby everywhere! Go read his blog for the details.


comments

Breedlove Tour   16 Aug 05
[ print link all ]

Extra-Curicular Activities during OSCON Week.

The Breedlove Guitar Company

During the week of OSCON, I took Monday off to drive down to Tumalo Oregon and take a tour of the Breedlove Guitar factory. I’ve owned a Breedlove guitar for 6 years and really love it. This was a fanstastic chance to see the place where it was made. I’ve posted some pictures from the tour if you would like to see them.


comments

Martin Fowler Writes About Rake   11 Aug 05
[ print link all ]

Fowler: After all until we tried it I thought XML would be a good syntax for build files..

Martin Fowler On Rake

Martin Fowler has written a great introduction to using Rake for building systems. The article is gentle and doesn’t assume a deep knowledge of Ruby.

Go read it now. You know you want to.


comments

OSCON 2005 Is Over   06 Aug 05
[ print link all ]

What a time! Here is a quick summary and overall impressions of the conference.

My Talks

Both of my talks, the Dependency Injection In Dynamic Languages and the 10 Things Every Java Programmer Should Know about Ruby, went well. Evidently, they were turning people away form the door for the “10 Things” talk (the room was small).

Both Howard Lewis Ship (of HiveMind) and Paul Hammant (of PicoContainers) attended the dependency injection talk. Howard pointed out a limitation in constructing object graphs with cycles in the current DIM implementation. Hivemind fixes that by introducing proxy objects. I’m wondering if DIM can do it without proxies. I’ll post later on this.

Ruby at OSCON

Ruby, and in particular Ruby on Rails, was getting a lot of notice at the conference. Here’s some items that come to mind.

  • In the keynote talk on O’Reilly’s Radar project where O’Reilly tries to keep a finger on what’s up and comming, Tim and Nat see Ruby on Rails as possibly the “Perl of Web 2.0”.
  • Both of Monday’s Tutorials on Ruby and Rails were very well attended. Several of the Ruby sessions on Thursday played to standing room only croweds.
  • David Heinemeyer Hannson’s keynote talk on the Secrets of Ruby on Rails did a good job of highlighting the philosophy behind the framework.
  • In his keynote talk “On Evil”, Danny O’Brian described the Gandhi method of preventing evil: First they ignore you, then they laugh at you, then they fight you, then you win. Danny noted that most groups haven’t figured out how to move from one state to another, and that the actual sequence is a bit more complicated than the simple progression laid out by the maxim. In particular Ruby seems to have gone directly from the “ignore” state to the “win” state in about 3 weeks.
  • Why’s talk, “A Starry Afternoon, a Sinking Symphony, and the Polo Champ Who Gave It All Up for No Reason Whatsoever” would have been sold out, but O’Reilly moved it at the last minute to the main ballroom and ran it during the afternoon break. Although plagued with some technical difficulties (such as the projection screen placed where Why couldn’t see the screen, and missbehaving mplayer sessions), the presentation had the whole room rolling on the floor. Why is going to upload the videos to his Redhanded website in the near future, make sure you check them out. Did anyone record the Thirsty Cups’ rendition of the “Ruby Syntax Song” or “May I Recommend Ruby”?

OSCON in General

I really enjoyed a number of keynote talks. Here’s some of the memorable ones:

  • TCP/IP and Shipping containers by Nick Gall. Yes, what do shipping containers and the TCP/IP protocol have in common? Nick compared the two and tried to come up with the characteristics of a technology that has potential for long term viability.
  • Open Source Biology by Drew Endy. Drew highlighted how many of the basic building blocks in DNA research are being patented and impending inovation in that field.
  • Identity 2.0 by Dick Hardt. Dick gets extra points for not only a interesting talk, but getting his point across in a fast paced, well written monologue that didn’t let your eyes wander from the screen for fear of missing something.

I’m not going to write up all the sessions I sat in on, but here are a couple of things that I found interesting.

  • I sat in a on Advanced Groovy talk by Rod Cope. I’ve not been following Groovy recently. I see the syntax has been refined a bit since the last time I looked at it. Rod claims that performance is now 20% to 90% of Java, quite a bit faster than the last time I looked. Ruby’s Builder::XmlMarkup (which is available as part of Rails) was stolen directly from ideas in the Groovy community, so keeping an eye on Groovy is definitly worthwhile.

Non-OSCON Stuff

Portland is great. The public transportation here is outstanding and the city is wonderful. While I have been attending OSCON, my wife has been exploring the city and its many gardens and museums. After OSCON closed, Helen and I went had a late lunch in the Chinese quarter and then hopped on over to Powell’s city of books. Powell’s is a bookstore covering an entire city block. Heh, they give you a map when you enter the store. I could have spend hours there ... well, hey, I guess I did.

On Monday, Helen and I took a tour of the Breedlove Guitar Company, a small guitar company near Bend, Oregon. (Did I mention I own a Breedlove guitar? ... wonderful instrument). It was a four hour drive from Portland, but it was well worth it. I took plenty of pictures there and will probably write up the Breedlove tour in more detail later.

Today, Helen and I will be puttering around Portland a bit more, then start back to Cincinnati on Sunday.


comments

Speaking at the Columbus Ruby Brigade   15 Jul 05
[ print link all ]

Last chance to hear the “Dependency Injection” talk before OSCON.

To Columbus!

Joe O’Brian and Robert Stevenson of the Columbus Ruby Brigade (CRB) have invited me to come up to Columbus to speak to their group. It will be the last “practice” presentation of the “Dependency Injection In Ruby” talk that I have prepared for the O’Reilly Open Source convention (OSCON) coming up the first week in August.

So, if you are in or near Columbus next Tuesday night (July 19, 2005), stop by and say hi. I’d love to meet you.

Here’s the CRB announcement:


A language that doesn’t affect the way you think about programming, is not worth knowing. —Alan Perlis

The Columbus Ruby Brigade and Quick Solutions are proud to sponsor noted speaker, Jim Weirich, on July 19th at 6pm (Food served at 5:30pm) to give a talk on Dependency Injection titled, “Dependency Injection : Vitally Important or Completely Irrelevant?”

Jim will be giving his talk that he will also be giving at the O’Reilly Open Source Conference on August 4th in Portland, Oregon. That’s right folks … you’ll hear it here first!

So, for most of you, I’m sure you have a number of questions swirling in your head:

  1. Who is Jim Weirich?
    • (Official O’Reilly Bio) Jim Weirich is a software consultant for Compuware with over twenty-five years of experience in software development. He has worked with real-time data systems for testing jet engines, networking software for information systems, and image processing software for the financial industry. Weirich is active in the Ruby community and has contributed to several Ruby projects, including the Rake build system and the RubyGems package software.
    • (Rob’s Unofficial Bio) Jim is a world-renowned Ruby “Sensei” who has contributed the RubyGems and Rake build system that are used by just about every Ruby programmer out there. Also, Jim is very active on the Ruby and Ruby on Rails mailing lists helping out with answers and articles (http://onestepback.org) regularly.
  2. What’s the Columbus Ruby Brigade?
    • The Columbus Ruby Brigade (CRB for short) is the name for the local Ruby Users Group that was started earlier this year. The Seattle Ruby UG gets credit for the unique naming convention that most other Ruby UGs have adopted. The CRB was started because there’s a growing community of Ruby and Ruby on Rails enthusiasts here in Columbus that we know is going to continue to grow because of the fact that the Ruby language (and killer apps like Ruby on Rails) is more fun to program with than Java and .NET combined. Try it out for yourself and see!
  3. What’s this talk really about?
    • Here’s the O’Reilly promo about Jim’s talk: The Dependency Injection Pattern (also known as Inversion of Control) is a technique to reduce the amount of coupling in a program. Since reduced coupling is a noble goal of software developers everywhere, dependency injection is an important technique to know. The Java community has seen numerous frameworks built around dependency injection and inversion of control (e.g. Hivemind, Spring, Pico Containers). But programs written in a dynamically typed language are already fairly decoupled compared to programs written in stiffly typed langauges. Is dependency injection still important in a language like Ruby, or is it yet another technique from the Java world that has no place in the dynamic world of Ruby programming? We will look at basics of dependency injection and develop a simple dependency injection framework in Ruby. We will compare the framework to other decoupling techniques.

Here’s your chance to sit in on a presentation given by a true software craftsman to hear about Dependency Injection and specifically how it applies (or doesn’t!) to dynamic languages like Ruby. The CRB is really excited that Jim has volunteered his time to drive up and give us a presentation that you can only hear at a premier conference like OSCON.

Hope you can make it!


Here’s the location/general information:

  • Date: Tuesday, July 19th
  • Time: 6pm-9pm (Food served at 5:30pm)
  • Location: Quick Solutions 9000 Antares Ave Columbus OH 43240
  • Google Map: http://rubyurl.com/9aJ

If you look at the satellite image, the building is just NE of the Google Map marker (Triangular building). The parking lot isn’t huge, so there’s overflow parking to the lot just to the N / NE of the Quick building. FYI.


comments

Thinking in Ruby   05 Jul 05
[ print link all ]

A language that doesn’t affect the way you think about programming, is not worth knowing.—Alan Perlis

Alan Perlis, the first head of the Carnegie Mellon University Computer Science Department and the first recipient of the Turing Award, recorded some of his accumlated knowledge about programming in a series of one sentence statements. You can read more about his Epigrams here.

I especially like number 19, about learning programming languages (quoted above). That’s the big reason the Pragmatic Programmers recommend learning a new language every year. To expand the way you think.

Thinking Different

Here’s an example of one way that Ruby affects the way you can approach a problem. I was preparing for my Dependency Injection talk (to be given as OSCON) and was working out the details of an example program I was using to demonstrate some DI features. I chose the “Mark IV Coffee Maker” problem from “Robert Martin:http://objectmentor.com (used with permission). I love the coffee maker problem and have used in C++ and Java courses over the years. It is simple enough to grasp in a teaching scenario, but rich enough in objects to be interesting. And because it is a physical control system, a lot of the objects are simple analogs to physical devices and therefore easy for beginning OO designers to work with.

I’ve written code for this example, oh, probably half a dozen times over the years; sometimes in C++, sometimes in Java (and once in Eiffel if I recall correctly). The solution changes with each iteration, but there are some common themes that keep appearing.

Java Coffee

One small part of the problem deals with a Brewer object that needs to control a Heater object (which implements an On/Off device interface) and a relief valve (which conforms to an open/close device interface). This is an excellent place to introduce two design patterns to the students. The first is the composite pattern where we create a Boiler object that is a composite of both the Heater and Relief valve. The Boiler becomes a single object to the brewer which just issues on/off commands to the boiler. The boiler is responsible for making sure all its subcomponents (the heater and the relief valve) are properly operated.

The composite pattern works by allowing the composite to forward the on/off commands to each of its subcomponents, but the valve wants to recieve open/close commands, not on/off commands. Here is the second pattern that emerges from this portion of the design: the Adapter Pattern. By wrapping the relief valve in an on/off adapter, the boiler composite sees a unified on/off interface that is translated for the valve to an open/close interface.

For the Dependency Injection talk, I was developing both a Java verison and a Ruby version in parallel. The Java version was straight forward and I implemented it like I normally do. The only big design choice is how to map on/off commands to open/close. For the coffee maker, on needs to map to close and “off” needs to map to “open” (when the boiler is off, the relief valve needs to be open to relieve the steam pressure).

The opposite mapping might make sense in other problems, and you alway think about making classes like the OnOffAdapter a bit more flexible so that it can be used in the other situations. I considered adding a flag to the adapter constructor to allow the user to select the desired mapping, but decided against it. I didn’t need it for this problem and felt the additional logic would just get in the way.

The Ruby Adapter

So now it was time to write the Ruby version. The straight forward implementation of of the Ruby adapter is simply:

  class OnOffAdapter
    def initialize(device)
      @device = device
    end
    def on
      @device.close
    end
    def off
      @device.open
    end
  end

Once written, I again considered adding a flag, but suddenly realized there was a better solution:

  class OnOffAdapter
    def initialize(device, on_command, off_command)
      @device = device
      @on_command = on_command
      @off_command = off_command
    end
    def on
      @device.__send__(@on_command)
    end
    def off
      @device.__send__(@off_command)
    end
  end

Instead of a flag that would only switch between two different on/off and open/close mappings, by adding the commands themselves to the interface I get an adapter that will adapter any device to an on/off interface (well, almost any device … keep reading).

To use the device in my coffee maker example, all I need is:

   valve_adapter = OnOffAdapter.new(relief_valve, :close, :open)

Once I took the step of making the open/close commands generic, I realized that I could make the on/off generic as well.

  class Adapter
    def initialize(device, mapping={})
      @device = device
      @mapping = mapping
    end
    def method_missing(sym, *args, &block)
      command = @mapping[sym]
      if command.nil?
        super
      else
        @device.__send__(command, *args, &block)
      end
    end
  end

Usage is now:

  valve_adapter = Adapter.new(relief_valve,
    :on  => :close,
    :off => :open)

I now have a generic adapter that will do a one-to-one mapping from one set of methods to another set of methods.

Continued Refinement

But is doesn’t have to stop there. As an exercise for the student, consider what it would take to add the following refinments:

  • Allow mappings that translated on and off commands to something like brightness_level(10) and brightness_level(3). (Hint: think about procs).
  • Allowed methods that were not mapped to pass through unchanged.
  • The current version creates an object that does the adaptation. If you need a bunch of similar adapters, would it be better to return a class whose instances are adapters implementing the defined mapping? How would one implement that.

Beyond Java

The point of this posting is not to bash on Java. Certainly you can create generic adapters in Java that can do much the same mappings as the Ruby version. But getting from the specific to the generic adapter is a big step, big enough that my YAGNI filtered kicked in and I didn’t go down that path in Java.

In Ruby, the step was small enough that refining the adapter was very easy and natural. And the end result yielded some worthwhile insites into the adapter pattern as well.


comments

 

Formatted: 24-May-13 16:05
Feedback: jim@weirichhouse.org