jastrachan | 14 Jul 13:35 2004

Re: [groovy-dev] Re: [groovy-jsr] Re: [groovy-dev] static binding subsystem for better performance

On 14 Jul 2004, at 05:11, bing ran wrote:
> Frankly I suspect that  "any" will cause more confusion than 
> clarification.
> q1: as John said, is "any" a type  or is it just a mark?

It means, 'any type' or 'dynamic type'.

> q2:  If it's a type, what's the relationship between "any" and Object? 
>  Is
> "any" a super type of Object?

No. Its not a specific type, it just means any type. So a variable of 
type any can hold any object.

> Can I use it to do casting?


> q3: Can I say: assert (myVar instanceof  any)?

No as its not a Java Class

> q4: If "any" means any, does it include void type?

Good point - I'd say no.

> q5: Can "any" be used as the type of method parameters?

Yes. So the idea is for it to be used as the type of

* return types
* variables
* fields
* properties
* parameters

So its a clue to the compiler on when things should be dynamically 
typed or statically typed (i.e. they are given a real type name).

Initially we'd hoped that we could just miss out type information to 
get dynamic typing. But if we're to try avoid a 'let' or 'def' keyword, 
then using any might be simpler. e.g.

class Foo {
     any aField

     any doSomething() {

     Object whatever() {

> I kind of like John's "let", which clearly indicates the purpose of 
> the code
> author: to declare/define a variable/field or a method, although I'd 
> suggest
> reuse "def", in the spirit of not expanding the keyword set of Groovy.
> def a;
> def b = "hello"
> def  void f() {}  // return type required
> class C {
> 	def p1, p2;
> 	def p3 = "hello"
> 	def String sayit() {...}
> 	def closure = {...}
> }
> In all cases "def" is required, not optional.

Agreed - I was hoping we could avoid using def to keep code looking 
similar to Java. i.e. if we're writing statically typed code (even if 
its just at the field / method prototype level) then it'd be cool if we 
could use normal Java syntax

class Foo {
     String x

     Object doSomething(String y) {

One of the reasons I like 'any' is its the same number of letters as 
def/let and the code is the same shape - we don't force everyone to use 
let/def where they are not used to doing so.

> BTW, typing "def" on the keyboard is a lot less stressful than typing 
> "let".
> You use both hands, 3 fingers for "let" and left hand, two fingers for
> "def". It almost feels like nothing.