Auto create new and initialize methods for new class?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
29 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Auto create new and initialize methods for new class?

Conrad Taylor
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


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

camille teruel
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.

-- 

Think different and code well,

-Conrad



Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

camille teruel
Yes, very dirty.

2012/6/15 camille teruel <[hidden email]>
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.

-- 

Think different and code well,

-Conrad




Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Damien Cassou
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

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Benjamin Van Ryseghem (Pharo)
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
>


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Mariano Martinez Peck


On Fri, Jun 15, 2012 at 5:14 PM, Benjamin <[hidden email]> wrote:
For initialize, if you use Nautilus:

- select your class
- CMD+SHIFT+I


Ben, you should move to somewhere OUTSIDE the menu "analyze" or rename analyze ;)

 
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
>





--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
In reply to this post by Damien Cassou
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.

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry




--

Think different and code well,

-Conrad


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
In reply to this post by Damien Cassou
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.


So, how do you create a new instance of a class?
 
--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry




--

Think different and code well,

-Conrad


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Marcus Denker-4
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.
>
#new calls #initialize by default.

So the only thing you need to implement is the #initialize method on your class.

        Marcus



--
Marcus Denker -- http://marcusdenker.de


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
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
- 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
>





--

Think different and code well,

-Conrad


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Mariano Martinez Peck


On Fri, Jun 15, 2012 at 6:08 PM, Conrad Taylor <[hidden email]> wrote:
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? 

Of course he will, he is the author ;)
BTW, I also do recommend it.
 
If so, what's the installation steps?
 
- 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
>





--

Think different and code well,

-Conrad





--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Benjamin Van Ryseghem (Pharo)
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:
For initialize, if you use Nautilus:


Ben, would you recommend installing Nautilus?  If so, what's the installation steps?
 
- 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
>





--

Think different and code well,

-Conrad



Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
On Fri, Jun 15, 2012 at 9:18 AM, Benjamin <[hidden email]> wrote:
You should do that :)

But in Pharo 2.0, it's the default browser.

Ben


OK, I'm using Pharo-2.0-one-click so I'm good to go in regards to Nautilis.
 
On Jun 15, 2012, at 12:08 PM, Conrad Taylor wrote:

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
- 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
>





--

Think different and code well,

-Conrad






--

Think different and code well,

-Conrad


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Damien Cassou
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

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Sean P. DeNigris
Administrator
Damien Cassou wrote
we should encourage people to ask
such kind of questions on stackoverflow.com.
+1
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Stéphane Ducasse
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
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
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
>

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Conrad Taylor
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
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Sean P. DeNigris
Administrator
Conrad Taylor wrote
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.
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
Reply | Threaded
Open this post in threaded view
|

Re: Auto create new and initialize methods for new class?

Nicolas Cellier
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
>>>
>>>
>>
>>
>

12