So my question is this , I have a class with nil variables that are lazy initialised only when needed the first time and of course they keep their values from there on. Lets say I get the latest update from github via metacello over an older update that I already have inside the image , do those variables revert back to nil values ? or do they keep their values as they are ? |
They remain nil.
That is why #initialize on the class side is needed. You can call that explicitly in a post load script, or rely on the class loading mechanism that normally calls #initialize automatically when loading a class. The warning is: this only happens when the *source* code of the #initialize methods changes. So sometimes, you will have to touch that method to force it. I hope that makes sense. See MCMethodDefinition>>#postloadOver: > On 20 Jan 2016, at 13:41, Dimitris Chloupis <[hidden email]> wrote: > > So my question is this , I have a class with nil variables that are lazy initialised only when needed the first time and of course they keep their values from there on. > > Lets say I get the latest update from github via metacello over an older update that I already have inside the image , do those variables revert back to nil values ? or do they keep their values as they are ? |
In reply to this post by kilon.alios
Is it instance or class variables ?
In both cases, there are unchanged. If class variables, Sven explain how to reinitialize. Hilaire -- Dr. Geo http://drgeo.eu |
In reply to this post by kilon.alios
On Wed, Jan 20, 2016 at 8:41 PM, Dimitris Chloupis
<[hidden email]> wrote: > So my question is this , I have a class with nil variables that are lazy > initialised only when needed the first time and of course they keep their > values from there on. > > Lets say I get the latest update from github via metacello over an older > update that I already have inside the image , do those variables revert back > to nil values ? No. > or do they keep their values as they are ? Yes. Loading a package is only loading source code. Its no different than manually changing a method's source through the Nautilus system browser (instance & class variables keep their values throughout) except you get the whole lot in one go. cheers -ben |
In reply to this post by Sven Van Caekenberghe-2
Thank you for the info but I think I did not make myself clear because you say "remain nil" Ok Imagine a class SomeClass and that class has a variable we will call SomeVariable, class variable that isOn Wed, Jan 20, 2016 at 2:54 PM Sven Van Caekenberghe <[hidden email]> wrote: They remain nil. |
ok thank you all , its now crystal clear that I need to follow Sven's approach, or maybe do it manually creating a reset method. On Wed, Jan 20, 2016 at 4:31 PM Dimitris Chloupis <[hidden email]> wrote:
|
In reply to this post by kilon.alios
> On 20 Jan 2016, at 15:34, Dimitris Chloupis <[hidden email]> wrote: > > Thank you for the info but I think I did not make myself clear because you say "remain nil" > > Ok Imagine a class SomeClass and that class has a variable we will call SomeVariable, class variable that is > , there is no class initialize method, now that class has a method that is eventually called , > someMethod > > SomeVariable ifNil: [ SomeVariable := 'hello world'] > > so when I decide to update this class via metacello loading the latest version from github , SomeVariable will have the value 'hello world' > > My question is , will SomeVariable after I do the update revert back to nil or stay 'hello world' ? > > If your answer is no, and it stays 'hello world' then yes i need an initialize method and call it at update time. Argh, I should have said: keeps it value, will not revert to nil. Sorry for the confusion ! > On Wed, Jan 20, 2016 at 2:54 PM Sven Van Caekenberghe <[hidden email]> wrote: > They remain nil. > > That is why #initialize on the class side is needed. > > You can call that explicitly in a post load script, or rely on the class loading mechanism that normally calls #initialize automatically when loading a class. The warning is: this only happens when the *source* code of the #initialize methods changes. So sometimes, you will have to touch that method to force it. > > I hope that makes sense. > > See MCMethodDefinition>>#postloadOver: > > > On 20 Jan 2016, at 13:41, Dimitris Chloupis <[hidden email]> wrote: > > > > So my question is this , I have a class with nil variables that are lazy initialised only when needed the first time and of course they keep their values from there on. > > > > Lets say I get the latest update from github via metacello over an older update that I already have inside the image , do those variables revert back to nil values ? or do they keep their values as they are ? > > |
no apologies owed, I just asked because I want to make sure Pharo wont do anything weird behind my back :) On Wed, Jan 20, 2016 at 4:39 PM Sven Van Caekenberghe <[hidden email]> wrote:
|
“The warning is: this only happens when the *source* code of the #initialize methods changes. So sometimes, you will have to touch that method to force it.” Perhaps there should be an overload able method that decides whether or not to initialize the class, such that classes relying on reinitializing every time a change is merged, can do this by simply answering true?
From: Pharo-users [mailto:[hidden email]]
On Behalf Of Dimitris Chloupis no apologies owed, I just asked because I want to make sure Pharo wont do anything weird behind my back :)
On Wed, Jan 20, 2016 at 4:39 PM Sven Van Caekenberghe <[hidden email]> wrote:
|
> On 20 Jan 2016, at 18:06, Henrik Nergaard <[hidden email]> wrote: > > “The warning is: this only happens when the *source* code of the #initialize methods changes. So sometimes, you will have to touch that method to force it.” > Perhaps there should be an overload able method that decides whether or not to initialize the class, such that classes relying on reinitializing every time a change is merged, can do this by simply answering true? Seems like a good idea, to modify the logic in MCMethodDefinition>>#postloadOver: However, I have a feeling that maybe people already have thought/discussed about this in the past, maybe we should find out why it was decided to do it like this. A question is also: will the test method only run in the existing image, and/or does the incoming code have an influence, because that could require two version before an initialiser runs in the worst case (previous version says no, incoming says yes). Just thinking out loud. > From: Pharo-users [mailto:[hidden email]] On Behalf Of Dimitris Chloupis > Sent: Wednesday, January 20, 2016 3:47 PM > To: Any question about pharo is welcome <[hidden email]> > Subject: Re: [Pharo-users] Updating a project and NIL class variables > > no apologies owed, I just asked because I want to make sure Pharo wont do anything weird behind my back :) > > On Wed, Jan 20, 2016 at 4:39 PM Sven Van Caekenberghe <[hidden email]> wrote: > > > On 20 Jan 2016, at 15:34, Dimitris Chloupis <[hidden email]> wrote: > > > > Thank you for the info but I think I did not make myself clear because you say "remain nil" > > > > Ok Imagine a class SomeClass and that class has a variable we will call SomeVariable, class variable that is > > , there is no class initialize method, now that class has a method that is eventually called , > > someMethod > > > > SomeVariable ifNil: [ SomeVariable := 'hello world'] > > > > so when I decide to update this class via metacello loading the latest version from github , SomeVariable will have the value 'hello world' > > > > My question is , will SomeVariable after I do the update revert back to nil or stay 'hello world' ? > > > > If your answer is no, and it stays 'hello world' then yes i need an initialize method and call it at update time. > > Argh, I should have said: keeps it value, will not revert to nil. > > Sorry for the confusion ! > > > On Wed, Jan 20, 2016 at 2:54 PM Sven Van Caekenberghe <[hidden email]> wrote: > > They remain nil. > > > > That is why #initialize on the class side is needed. > > > > You can call that explicitly in a post load script, or rely on the class loading mechanism that normally calls #initialize automatically when loading a class. The warning is: this only happens when the *source* code of the #initialize methods changes. So sometimes, you will have to touch that method to force it. > > > > I hope that makes sense. > > > > See MCMethodDefinition>>#postloadOver: > > > > > On 20 Jan 2016, at 13:41, Dimitris Chloupis <[hidden email]> wrote: > > > > > > So my question is this , I have a class with nil variables that are lazy initialised only when needed the first time and of course they keep their values from there on. > > > > > > Lets say I get the latest update from github via metacello over an older update that I already have inside the image , do those variables revert back to nil values ? or do they keep their values as they are ? > > > > > |
Free forum by Nabble | Edit this page |