Hi Merlin,

I don't know how your reply pertains to what I said, but generally speaking having implicit variables is imho generally a very poor design choice, as anyone who has experienced them in e.g. a Basic dialect will be able to confirm, simply because one innocuous typo can introduce a hard to track bug into your code, by implicitly defining a new variable instead of modifying an existing one.

Cheers,
mg


On 21/10/2020 17:46, Merlin Beedell wrote:
I thought that implicit variables would overcome this.  Not an elegant solution 
- as you are simply declaring variables on the fly without an explicit data 
type or even a 'def'.
Having said, it is generally safer to explicitly list the parameters used in a 
method when used in this context (e.g. in a script without an explicit class 
declaration to mop up this case).
And as for 'global' - I sure wish the word 'global' was used instead of 
'static'.  It just kinda makes more sense to me!
//===========
    test=''  //implicit declaration of a variable
    void func()
    {
       println(test)
    }
    test = 'hello'
    func()
//===========

Or just

//===========
    void func()
    {
       println(test)
    }
    test = 'hello'
    func()
//===========

Merlin Beedell
-----Original Message-----
From: MG <[email protected]>
Sent: 15 October 2020 6:21 PM
To: [email protected]; Jochen Theodorou <[email protected]>
Subject: Re: Defining a global variable

On 15/10/2020 18:27, Jochen Theodorou wrote:
well.. even scripts are first compiled into a class before the class
is then executed. Groovy has no interpreter
Which, I think, is a lesser known fact, and quite surprising to people who perceive 
Groovy just under its "script language" aspect ;-)



Reply via email to