28 Dec 15:22
Re: Scala Object Notation ( SCON? )
Andrés Testi <andres.a.testi <at> gmail.com>
2007-12-28 14:22:44 GMT
2007-12-28 14:22:44 GMT
Object Notation would be completed with Groovy Bean Constructors style (take a look at http://groovy.codehaus.org/Groovy+Beans ). Groovy bean constructor accept parameters like JSON objects. For example: class Person{ String name; Integer age; } p = new Person(name: "Andres", age: 29) A pretty feature to add to Scala. 2007/12/24, Jon Pretty <jon.pretty <at> sygneca.com>: > John Nilsson wrote: > > This doesn't fit with the requirement of instantiating a Person (type > > Person isn't quite the same is it?) without creating a new subclass per > > instance dose it? > > Probably not; I don't think the compiler does this optimisation. > > And I sometimes forget constraints I don't agree with.> > >> So many options, but none of them quite as concise as JSON... > > > > If you skip the type declaration I'd say it's close enough. > > Probably; I was only suggesting it for the people who like conciseness, > thou I'm actually happy to type a few more characters for the benefit of > clearer code. > > Another problem with the code I suggested is that it doesn't allow > methods to be inherited from a Person class, so I would have to conclude > that there's nothing better, or clearer in the context of Scala, than to > write: > > val person = new Person { > def name = "Peter" > def age = 20 > } > > Merry Christmas, > Jon > > -- > Jon Pretty | Sygneca Ltd. >
>
> >> So many options, but none of them quite as concise as JSON...
> >
> > If you skip the type declaration I'd say it's close enough.
>
> Probably; I was only suggesting it for the people who like conciseness,
> thou I'm actually happy to type a few more characters for the benefit of
> clearer code.
>
> Another problem with the code I suggested is that it doesn't allow
> methods to be inherited from a Person class, so I would have to conclude
> that there's nothing better, or clearer in the context of Scala, than to
> write:
>
> val person = new Person {
> def name = "Peter"
> def age = 20
> }
>
> Merry Christmas,
> Jon
>
> --
> Jon Pretty | Sygneca Ltd.
>
RSS Feed