[Grace-core] Fwd: [important] Traits

James Noble kjx at ecs.vuw.ac.nz
Mon Mar 11 22:35:51 PDT 2013


> Not sure to understand here:
> If you can already write object Foo(...)
> where Foo is a method that returns a trait, I do not see how this is
> worst that using "new" in Java.

it's different.
In Java what follows new has to be a literal class (aka trait) name.
if Foo is a method that returns a trait, or a parameter to a method, that's very different. 

> But I do believe that using new in Java is not good, since creating an
> object should be perceived as a normal thing that each method can do,
> not just "the special cool thing that happen when I wrote new", so
> programmers should perceive construction
> as simple method calls.

there are two questions: where you can use new, and what new does   (and what it does it with)

any Java method can call new, but only on any class that is statically & lexically in scope.

> Now, IF you share this reason for avoiding new, that is equivalent
> reason to avoid "object", but going in this direction
> makes the language more "class first", object are "emanation of classes"
> that "object first", classes are just a syntactic sugar for special "singleton" objects.

well that is the question: do objects precede classes, 
or do classes precede objects,
or are they both equal (but somehow not redundant)

> Otherwise, I think we are happy that in most cases writing object
> Foo(..) is a good way to create an instance, and the factory pattern
> is not fundamental. Especially since one can write something like
> 
> method foo(x,y) { return .... object x(y) .... }
> 
> where the "trait" can be a parameter of a method, and thus can be used
> as an instance of an abstract factory

again: this is precisely the kind of question we have to decide! 

and even the choice of "object" vs "new" is not clear.
new/class follows many more languages than object/trait

Also  def x = new List    // "x is a new list"  

reads euphonically to an English speaker than

def x = object List  // "is an object? list??"


James


More information about the Grace-core mailing list