jastrachan | 29 Nov 10:56 2004

Re: variable declaration syntax: use cases and thoughts

On 28 Nov 2004, at 15:01, Jochen Theodorou wrote:
> Xavi MirĂ³ schrieb:
>>> I think the questione "do we need a variable declaration token" 
>>> depends much on the cases we want groovy to be used for. If we want 
>>> to make another "usefull for all things" language we have to think 
>>> of bigger projects to be done in groovy.
> By writing this I also thought about the "option excplicit" or "use 
> strict" of VB and perl. In pascal like languages the noise of "var" is 
> reduced because there is only one place where you can declare 
> variables and that's outside the normal code block. I liked the idea 
> of having to declare variables in methods because of typos, but the 
> more I think about it I don't like it that much. Currently the 
> variable declaration token is optional, right? why not a mechanism 
> like in perl or VB to define when a variable declaration token is 
> needed and when it is optional? And BTW:
> for (var int i=0; i<I_MAX; i++) {
>  /* do something */
> }
> I don't like this one... and saying "var" is not needed if a type is 
> given seems to be confusing... why is it sometime optional and 
> sometimes not. Being able to control the behaviour is different I 
> think. But it seems currently "var" is just a better "any"... better 
> because var is not that misleading as any.
> So I'm still not sure if it is worth it.

Note that 'var' is only required for non-typed variables. So its not 
required in your example above. So if you want to adorn your variable 
declarations with type information like 'int' then you don't need to 
use 'var'/