Honestly, I do not like that much having a more declarative (less Smalltalksish) definition. In fact, one of the things I was always proud of showing to Smalltalk newcomers, that when they created a class, all they were doing was a "DoIt" to tell the superclass to create the new subclass. And then showing how they could copy and paste that into a workspace and DoIt. Or Debug it.
So..if it were for me, I would keep a Smalltalk syntax with a plain message send. Sure, a builder kind of API is better to me, like Luc proposes. Also, I do prefer too the #createAndInstall kind of message so that we can have a flavour of #createClass that only creates the class but doesn't install it into the system. Cheers, On Mon, May 22, 2017 at 10:48 AM, Ben Coman <[email protected]> wrote: > > > On Mon, May 22, 2017 at 3:25 PM, Luc Fabresse <[email protected]> > wrote: > >> Hi, >> >> Following Pharo Days, I brainstormed about some possible class definition >> syntaxes. >> What I have in mind: >> >> "basic mechanics, only THIS one in the image!" >> ClassDefinition new >> superclass: Object; "optional. If not specified, Object by default ;-)" >> name: #A; "optional and create an anonymous class if not specified" >> instVars: 'a b c'; >> traits: {TEquality}; >> package: 'Plop'; >> createClass. " this message sent might be hidden by the browser when >> accepting" >> >> "---------------" >> "Some IDEAS (but I did not find one that I really like) of >> scripting/shorter syntaxes that must ALWAYS end up calling the above basic >> mechanics at the end:" >> >> Class fromDefinition: [ :def | >> def name: #sub; >> instVars: 'w r g'; >> superclass: Object ]. >> >> Object subclass "<-- returns a subclass of Object but the problem is >> that the new class is muted >> > > (btw, I assume you mean mutated.) > > >> each time and the class definition is not explicit" >> name: #A; >> ivs: 'a b c'; >> traits: { TEquality }. >> > > What about... > > Object subclass: [ :def | def > name: 'MyClass' ; "optional and create an anonymous class if not > specified" > instanceVariables: 'a b c' ; > classVariables: 'M N O'; > classInstanceVariables: 'x y z' ; > traits: {TEquality} ; > package: 'Plop']. > > Object>>subclass: builderBlock > ^ (builderBlock value: ClassDefinition new) createClass > > or similar to Guille's declarative proposal... > > Object subclass: { > name: 'Myclass', > a: InstVar, > b: InstVar, > c: InstVar > } > > > cheers -ben > -- Mariano http://marianopeck.wordpress.com
