A
Austin Ziegler
Hi all,
I was just looking at http://boo.codehaus.org/BooManifesto.pdf.
One thing I really kinda like is the optional static typing.
Wouldn't this allow potential compile time error checking and
optimization with a virtual machine running things? I imagine the
syntax looking something like this:
def foo(String s, Hash h)
...
end
I don't like that because it then suggests that this should be
possible:
def foo(String s, Hash h)
end
def foo(Integer s, Hash h)
end
This seems to regress from what I have come to know and love in
Ruby. As I've said, I think that the main purpose for typing hints
is for language interop (e.g., SOAP, CORBA, etc.) so that we can
meaningfully provide services without having to write a lot of
supporting code. I've had a couple of thoughts regarding this.
The first thought comes from C# attributes:
[Attribute(parameters)]
void foo(...) { ... };
Obviously, this won't quite work in Ruby as is, but we don't tag
anything with <>, e.g.:
<parameters(String, Hash)>
<parameters(Integer, Hash)>
def foo(s, h)
end
Strictly speaking, such markup isn't necessarily even "necessary":
parameters String, Hash
parameters Integer, Hash
returns String
def foo(s, h)
end
The "parameters" portion is already feasible because of the
#method_added hook (e.g., you collect the arguments passed to
"parameters" until you see a method definition). Hooking into the
calling of methods is a bit harder, but you could provide heavy,
light, or zero class checking with a bit of work in the interpreter
itself.
I don't see great value in type hinting -- and static typing is a
big lose in Ruby, I think (type inferencing, on the other hand, is
valuable). This might actually be something that can be done, and
done without really harming the flexibility of Ruby.
I like the idea of metadata attributes being added right in the
code; if it's Ruby, that's even neater -- but I don't want to see
type tags put right in the method definition, because I think that
will reduce the overall flexibility of code.
-austin