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.

Posted in  | 5 comments

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.

Posted in  | no comments

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:

Gem counts 2008-03

Posted in ,  | 2 comments

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:

  1. DOWNLOAD FROM: rubyforge.org/frs/?group_id=126
  2. UNPACK INTO A DIRECTORY AND CD THERE
  3. 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)

Posted in ,  | 6 comments

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

Posted in ,  | 4 comments

RubyGems 1.1.0 on Apple Ruby

Eric Hodel | Sun, 30 Mar 2008 03:04:14 GMT

There is a bug on updating RubyGems to 1.1.0 on Apple’s Ruby. The workaround is to run:

sudo gem install rubygems-update
sudo update_rubygems

Posted in  | 3 comments

RubyGems 1.1.0

Eric Hodel | Sat, 29 Mar 2008 08:41:00 GMT

Announce: RubyGems Release 1.1.0

Release 1.1.0 adds some new features and fixes some bugs.

New features:

  • RubyGems now uses persistent connections on index updates. Index updates are much faster now.
  • RubyGems only updates from a latest index by default, cutting candidate gems for updates to roughly 1/4 (at present). Index updates are even faster still.
    • gem list -r may only show the latest version of a gem, add --all to see all gems.
  • gem spec now extracts specifications from .gem files.
  • gem query --installed to aid automation of checking for gems.

Bugs Fixed:

  • RubyGems works with both Config and RbConfig now.
  • Executables are now cleaned upon uninstall.
  • You can now uninstall from a particular directory.
  • Updating from non-default sources fixed.
  • Executable stubs now use ruby install name in shebang.
  • gem unpack checks every directory in Gem.path now.
  • gem install now exits with non-zero exit code when appropriate.
  • gem update only updates gems that need updates.
  • gem update doesn't force remote-only updates.
  • gem update handles dependencies properly when updating.
  • Gems are now loaded in Gem.path order.
  • Gem stub scripts on windows now work outside Gem.bindir.
  • gem sources -r now works without network access.

Other Changes Include:

  • RubyGems now requires Ruby > 1.8.3.
  • Release notes are now printed upon installation.
  • gem env path now prints a usable path.
  • gem install reverts to local-only installation upon network error.
  • Tar handling code refactoring and cleanup.
  • Gem::DependencyInstaller's API has changed.

For a full list of changes to RubyGems, 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:

  1. DOWNLOAD FROM: rubyforge.org/frs/?group_id=126
  2. UNPACK INTO A DIRECTORY AND CD THERE
  3. 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)

Posted in ,  | 10 comments

Safari 3.1

Eric Hodel | Tue, 18 Mar 2008 21:08:26 GMT

Safari 3.1 fixed a bug I found with urlbar-less tab reloading and removed the Debug menu, with the important bits split off into the Developer menu. To get the Debug menu from Safari 3.x and earlier, set the IncludeInternalDebugMenu pref via the command line. (I don’t think you’ll need it, though.)

The new Network Timeline is pretty sweet, hit opt-cmd-n to bring it up. Click on the file name to view the file, click on the rest of the line to see the request and response headers.

Posted in  | no comments

.au Sprint

Eric Hodel | Tue, 11 Mar 2008 09:16:16 GMT

I spent Saturday and Sunday at the Sydney Rubinius sprint, and it was quite productive. Not only were local beers sampled, but we also got some good work done.

Lincoln Stoll helped me shake the last bugs out of RubyGems, so we integrated it into Rubinius. We decided to make it a subcommand rbx gem like rbx compile or rbx describe. There are still a few things broken in RubyGems, namely installing gems with extensions because mkmf.rb doesn’t work in Rubinius.

Lincoln also pointed out and gave me patches for a few backwards-compatibility problems with RDoc, so now both RubyGems and RDoc work on Rubinius.

Upon my return next week I’ll be cooking up a release of RubyGems with a handful of bug fixes and persistent connection support for RubyGems’ HTTP fetching which will make those incremental updates quite a bit faster.

Posted in ,  | 1 comment

An RDoc Wiki

Eric Hodel | Fri, 15 Feb 2008 00:14:37 GMT

For fun, I wrote a 200 line wiki a couple of weeks ago using WEBrick and RDoc withRCS as the only external dependency for history. You’ll need a recent build of Ruby 1.9 or Rubinius to run it:

rdoc_wiki.rb

It uses RDoc’s markup for formatting, and stores its content into ~/.rdocwiki as plain text files.

RdocWiki has one special page, /WikiCss that you can use to style things, here’s what I used:

#wiki_edit textarea {
  width: 40em;
  height: 20em;
}
#wiki_edit input {
  display: block;
}
#wiki_restore {
  display: inline;
}

I’d run a copy on Rubinius for you to use, but currently Rubinius is broken on FreeBSD.

Posted in ,  | no comments

Older posts: 1 2 3 ... 19