new and initialize

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

new and initialize

Joseph Alotta
Greetings,

I have an instance method called ‘initialize’ that defines instance variables.  

I want it to run whenever a new instance is created.  How do I accomplish that?

I tried to add a class method ‘new’  that contained ^(super new) initialize.  But it warned me about adding the message saying it would have serious effects.

So where do I put it?

Sincerely,

Joe.



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: new and initialize

Ron Teitelbaum
Hi Joe,

Excellent question.  Try this.  

Object new.

Highlight it and do debug it.   Click "Into" to go into the #new method.

Notice the implementation of #new.  

You should be able to see there that #initialize is called automatically.
 
Also for extra points notice what class new is implemented on.  What method should you call to skip initialize?

All the best,

Ron Teitelbaum



> -----Original Message-----
> From: [hidden email] [mailto:beginners-
> [hidden email]] On Behalf Of Joseph Alotta
> Sent: Tuesday, May 10, 2016 2:07 PM
> To: [hidden email]
> Subject: [Newbies] new and initialize
>
> Greetings,
>
> I have an instance method called ‘initialize’ that defines instance variables.
>
> I want it to run whenever a new instance is created.  How do I accomplish
> that?
>
> I tried to add a class method ‘new’  that contained ^(super new) initialize.
> But it warned me about adding the message saying it would have serious
> effects.
>
> So where do I put it?
>
> Sincerely,
>
> Joe.
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

Joseph Alotta

> On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
>
> Hi Joe,
>
> Excellent question.  Try this.  
>
> Object new.
>
> Highlight it and do debug it.   Click "Into" to go into the #new method.
>
> Notice the implementation of #new.  
>
> You should be able to see there that #initialize is called automatically.
>  
> Also for extra points notice what class new is implemented on.

Behavior

>  What method should you call to skip initialize?

basicNew

More questions:  why isn’t there a command key for debug it?
                 why isn’t my initialize method not running or running without setting variables?


Thank you.

Sincerely,

Joe.


Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

Ben Coman
On Wed, May 11, 2016 at 3:37 AM, Joseph Alotta <[hidden email]> wrote:

>
>> On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] <[hidden
>> email]> wrote:
>>
>> Hi Joe,
>>
>> Excellent question.  Try this.
>>
>> Object new.
>>
>> Highlight it and do debug it.   Click "Into" to go into the #new method.
>>
>> Notice the implementation of #new.
>>
>> You should be able to see there that #initialize is called automatically.
>>
>> Also for extra points notice what class new is implemented on.
>
> Behavior
>
>>  What method should you call to skip initialize?
>
> basicNew
>
> More questions:
>                  why isn’t my initialize method not running or running
> without setting variables?

Is your initialize method on the class-side or the instance-side ?
At the very very start of using Squeak this would catch me up.  It
soon became instinctive to notice which side I was working on.

cheers -ben
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

Ron Teitelbaum
In reply to this post by Joseph Alotta

 

 

From: Joseph Alotta
Sent: Tuesday, May 10, 2016 3:38 PM

 


> On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
>
> Hi Joe,
>
> Excellent question.  Try this.  
>
> Object new.
>
> Highlight it and do debug it.   Click "Into" to go into the #new method.
>
> Notice the implementation of #new.  
>
> You should be able to see there that #initialize is called automatically.
>  
> Also for extra points notice what class new is implemented on.

Behavior

[Ron Teitelbaum] Exactly! 



>  What method should you call to skip initialize?

basicNew

[Ron Teitelbaum] Excellent!



More questions:  why isn’t there a command key for debug it?

[Ron Teitelbaum] No clue. 


                 why isn’t my initialize method not running or running without setting variables?

[Ron Teitelbaum] put a halt in your method and run it.  See if the initialize is being called at all.  If it is then check the content of your method for errors.  If not then your initialize method is spelled wrong, is not on the instance side, or there is a new method implemented in your class or a superclass that is bypassing the default implementation of #new which is a bad thing.  The system gives you a warning to let you know that!! J

All the best,

Ron




Thank you.

Sincerely,

Joe.



View this message in context: Re: new and initialize
Sent from the Squeak - Beginners mailing list archive at Nabble.com.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
cbc
Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

cbc
In reply to this post by Joseph Alotta
Hi.

On Tue, May 10, 2016 at 12:37 PM, Joseph Alotta <[hidden email]> wrote:
<snip>
More questions:  why isn’t there a command key for debug it? 

I just learned this today - we do have a command key (well, command key sequence) for debug it:

Shift+Cmd+D to "Debug it"

-cbc

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

Joseph Alotta
Sorry, it doesn’t work on the Mac.  The window gets black and then redraws.  I think maybe it means “refresh”.

Sincerely,

JOe.



> On May 11, 2016, at 5:07 PM, cbc [via Smalltalk] <[hidden email]> wrote:
>
> Hi.
>
> On Tue, May 10, 2016 at 12:37 PM, Joseph Alotta <[hidden email]> wrote:
> <snip>
> More questions:  why isn’t there a command key for debug it?
>
> I just learned this today - we do have a command key (well, command key sequence) for debug it:
>
> Shift+Cmd+D to "Debug it"
>
> -cbc
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://forum.world.st/new-and-initialize-tp4894227p4894371.html
> To start a new topic under Squeak - Beginners, email [hidden email]
> To unsubscribe from Squeak - Beginners, click here.
> NAML

Reply | Threaded
Open this post in threaded view
|

Re: new and initialize

Tobias Pape

On 12.05.2016, at 01:50, Joseph Alotta <[hidden email]> wrote:

> Sorry, it doesn’t work on the Mac.  The window gets black and then redraws.  I think maybe it means “refresh”.
>
> Sincerely,
>
> JOe.

Joe, which version of Squeak are you using?
5.0 does not yet have this shortcut but the current development version (trunk / 5.1alpha) does.

Best regards
        -Tobias


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners