From: "Mauricio Fern�ndez" Date: 2002-09-27T07:26:07+09:00 Subject: Re: adding overload to ruby On Fri, Sep 27, 2002 at 06:17:23AM +0900, William Djaja Tjokroaminata wrote: > 2) Now, all those class names (at least the built-in classes) will also be > keywords in declaring variables: > > Fixnum a I'd prefer something really horrible so newcomers don't start coding as if it were Java... Say make_statically_typed_variable Fixnum, :a (no, no shorter alias, let it that long and make it *impossible to alias* :-) Another side effect is that the parser doesn't need to change, the modifications must be done on the AST level. > a = 10 # fine > a = 'abc' # --> run time syntax error > b = 'abc' # fine, b is "untyped" def foo 4 end a = 10 # ok b = foo # ok too a = b # FAIL as b is statically typed class Argh def foo ... end end make_statically_typed_variable Argh, :a a.foo # ok class Argh def bar end end a.foo # OK a.bar # �? a.bar should fail to compile, because we have no idea when bar will be added to Argh. But this means Ruby has to remember the state of the static type of a variable (the class when we did make_statically_typed_variable) for _each_ variable. Either this or have a way to freeze classes, but we almost certainly don't want this... > All the Ruby internal object models stay the same. Only the > parser/interpreter will have to work harder in keeping the type of each > variable and checking when assignment is being made. > > Of course, we can later decide whether the checking is based on > "instance_of?" or "kind_of?" or even a mix of the two; but that is > secondary. It buys you little type-safety-wise. We can only get some speed in method lookup, but not that much :-| -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com People are going to scream bloody murder about that. -- Seen on linux-kernel