jastrachan | 17 Nov 08:06 2004
Picon

Re: Re: Keyword: "any" over "def"


On 16 Nov 2004, at 20:51, Patrick Mueller wrote:

> Jeremy Rayner wrote:
>> ... The only questions would be could I define a method like this:
>>   public Foo myMethod(any mooky)
>> * how would that appear from outside groovy? As a method with one 
>> Object param?
>> public any myOtherMethod()
>> * what would the return type export as to Java? Object again?
>
> Well, I'm a big def-fan (also Python fan), but I have to say, if "any" 
> is going to be a first-class thing in Groovy, then perhaps we should 
> completely do away with 'def', and only allow 'any'.  Better one than 
> two.  ie, the def used to define 'functions' in 'scripts' (instance 
> methods on the script class), would also be changed to use any as 
> well.

Agreed. We only need 1 keyword to be used both to declare methods 
outside of classes and to declare variables. The decision is, is it 
let, def, any or var...

> I still don't quite have the runtime semantics of any vs. Object clear 
> in my head.  I presume that at some point, if an variable, parameter, 
> return, field, etc are typed Object, somewhere in the code, in a 
> strict version of the runtime, someone might actually try to ensure 
> the class of the object was actually Object, vs, not bother checking 
> at all if it was typed any?

The difference is, if you mention a specific type, you are saying to 
the compiler, please perform compile time static type checking and give 
me a compile error if I make a typeo on a method name etc. If you omit 
the type name then the compile will silently let you call anything on 
any object and you'll get a runtime.

The benefit of static typing is we can generate super fast bytecode; 
though the primary difference to the developer is, do you want the 
compiler to catch typeos at compile time or not.

The idea is to make this choice the programmers based on whether or not 
they specify a type restriction. Restricting things to type Object is 
different from not restricting types (e.g. 'any').

> There's also the odd word-play between 'def/define' vs. 'any'.  With 
> 'def', I know I'm defining something (though with variables, it's 
> actually more of a declaration; PL/I's 'DCL' anyone?  Or did I just 
> date  myself? :-)).  'any' ... seems a little more ambivalent.  Not 
> sure if it 'reads' well ...

:)

The leading contenters all seem to be 3 letters long: def, any, let, var

James
-------
http://radio.weblogs.com/0112098/


Gmane