Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree, better tools are often very quick to write. I'll plug what I think is a lovely piece of code now ;) Here is a tiny toy Ruby framework inspired by Arc https://github.com/julesjacobs/Raamwerk (29 loc, if you don't count blank and end lines). In the examples you can see that even though the framework is a toy you can write interesting applications much more concisely and logically than with e.g. Rails. For example a page that displays a counter, and a link to increase the counter and a link to decrease the counter:

    def counter(i)
      puts "the counter is #{i}"
      link("increase") { counter(i+1) }
      link("decrease") { counter(i-1) }
    end
The quality of the code you're reusing is much more important than the quantity.

Edit. Another example: a stack based calculator.

    def calc(stack)
      tag(:p){ puts stack }
      %w{+ - * /}.each do |op|
        link(op){ calc([stack[0].send(op, stack[1])] + stack[2..-1]) }
      end
      10.times{|n| link(n){ calc([n] + stack) } }
    end
Video demonstration: http://dl.dropbox.com/u/388822/calculator.avi


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: