Hi, is there an automated setting which creates default new and initialize methods for a new class? BTW, I'm using Pharo 2.0-one-click. Well, I must go and thanks in advance.
Think different and code well, -Conrad |
Dirty way:
You can modify Class>>subclass:instanceVariableNames:classVariableNames:poolDictionaries:category: like this: subclass: t instanceVariableNames: f classVariableNames: d poolDictionaries: s category: cat
"This is the standard initialization message for creating a new class as a subclass of an existing class (the receiver)."
| newClass | newClass := (ClassBuilder new) superclass: self
subclass: t instanceVariableNames: f classVariableNames: d
poolDictionaries: s category: cat. newClass compile: 'initialize'.
^newClass. 2012/6/15 Conrad Taylor <[hidden email]> Hi, is there an automated setting which creates default new and initialize methods for a new class? BTW, I'm using Pharo 2.0-one-click. Well, I must go and thanks in advance. |
Yes, very dirty.
2012/6/15 camille teruel <[hidden email]> Dirty way: |
In reply to this post by Conrad Taylor
On Fri, Jun 15, 2012 at 4:09 PM, Conrad Taylor <[hidden email]> wrote:
> Hi, is there an automated setting which creates default new and initialize > methods for a new class? why do you need to implement #new so often? It's kind of rare in the code I've read. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry |
For initialize, if you use Nautilus:
- select your class - CMD+SHIFT+I enjoy :) Ben On Jun 15, 2012, at 11:05 AM, Damien Cassou wrote: > On Fri, Jun 15, 2012 at 4:09 PM, Conrad Taylor <[hidden email]> wrote: >> Hi, is there an automated setting which creates default new and initialize >> methods for a new class? > > why do you need to implement #new so often? It's kind of rare in the > code I've read. > > -- > Damien Cassou > http://damiencassou.seasidehosting.st > > "Lambdas are relegated to relative obscurity until Java makes them > popular by not having them." James Iry > |
On Fri, Jun 15, 2012 at 5:14 PM, Benjamin <[hidden email]> wrote: For initialize, if you use Nautilus: Ben, you should move to somewhere OUTSIDE the menu "analyze" or rename analyze ;) enjoy :) -- Mariano http://marianopeck.wordpress.com |
In reply to this post by Damien Cassou
On Fri, Jun 15, 2012 at 8:05 AM, Damien Cassou <[hidden email]> wrote:
Hi, I would like to initialize the objects I create with some reasonable defaults and I don't want to have setters and getters for every instance variable. -- -- Think different and code well, -Conrad |
In reply to this post by Damien Cassou
On Fri, Jun 15, 2012 at 8:05 AM, Damien Cassou <[hidden email]> wrote:
So, how do you create a new instance of a class? -- -- Think different and code well, -Conrad |
In reply to this post by Conrad Taylor
On Jun 15, 2012, at 5:48 PM, Conrad Taylor wrote: > On Fri, Jun 15, 2012 at 8:05 AM, Damien Cassou <[hidden email]> wrote: > On Fri, Jun 15, 2012 at 4:09 PM, Conrad Taylor <[hidden email]> wrote: > > Hi, is there an automated setting which creates default new and initialize > > methods for a new class? > > why do you need to implement #new so often? It's kind of rare in the > code I've read. > > > Hi, I would like to initialize the objects I create with some reasonable defaults and I don't want to have setters and getters for every instance variable. > So the only thing you need to implement is the #initialize method on your class. Marcus -- Marcus Denker -- http://marcusdenker.de |
In reply to this post by Benjamin Van Ryseghem (Pharo)
On Fri, Jun 15, 2012 at 8:14 AM, Benjamin <[hidden email]> wrote:
For initialize, if you use Nautilus: Ben, would you recommend installing Nautilus? If so, what's the installation steps? - select your class -- Think different and code well, -Conrad |
On Fri, Jun 15, 2012 at 6:08 PM, Conrad Taylor <[hidden email]> wrote:
Of course he will, he is the author ;) BTW, I also do recommend it.
-- Mariano http://marianopeck.wordpress.com |
In reply to this post by Conrad Taylor
You should do that :)
But in Pharo 2.0, it's the default browser. Ben On Jun 15, 2012, at 12:08 PM, Conrad Taylor wrote: On Fri, Jun 15, 2012 at 8:14 AM, Benjamin <[hidden email]> wrote: |
On Fri, Jun 15, 2012 at 9:18 AM, Benjamin <[hidden email]> wrote:
OK, I'm using Pharo-2.0-one-click so I'm good to go in regards to Nautilis.
-- Think different and code well, -Conrad |
In reply to this post by Conrad Taylor
On Fri, Jun 15, 2012 at 5:51 PM, Conrad Taylor <[hidden email]> wrote:
> I would like to initialize the objects I create with some reasonable defaults and I don't want to have setters and getters for every instance variable. > So, how do you create a new instance of a class? don't touch #new. Just implement #initialize and set your fields there. To everyone on the mailing list: we should encourage people to ask such kind of questions on stackoverflow.com. -- Damien Cassou http://damiencassou.seasidehosting.st "Lambdas are relegated to relative obscurity until Java makes them popular by not having them." James Iry |
Administrator
|
+1
Cheers,
Sean |
In reply to this post by Conrad Taylor
why do you need an automatic new method?
Because by default new invoke initialize and it works well. On Jun 15, 2012, at 4:09 PM, Conrad Taylor wrote: > Hi, is there an automated setting which creates default new and initialize methods for a new class? BTW, I'm using Pharo 2.0-one-click. Well, I must go and thanks in advance. > > -- > > Think different and code well, > > -Conrad > > |
In reply to this post by Damien Cassou
Sent from my iPhone
On Jun 15, 2012, at 11:43 AM, Damien Cassou <[hidden email]> wrote: > On Fri, Jun 15, 2012 at 5:51 PM, Conrad Taylor <[hidden email]> wrote: >> I would like to initialize the objects I create with some reasonable defaults and I don't want to have setters and getters for every instance variable. >> So, how do you create a new instance of a class? > > don't touch #new. Just implement #initialize and set your fields there. > > To everyone on the mailing list: we should encourage people to ask > such kind of questions on stackoverflow.com. > Damien, this is a great point and I'll ask such questions there in the future. Think different and code well, -Conrad > -- > Damien Cassou > http://damiencassou.seasidehosting.st > > "Lambdas are relegated to relative obscurity until Java makes them > popular by not having them." James Iry > |
In reply to this post by Stéphane Ducasse
Sent from my iPhone
On Jun 15, 2012, at 12:06 PM, Stéphane Ducasse <[hidden email]> wrote: > why do you need an automatic new method? > Because by default > new invoke initialize > > and it works well. > Stéphane, I have been using VW Smalltalk and it creates new classes ,by default, with a #new method on the class side and a #initialize method on the instance side. > > > On Jun 15, 2012, at 4:09 PM, Conrad Taylor wrote: > >> Hi, is there an automated setting which creates default new and initialize methods for a new class? BTW, I'm using Pharo 2.0-one-click. Well, I must go and thanks in advance. >> >> -- >> >> Think different and code well, >> >> -Conrad >> >> > > |
Administrator
|
In Pharo, new is built-in and calls initialize. I have a cool little hack that gives you the option to automatically create/add to #initialize as instVars are added. I'll post it in case that helps you...
Cheers,
Sean |
In reply to this post by Conrad Taylor
2012/6/16 Conrad Taylor <[hidden email]>:
> Sent from my iPhone > > On Jun 15, 2012, at 12:06 PM, Stéphane Ducasse <[hidden email]> wrote: > >> why do you need an automatic new method? >> Because by default >> new invoke initialize >> >> and it works well. >> > > Stéphane, I have been using VW Smalltalk and it creates new classes ,by default, with a #new method on the class side and a #initialize method on the instance side. > Yes, true in VW, but unecessary in squeak/pharo, this is in Behavior>>new ^ self basicNew initialize Also, a generally good rule is to remember to send super initialize (very few exceptions). Nicolas >> >> >> On Jun 15, 2012, at 4:09 PM, Conrad Taylor wrote: >> >>> Hi, is there an automated setting which creates default new and initialize methods for a new class? BTW, I'm using Pharo 2.0-one-click. Well, I must go and thanks in advance. >>> >>> -- >>> >>> Think different and code well, >>> >>> -Conrad >>> >>> >> >> > |
Free forum by Nabble | Edit this page |