The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Static Duck Typing?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Static Duck Typing? Posted: Apr 13, 2006 8:52 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Static Duck Typing?
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
I've been reading over Michael Feather's entry Is Static Typing a Form of Bad Coupling? and subsequent comments. Then I read over Christopher Diggins' Bridging Static and Dynamic Typing entry.

That got me thinking about Ruby, and previous conversations regarding optional static typing. Maybe we're approaching this from the wrong end of the stick. Instead of checking type, we should use duck typing, but in a static fashion.

Whoa, stop laughing and hear me out.

Currently in Ruby, a traditional duck typing approach looks like this:
def foo(arg)
   raise SomeError unless arg.respond_to?(:bar)
   ...
end

What if we could marry the concept of static typing with duck typing? Then, the syntax might look like this:
def foo(arg{:bar})
  ...
end

Then we add a compile time step to Ruby (remember, I'm in fantasy land here), so that if you try to pass any object to the foo method that doesn't respond to bar, it would automatically raise a NoMethodError without you having to add your own respond_to? checks. Perhaps this would have the side effect of improving speed and/or intellisense. Maybe.

Cool? Stupid?

Read: Static Duck Typing?

Topic: My DVCS wishlist Previous Topic   Next Topic Topic: Care and Feeding of Timeout.timeout

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use