Static Typing for Ruby
Eric Hodel | Wed, 16 Apr 2008 23:36:00 GMT
Last week I went to a presentation by Jeff Foster about Diamondback Ruby (DRuby), a static type inferencer for Ruby. DRuby's goals are to be simple to use, be flexible enough to handle common ruby idioms, be reasonably useful, and to revert to run-time type checking as needed.
DRuby features its own GLR parser for Ruby grammar with extensions for type annotations and is written in OCaml. Internally it uses a normalized and simplified ruby subset to perform the type analysis in order to remove ambiguities and simplify flow analysis.
Type inference is fed a prebuilt set of type annotations derived from the core library that look very similar to rdoc. The annotation system can handle variable arguments to methods, type intersections and type unions. Basically, this means it's expressive enough to handle String#slice which can be called six different ways.
For details on the type inferencing itself, you should read the paper. There are currently some limitations in DRuby, among them are unsuitability for large applications due to time constraints and too many false positives, it flattens namespaces such that A::C and B::C are considered the same, and it doesn't handle #eval.
On a set of eight benchmark applications, five required some minor modifications for DRuby to operate (described in the paper), and three of the eight had false positives. I found two of the false positives interesting, as I think the code highlighted by DRuby is questionably written.
The false positive in sudokosolver is from a method that returns an Array or false then performs a run-time type check to do the appropriate thing with the results. The false positive in ObjectGraph involves a String that is duck-typed into a StringIO if StringIO wasn't required through a singleton class.
Compared to other static typing add-ons for Ruby, this is the most promising one I've seen. There's no type annotations required to muck up my existing applications (they would be provided with DRuby), no penalties for checking at run-time, and it's smart about functions as convoluted as String#slice.
Unfortunately, since it hasn't been released into the wild yet (the target date we were given was sometime this summer) it's hard to say if it how useful it would be. Judging from the two false positives given, it may have some utility as an equivalent to a flog, though.
PlayStation 3
Eric Hodel | Wed, 16 Apr 2008 09:11:50 GMT
I like my PlayStation 3. I bought it in November when my PS2 was dying of a hacking cough because it couldn’t read disks. I thought the PS3 was alright then, it didn’t make horrible noises and it let me check the Blu-Ray box on Netflix.
I’m semi-disappointed that the PS3 DVD player lost the L3/R3 buttons that subtitles and audio settings that the PS2 had. Now I have to bring up the onscreen menu to turn on and off the subtitle tracks in case I missed or misheard some dialogue.
Since I bought my PS3, the software updates have improved it into a decent console. The PS2 Hitman games now all work on the 80GB (which I bought) and the store was fixed so it isn’t totally stupid for the majority of its users.
The pricing on the store’s downloadable content is reasonable. I’ve bought PixelJunk Monsters, a tower-defense game, flOw, a game where you eat stuff by using the motion-sensors in the controller, Lemmings and PAIN, a physics game that involves slingshotting a character into stuff and watching them scream. Lemmings is slightly handicapped by the PS3 controller, but I really like PixelJunk Monsters and flOw, I’ve certainly gotten my $10 of enjoyment out of them. PAIN is too hard to unlock and doesn’t have enough single-player content to keep my interest.
The most recent PS3 update replaced the old store with a brand new one that’s faster to navigate, unless you want to look at something. It downloads item images as you navigate and doesn’t cache them between runs which is annoying. The new store now knows which demos you’ve downloaded which is a really nice feature, though.
The DualShock 3 controller is much nicer than the SIXAXIS, by both being slightly heavier and having slightly stiffer buttons. Compared to the PS2 controller, the vibration doesn’t seem as powerful and the motors seem noisier. (I’m not sure, as my PS2 is in pieces and I doubt I can keep it alive long enough to start a game.)
The one extra thing I bought for the PS3 is the NYKO Blu-Wave remote so I could control the PS3 with my universal remote (which doesn’t speak Bluetooth) through the Blu-Wave’s USB IR dongle. The remote can be found on Amazon for under $20.
3000 Gems
Eric Hodel | Mon, 14 Apr 2008 22:39:12 GMT
Earlier this month the 3000th gem was released! Here’s how the repository has grown since its early days:

RubyGems 1.1.1
Eric Hodel | Fri, 11 Apr 2008 05:19:00 GMT
Release 1.1.1 fixes some bugs.
Bugs Fixed:
- Gem.prefix now returns non-nil only when RubyGems was installed outside sitelibdir or libdir.
- The gem server gem list now correctly links to gem details.
- gem update --system now passes --no-format-executable to setup.rb.
- Gem::SourceIndex#refresh! now works with multiple gem repositories.
- Downloaded gems now go into --install-dir's cache directory.
- Various fixes to downloading gem metadata.
- gem install --force now ignores network errors too.
- gem pristine now rebuilds extensions.
- gem update --system now works on virgin Apple ruby.
- Gem::RemoteFetcher handles Errno::ECONNABORTED.
- Printing of release notes fixed.
For a full list of changes to RubyGems including credits, see the ChangeLog file.
How can I get RubyGems?
NOTE: If you have installed RubyGems using a package system you may want to install a new RubyGems through the same packaging system.
If you have a recent version of RubyGems (0.8.5 or later), then all you need to do is:
$ gem update --system (you might need to be admin/root)
(Note: You may have to run the command twice if you have any previosly installed rubygems-update gems).
If you have an older version of RubyGems installed, then you can still do it in two steps:
$ gem install rubygems-update (again, might need to be admin/root) $ update_rubygems (... here too)
If you don’t have any gems install, there is still the pre-gem approach to getting software … doing it manually:
- DOWNLOAD FROM: rubyforge.org/frs/?group_id=126
- UNPACK INTO A DIRECTORY AND CD THERE
- INSTALL WITH: ruby setup.rb (you may need admin/root privilege)
To File Bugs
The RubyGems bug tracker can be found on RubyForge at: rubyforge.org/tracker/?func=add&group_id=126&atid=575
When filing a bug, gem env output will be helpful in diagnosing the issue.
If you find a bug where RubyGems crashes, please provide debug output. You can do that with gem --debug the_command.
Thanks
Keep those gems coming!
— Jim & Chad & Eric (for the RubyGems team)
RDoc 2.0.0
Eric Hodel | Fri, 11 Apr 2008 01:21:00 GMT
rdoc version 2.0.0 has been released!
http://rubyforge.org/projects/rdoc
http://rdoc.rubyforge.org/rdoc
RDoc is an application that produces documentation for one or more Ruby source files. RDoc includes the `rdoc` and `ri` tools for generating and displaying online documentation.
At this point in time, RDoc 2.x is a work in progress and may incur further API changes beyond what has been made to the RDoc 1.0.1. Command-line tools are largely unaffected, but internal APIs may shift rapidly.
Changes:
- 3 Major Enhancements:
- Renamespaced everything RDoc under the RDoc module.
- New `ri` implementation.
- Reads from a cache in ~/.ri/ for enhanced speed.
- RubyGems aware, only searches latest gem versions.
- Now up to over 100 tests and 200 assertions.
- 4 Minor Enhancements:
- Switched to an ERb-based TemplatePage, see RDoc::TemplatePage.
- Class/module ri now displays attribute and constant comments.
- Cross-references can be disabled with a leading \.
- Relaxed parsing for some RDoc inline markup.
Bugs:
If you found a bug, please report it at the RDoc project's tracker on RubyForge: http://rubyforge.org/tracker/?group_id=627
Synopsis:
gem 'rdoc' require 'rdoc/rdoc' # ... see RDoc

Articles