491477 messages in 933 lists

> Tom Nichols [mailto:tmnichols@gmail...] 
> Sent: Tuesday, July 08, 2008 10:14 PM
> To: user@groovy.codehaus...
> Subject: Re: [groovy-user] Omit "new"?
> 
> On Tue, Jul 8, 2008 at 3:22 PM, Alexander Veit 
> <alexander.veit@gmx...> wrote:
> > IMO omitting 'new' would weaken the language's expressive 
> > strength too much.
> This argument could have been used for omitting "return" as well :)

You hit the point :)

> > The code would become less understandable for the reader. But even 
> > worse, the compiler's inference rules would become much more
> > complex, probably up to a point where it not even could decide to
> > generate a NEW bytecode (think e.g. of pretended methods). The 
> > decision what to invoke would then be left to the runtime...
> 
> As I understand, already the compiler does not generate a NEW 
> bytecode, because in Groovy, instantiation goes through the 
> MOP (so it can be intercepted/ overridden at runtime).

You're right with the NEW bytecode. It seems to go through

 org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeNewN(Class, Class,
Object)

which calls

 MetaClass#invokeConstructor(Object[])

which calls

 Constructor#newInstance(Object[])

I incorrectly drew my conclusion from a previous post on this topic.

> > As you note, this argument does not neccessarily hold for the Ruby 
> > syntax
> >
> >  TheClass.new(...)
> >
> > as a syntactic equivalent for
> >
> >  new TheClass(...)
> 
> No, it would be equivalent to TheClass.newInstance(...)

TheClass.new(...) looks like a call to a static method of the class (with an
implicitly passed class parameter). So it may be easier to think of it as a
syntactical equivalent to new TheClass(...) (maybe I'm wrong).

> > However, personally I would not like to see this construct 
> > in Groovy. I suspect it would force to drop the restrictions
> > to 'new' from the grammar.
> > Would it allow to define methods with the name 'new'? If so, how 
> > should the compiler separate constructor calls
> >
> >  Xxx.new(...)
> >
> > from method calls on an instance
> >
> >  Xxx.new(...)
> 
> Didn't Guillaume say you already cannot use 'new' as a method 
> identifier?

Yes, 'new' is a reserved keyword. Currently the compiler issues an
unexpected token error. So the grammar had to be adopted to allow just the
proposed case - but nothing more.

>  So the compiler could assume that "TheClass.new" 
> _must_ be an initializer call.  Which is really just an alias 
> for Class.newInstance(...).  Which is already handled through 
> the MOP like any other method call.  Right?
> 
> As Groovy stands _right_now_, does "new Something" generate a "new"
> bytecode, or does it generate a method call to 
> Class.newInstance that is handled through the MOP?



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Message Thread
[groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Russel Winder (russel.winder@concertant...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Tom Nichols (tmnichols@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Alexandru Popescu ☀ (the.mindstorm.mailinglist@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Paul King (paulk@asert.com...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Alexandru Popescu ☀ (the.mindstorm.mailinglist@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Graeme Rocher (graeme@g2one...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Alexandru Popescu ☀ (the.mindstorm.mailinglist@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Alexandru Popescu ☀ (the.mindstorm.mailinglist@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Alexander Veit (alexander.veit@gmx...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
06 Jul 2008
Re: [groovy-user] Omit "new"? Tom Nichols (tmnichols@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Charles Oliver Nutter (charles.nutter@sun...)
20 Jul 2008
RE: [groovy-user] Omit "new"? Eric Kolotyluk (eric.kolotyluk@kodak...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Detering Dirk (Dirk.Detering@bitmarck...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Detering Dirk (Dirk.Detering@bitmarck...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Francesco Pasqualini (frapas@gmail...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Detering Dirk (Dirk.Detering@bitmarck...)
09 Jul 2008
RE: [groovy-user] Omit "new"? Eric Kolotyluk (eric.kolotyluk@kodak...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Mark Davidson (ukdavo@googlemail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
07 Jul 2008
Re: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
07 Jul 2008
RE: [groovy-user] Omit "new"? Detering Dirk (Dirk.Detering@bitmarck...)
08 Jul 2008
RE: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
08 Jul 2008
Re: [groovy-user] Omit "new"? c0mrade (jacksingleton1@gmail...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Guillaume Laforge (glaforge@gmail...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Alexander Veit (alexander.veit@gmx...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Tom Nichols (tmnichols@gmail...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Alexander Veit (alexander.veit@gmx...)
08 Jul 2008
RE: [groovy-user] Omit "new"? Eric Kolotyluk (eric.kolotyluk@kodak...)
08 Jul 2008
Re: [groovy-user] Omit "new"? Alexandru Popescu ☀ (the.mindstorm.mailinglist@gmail...)
08 Jul 2008
Copyright 2006-2008 The Codehaus Foundation
Powered by Codehaus March (Version: 0.1-HEAD)