jastrachan | 16 Nov 16:14 2004
Picon

Re: Keyword: "any" over "def"


On 16 Nov 2004, at 15:11, Jeremy Rayner wrote:

> Hi,
>
> 'def', short for 'define' I assume.
>
> 'define' is a transitive verb, where the property/method name is the
> subject and the actual definition is the object.
>
> def foo {return bar}
> (subject of define is foo)
> (object of define is {return bar})
>
> def mooky
> (subject of define is mooky)
> (object of define is undefined)
>
> def String foo {return bar}
> (subject of define is foo)
> (object of define is {return bar} which is of type String)
>
> 'any' is a pronoun, and takes the place of a noun (e.g. MyObjectType, 
> int, etc)
> 'any' feels almost like the natural opposite of 'void', giving a sense
> of symmetry
> 'any' isn't half a word
> 'any' indicates something is coming back from the method,
>    i.e. parser will give noisy error with return from an 'void' method,
>      and vice versa
>
> I'm currently in favour of 'any' as it can easily be substituted in
> the places where
> you would normally in the language use Object, MyType or 'void'
>
> The only questions would be could I define a method like this:
>   public Foo myMethod(any mooky)

Yes

> * how would that appear from outside groovy? As a method with one 
> Object param?

Yes

The difference is, groovy would know the difference between any and 
Object and so would use dynamic typing. Though parameter types are 
currently optional, so the 'any' is currently optional but having the 
same meaning. e.g.

public Foo myMethod(mooky) { ... }

is the same, currently as

public Foo myMethod(any mooky) { ... }

> public any myOtherMethod()
> * what would the return type export as to Java? Object again?

Yes.

Though again, the difference is the meaning when using this method 
inside Groovy.

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


Gmane