RFE: __this__ keyword

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

RFE: __this__ keyword

Marc Palmer Local

Hi,

Are we stuck with __this__ to refer to the class? It doesn't seem to  
sit well with the general syntax.

Can't we have "thisclass" instead? Surely that's much nicer and sits  
well with "this"?

~ ~ ~
Marc Palmer ([hidden email])
Consultant/Analyst
AnyWare Ltd.
http://www.anyware.co.uk/

Reply | Threaded
Open this post in threaded view
|

Re: RFE: __this__ keyword

Jochen Theodorou
Marc Palmer schrieb:
>
> Hi,
>
> Are we stuck with __this__ to refer to the class? It doesn't seem to  
> sit well with the general syntax.
>
> Can't we have "thisclass" instead? Surely that's much nicer and sits  
> well with "this"?

I'm afraid I don't understand... can you show me an example for the
current situation and the improvement?

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: RFE: __this__ keyword

Marc Palmer Local

On 15 Dec 2005, at 20:08, Jochen Theodorou wrote:

> Marc Palmer schrieb:
>> Hi,
>> Are we stuck with __this__ to refer to the class? It doesn't seem  
>> to  sit well with the general syntax.
>> Can't we have "thisclass" instead? Surely that's much nicer and  
>> sits  well with "this"?
>
> I'm afraid I don't understand... can you show me an example for the  
> current situation and the improvement?

It says in the Groovy docs on the wiki:

"Things to be aware of

     * semicolon is optional. Use them if you like (though you must  
use them to put several statements on one line).
     * the return keyword is optional
     * you can use the _this_ keyword inside static methods (which  
refers to this class)
"

...so _this_ refers to "this class" - i.e:

     _this_.newInstance()   // Caveat not sure if this would work but  
sounds like it would

However _this_ looks rather anomalous to me, why not use something  
much more self explanatory like "thisclass:

     thisclass.newInstance()   // Caveat not sure if this would work  
but sounds like it would

Is that clearer?

Cheers

~ ~ ~
Marc Palmer ([hidden email])
Consultant/Analyst
AnyWare Ltd.
http://www.anyware.co.uk/

Reply | Threaded
Open this post in threaded view
|

Re: RFE: __this__ keyword

tugwilson

On 15 Dec 2005, at 14:47, Marc Palmer wrote:

>
> On 15 Dec 2005, at 20:08, Jochen Theodorou wrote:
>
>> Marc Palmer schrieb:
>>> Hi,
>>> Are we stuck with __this__ to refer to the class? It doesn't seem  
>>> to  sit well with the general syntax.
>>> Can't we have "thisclass" instead? Surely that's much nicer and  
>>> sits  well with "this"?
>>
>> I'm afraid I don't understand... can you show me an example for  
>> the current situation and the improvement?
>
> It says in the Groovy docs on the wiki:
>
> "Things to be aware of
>
>     * semicolon is optional. Use them if you like (though you must  
> use them to put several statements on one line).
>     * the return keyword is optional
>     * you can use the _this_ keyword inside static methods (which  
> refers to this class)
> "
>
> ...so _this_ refers to "this class" - i.e:

I think that this is a typo.

In a static context "this" refers to the class itself.

so

class C {
     static main(args) {
         println this
     }
}

prints class C

So we have no Python oddness here :)

John Wilson
The Wilson Partnership
http://www.wilson.co.uk


Reply | Threaded
Open this post in threaded view
|

Re: RFE: __this__ keyword

Maurice Diamantini
In reply to this post by Jochen Theodorou

Marc Palmer schrieb:
> Hi,
> Are we stuck with __this__ to refer to the class? It doesn't seem  
> to  sit well with the general syntax.
> Can't we have "thisclass" instead? Surely that's much nicer and  
> sits  well with "this"?


Why not
    "this"
for this object and
    "This"
for this class (the class of "this")
This would be short, consistant with ja convention and easy to remember.

-- Maurice