Ruby (4 blogmarks)

← Blogmarks

On Ruby: Sequel Interview with Jeremy Evans

https://on-ruby.blogspot.com/2009/01/sequel-interview-with-jeremy-evans.html

Here a couple fun pearls of wisdom from the vault of time in this 2009 interview with Jeremy Evans, the maintainer of Sequel.

On test coverage:

I test coverage before every release, anything less than 100% gets fixed. 100% code coverage means nothing, but less than 100% code coverage means something.

Refactoring should be in service of something:

There are parts of Sequel that could definitely do with refactoring, but I generally wait to refactor until I'm going do make changes to the code that refactoring will help. I don't refactor for it's own sake.

Finding a balance with when to use Test-Driven Development:

I use TDD when the problem space is known and I know what outputs I want for each input. I'd say I do TDD for new features about 50% of the time, and about 90% of the time for bug fixes.

Shrinking Ruby Hashes

https://byroot.github.io/ruby/performance/2026/08/05/shrinking-ruby-hashes.html

I had no idea Ruby hashes had this much of a memory footprint (relative to struct).

It’s super impressive to see the small steady improvements the Ruby core team / contributors are able to squeeze out by doing hyper-specific, low-level optimizations.

Reading this post reminded me of some of the Aaron Patterson talks I’ve seen.

I don't have much practical use for this kind of under-the-hood perf optimization analysis in my day-to-day. However, I do find it interesting to see the bits of Ruby code one can use to pull out these kinds of memory footprint numbers -- primarily ObjectSpace.memsize_of.

Here is some of my own basic fiddling:

> require 'objspace'
=> true
> ObjectSpace.memsize_of(1)
=> 0
> ObjectSpace.memsize_of("Hello, World!")
=> 40
> ObjectSpace.memsize_of([1,2,3])
=> 40
> ObjectSpace.memsize_of({[1,2,3] => :abc})
=> 160

And here is a snippet of measuring code from the post:

require 'objspace'
puts "Ruby: #{RUBY_VERSION}"

11.times do |size|
  struct_class = size.zero? ? Object : Struct.new(*size.times.map { |i| :"m_#{i}" })
  struct = ObjectSpace.memsize_of(struct_class.new)
  hash = ObjectSpace.memsize_of(Hash[size.times.map { |i| [i, i] }])
  diff = (hash.to_f / struct).round(1)
  puts "size: #{size} \tstruct: #{struct} \thash: #{hash} \tdiff: #{diff}x"
end

Ruby for "shell scripting"

https://ratfactor.com/cards/ruby-shell-scripts

Ruby is a really good Unix citizen and I think it’s woefully underused as a general-purpose "scripting" language.

This article is a nice background and introduction to using Ruby for scripting. I've always felt that small, expressive scripts are one of Ruby's strong suits. When I need a personal one-off script to automate a set of steps, I almost always reach for Ruby.

Here is a fun tidbit:

I think this ancestral timeline may be interesting:

  • 1977 AWK by Aho, Weinberger, and Kernighan

  • 1987 Perl by Larry Wall

  • 1995 Ruby by Yukihiro Matsumoto

I had no idea that awk was so named because it is the initials of the creators.