published on 18.03.2009 06:10.

Mindmap for Software Craftsmanship Talk

I’m currently preparing a talk on Software Craftsmanship for Euruko 2009 in Barcelona. It’s the first time I try out a mind map for structuring everything related to a topic, and I really like it. By looking at the whole at once, you’re able to see new connections, redundancy, overlap, etc. And it’s more fund to draw stuff than putting everything in nested bullet lists.

I’ve also become a fan of Big Visible Charts, so I prefer creating it by hand instead of using a computerized tool, like MindMeister. Don’t get me wrong – MindMeister is very cool – it’s just that I don’t need it’s advantages of collaboration, change tracking etc. since I’m working on my own.

Two learnings already:

  • always start with a really big sheet of paper on a big wall. You never know in which direction you’re gonna need more space! I failed with that, and it’s probably limiting me currently.
  • use stickies to dump ideas that come to your mind when you’re not really working on the preparation. You don’t waste much time drawing and sorting, but you don’t forget and can pick up or discard the ideas later.

By the way, the Euruko conference artwork is the best I have ever seen. It’s a beautiful blend of Barcelona’s omnipresent Gaudi tiles and color tones and the Ruby logo.

Posted in ,  | Tags , , , , , ,  | no comments | no trackbacks

published on 21.07.2008 00:19.

loading data from mysql into couchdb with rest and ActiveRecord

$KCODE = 'u'

require 'rubygems'
require_gem 'activerecord'
require 'rest_client'

class MyModel < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection(
  :adapter => "mysql", 
  :database => "hello_world", 
  :encoding => 'UTF8'
)

MyModel.find(:all).each do |record|
  p RestClient.post('http://localhost:5984/hello_world', record.to_json)
end

Posted in ,  | Tags , , , , ,  | no comments | no trackbacks

published on 22.06.2008 16:23.

Ruby on Rails developers use Macs? You must be kidding!

taken at the Rails Konferenz 2008 by patrick lenz.

Posted in , ,  | Tags , , , ,  | no comments | no trackbacks

published on 07.10.2007 14:02.

so what's duck typing?

duck typing is actually a simple concept. the best explanations i have come across (from wikipedia 1, 2):

»Suppose you see a bird walking around in a farm yard. This bird has no label that says ‘duck’. But the bird certainly looks like a duck. Also, he goes to the pond and you notice that he swims like a duck. Then he opens his beak and quacks like a duck. Well, by this time you have probably reached the conclusion that the bird is a duck, whether he’s wearing a label or not.” (Immerman 1982, p. 102)«

So, in programming, duck typing is a style of dynamic typing in which an object’s current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class, or implementation of a formal interface.

The ruby mailing list has a great post called ”How to duck type? - the psychology of static typing in Ruby”, explaining the rationale and why duck typing is a good thing (in ruby). an excerpt:

»Many people coming to Ruby from a statically-typed language are somewhat afraid of Ruby’s dynamism, or “don’t get it(TM)”. David Black and I (edit: Tim Bates) believe that this is in part because it is thought that the uncertainty and changeability built into Ruby are dangerous and one wants to find shelter from them.«

Posted in ,  | Tags , ,  | no comments

published on 18.04.2007 13:37.

"This path leads to the gates of madness."

»Because if itself is an expression, you can get really obscure with statements such as:«

if artist == "John Coltrane"
  artist = "'Trane"
end unless nicknames == "no"

from the original pickaxe by dave thomas.

Posted in ,  | Tags , , ,  | 1 comment

published on 18.03.2007 11:20.

ruby: performance comparison of rexml and libxml

update: here’s the same for PHP’s XML Parser.

a quick comparison of the two libraries available for processing XML in ruby shows dramatic performance differences.

am i missing something, is there a fundamental flaw in the test? of course REXML is pure ruby, while libxml is C; but can the difference really be so huge?

loading an xml file

file size libxml REXML factor
10KB 0,83 39,17 47,0
100KB 6,67 306,56 46,0
1.6MB 71,88 3954,21 55,0

simple xpath expression

file size libxml REXML factor
10KB 0,12 124,68 1004,7
100KB 0,67 678,11 1016,8
1.6MB 6,21 22578,18 3633,6

the test code

def benchmark
   start = Time.new.to_f
   10.times { yield }
   puts ((Time.new.to_f - start) / 10) * 1000
end

doc = nil

# exclude the effect of filesystem caching (makes sense?)
File.read('products.xml')

#
# libxml
#
require 'rubygems'
require 'xml/libxml'

benchmark do
   doc = XML::Document.file("products.xml")
end

benchmark do
   doc.find('//articles/article/shortdesc').each do |node|
      #puts node.content
   end
end

#
# rexml
#
require "rexml/document"

benchmark do
   doc = REXML::Document.new File.read("products.xml")
end

benchmark do
   doc.elements.each("//articles/article/shortdesc") do |node| 
      #puts node.text
   end
end

Posted in , ,  | Tags , , , ,  | no comments

published on 28.02.2006 20:31.

Ruby tip of the day

EDIT (11.11.2007): Dir#glob (aliased as: Dir[]) could also be used.

find all files in a directory matching some pattern

list = Dir.new('.').entries.select { |f| f =~ /_\d{2}.(jpg|gif)$/ }
=> ["11-029_42.jpg", "1209-180_32.jpg", "1210-180_32.jpg", "1218-180_32.jpg"]

list.size
=> 4

Posted in ,  | Tags

published on 31.01.2006 23:25.

completely useless ruby code

this chunk of code is completely useless, apart from the fact that it let me practise how ruby does arrays, objects, constants, observers and singletons. and how to pass a variable number of arguments to a function method and set defaults for arguments that weren’t passed. plus it had me thinking about “what-goes-where” and coupling in object oriented programming.

maybe not so useless after all!

#
# for documentation see the UML diagram at the following url
# @url <a href="http://www.flickr.com/photos/calicojane/93113537">http://www.flickr.com/photos/calicojane/93113537</a>
#
require 'observer'
require 'singleton'

class StickFigure
   MALE = 0
   FEMALE = 1   
   attr_reader :name
   def initialize(attrs)
      @name     = attrs[:name] ||= 'Anonymous Coward'
      @sex      = attrs[:sex] ||= MALE
      @is_lazy  = attrs[:is_lazy] ||= false
      @in_peril = false
   end
   def in_peril!
      @in_peril = true
      puts @name + ' is in peril!'
   end
   def to_s
      puts "\nHi! I'm " + @name + ' and I am ' + (@is_lazy == true ? 'a little' : 'not') + ' lazy.'
   end   
   alias :introduce_self :to_s   
end

class CoffeeDrinkingStickFigure < StickFigure
   def have_coffee
      puts @name + ' has a cup of coffee.'
      pot = get_coffee_pot
      pot.pour_coffee
      if pot.needs_refill?
         make_more_coffee unless @is_lazy
      end
      return_to_desk
   end

   #
   # :TODO: the stickfigure should NOT be responsible for notifying it's observer ... better solution?
   # this part is not so pretty.
   # 
   def return_to_desk
      puts @name + ' returns to ' + (@sex == FEMALE ? 'her' : 'his') + ' desk.'
      get_coffee_pot.notify_observers(get_coffee_pot, self)
   end   
   def make_more_coffee
      puts @name + ' refills the coffee pot.'
      pot = get_coffee_pot
      pot.refill
   end   
   private
   def get_coffee_pot
      CoffeePot.instance
   end   
end

class CoffeePot
   include Singleton
   include Observable
   attr_reader :cups_left
   CUPS_WHEN_FULL = 2.5   
   def initialize
      @cups_left = 0
      self.refill
      self.add_observer(BigBrother.new)
   end   
   def pour_coffee
      @cups_left -= 1
      changed
   end   
   def refill
      @cups_left = CUPS_WHEN_FULL
      changed
   end
   def is_empty?
      @cups_left == 0
   end   
   def needs_refill?
      @cups_left < 1
   end   
end

class BigBrother
   def update(pot, who_got_coffee)
      if pot.needs_refill?
         puts 'The coffee pot needs a refill and ' + who_got_coffee.name + " didn't refill it!\n"
         who_got_coffee.in_peril!
      else 
         cup_string = pot.cups_left == 1 ? 'is 1 cup' : 'are ' + pot.cups_left.to_s + ' cups'
         puts "There #{cup_string} of coffee left."
      end
   end
end

stick_figures = [
   CoffeeDrinkingStickFigure.new(:name => 'Miss Piggy', :sex => StickFigure::FEMALE),
   CoffeeDrinkingStickFigure.new(:name => 'Bert'),
   CoffeeDrinkingStickFigure.new(:name => 'Kermit', :is_lazy => true),
   CoffeeDrinkingStickFigure.new(:name => 'Ernie', :is_lazy => true)
]

stick_figures.each do |stick_figure|
   stick_figure.introduce_self
   stick_figure.have_coffee
end

Posted in , ,  | Tags , ,