Best way to implement two-dimensional array

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

Re: Re: Best way to implement two-dimensional array

John Almberg
But if I understand what is going on with Classes, as soon as I call  
"MyClass initialize", and save the Image, the class variables contain  
whatever I put them, and will do unless I do something to clear them  
out.

So it doesn't matter whether I set them interactively or with an  
initialize method. Either way the class variables contain data.

Furthermore, unless the initialize method changes, there is no actual  
need to call it again (though you might want to do so to ensure it's  
up to date).

I've just done this and when I reopen the Image, the MyClass class  
variables are still set. So is it good style to tear down classes  
when done with them? To 'uninitialize' them to minimize the Image size?

As I said, the implications are still sinking in...

-- John


On Sep 4, 2007, at 6:38 PM, Bert Freudenberg wrote:

> Also, you easily can inflate your image to ridiculous sizes with  
> class variables accidentally holding onto huge structures.  
> Maintaining an image requires a bit of discipline. It's an organic  
> thing, which quite literally has been nurtured for 30 years now  
> (with periods of hibernation of course).
>
> - Bert -
>
> On Sep 4, 2007, at 15:31 , John Almberg wrote:
>
>> Yes, that's clear, and I do intend to initialize this big table  
>> with code, mainly to make it easy for me to spot and fix typos.  
>> However, it's still cool to gain a sense of the concreteness of  
>> Smalltalk classes.
>>
>> And I find myself trying out code in a Workspace to see how things  
>> work, before encoding it in a method. I suspect interactively  
>> tweaking a class might help me figure things out before committing  
>> it to an initialize method.
>>
>> -- John
>>
>> On Sep 4, 2007, at 5:29 PM, nicolas cellier wrote:
>>
>>> However, Classes and methods are Objects which have well defined  
>>> tools to help them migrating from an image to another, even to  
>>> another Smalltalk dialect. This ease code sharing.
>>>
>>> This is less clear for arbitrary objects...
>>>
>>> That's why I restrict myself to initialize these class vars in an  
>>> initialize method in the class side, and loose some of the power  
>>> of the image...
>>>
>>> But there is a better reason:
>>> if you construct your object with some snippets of code, say in  
>>> an inspector or a debugger:
>>> MyTable at: 1 put: 30 degreesToRadians cos * 4
>>>
>>> Then your image will loose the history of construction.
>>> All it retains is 3.464101615137755 which is somehow less  
>>> expressive.
>>>
>>> Nicolas
>>>
>>> Bert Freudenberg a écrit :
>>>> Seems you've made the first step to truly understanding  
>>>> Smalltalk :)
>>>> Also you must realize that the browser is just a view into that  
>>>> live system of objects we call classes and is simply modifying  
>>>> those live objects. You could do that in an inspector as well,  
>>>> but the class browser is more specialized so it is easier to use  
>>>> for that purpose.
>>>> Welcome to Real Objects.
>>>> - Bert -
>>>> On Sep 4, 2007, at 12:19 , John Almberg wrote:
>>>>> Whoa... that worked, but the implications are a bit hard to  
>>>>> digest...
>>>>>
>>>>> So MyClass is an object in my Smalltalk image, and it can have  
>>>>> variables that I can set interactively, and the values  
>>>>> contained therein are now part of the class...
>>>>>
>>>>> I keep reading that classes are objects, but this is the first  
>>>>> time I've seen something that makes me realize that they are  
>>>>> fundamentally different than objects in other languages. I  
>>>>> guess because they are 'live', in some sense, in the Smalltalk  
>>>>> environment. That is, not just source code, but an instantiated  
>>>>> object.
>>>>>
>>>>> Talk about paradigm whiplash... I'm going to have to think  
>>>>> about this, a bit :-)
>>>>>
>>>>> Thanks!
>>>>>
>>>>> -- John
>>>>>
>>>>>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
>>>>>> inspector on a class - which of course is the instance of  
>>>>>> another class, as everything is an object (and hence an  
>>>>>> instance of a class) in Smalltalk. Anyway, you should see a  
>>>>>> reference to the superclass, a dictionary of all the methods,  
>>>>>> the list of instance variables and subclasses etc. Class  
>>>>>> variables are simply held in a Dictionary in the "classPool"  
>>>>>> instance variable of that class. So by inspecting that and  
>>>>>> drilling down into your class var you can modify it.
>>>>>>
>>>>>> A simpler way to get at the contents of your class var is just  
>>>>>> selecting its name in a browser showing any method of your  
>>>>>> class, and press Cmd-i there. That works because in the  
>>>>>> browser, code is evaluated in the context of the selected class.
>>>>>>
>>>>>> - Bert -
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Re: Re: Best way to implement two-dimensional array

Conrad Taylor
Hi, I'm no longer able to see the code for the methods because there's
a red box with yellow lines.  BTW, I'm using Squeak 3.10.

Thanks in advance,

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

Re: Re: Best way to implement two-dimensional array

Herbert König
In reply to this post by John Almberg
Hello John,


JA> But if I understand what is going on with Classes, as soon as I call
JA> "MyClass initialize", and save the Image, the class variables contain
JA> whatever I put them, and will do unless I do something to clear them
JA> out.

two things to add:
first: are you aware that Alt Shift i will bring up an explorer
instead of an inspector?

There it's easier to change classVars than stepping down to various
inspectors. Be aware that unlike an inspector it doesn't update
automatically.

second:
I have a few classes which I use as lookup tables, stored in
classvars.

For these I implement on the class side a fileIn/Out protocol to move
the classVars between images like e.g.:

TrainingsSamplesFehlerkategorien>>writeTrainingsSamples
        "write the class var TrainingsSamples to a file using ReferenceStreams"

        | rr |
        rr := ReferenceStream fileNamed: 'trainingssamples.obj'.
        "trainingsSamples is an accessor to classVar TrainingsSamples
        which is a dictionary"
        rr nextPut: TrainingsSamplesFehlerkategorien  trainingsSamples .
        rr close.
        rr := nil

and for the opposite direction:

TrainingsSamplesFehlerkategorien>>readTrainingsSamples
        "read the class var TrainingsSamples from a file using ReferenceStreams "
        | rr |
        rr := ReferenceStream fileNamed: 'trainingssamples.obj'.
        TrainingsSamplesFehlerkategorien  trainingsSamples:  rr next.
        rr close.
        rr := nil



JA> So it doesn't matter whether I set them interactively or with an  
JA> initialize method. Either way the class variables contain data.

JA> Furthermore, unless the initialize method changes, there is no actual
JA> need to call it again (though you might want to do so to ensure it's
JA> up to date).

Cheers

Herbert                            mailto:[hidden email]

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

Re: Re: Best way to implement two-dimensional array

John Almberg
Herbert,

> two things to add:
> first: are you aware that Alt Shift i will bring up an explorer
> instead of an inspector?
>
> There it's easier to change classVars than stepping down to various
> inspectors. Be aware that unlike an inspector it doesn't update
> automatically.

Actually, I had tried the Explorer a few weeks ago, but didn't see  
what it was good for until trying it on this class I have with the  
big table. Nice how it breaks the table down, making it relatively  
easy to edit. I'll have to do some more digging on Explorer to see  
what else it's good for. Thanks for the tip.

>
> second:
> I have a few classes which I use as lookup tables, stored in
> classvars.
>
> For these I implement on the class side a fileIn/Out protocol to move
> the classVars between images like e.g.:
>
> TrainingsSamplesFehlerkategorien>>writeTrainingsSamples
>         "write the class var TrainingsSamples to a file using  
> ReferenceStreams"
>

<snip>

That is also very useful.

As they say, anything that you don't understand looks like magic, and  
people who can find useful classes in the Squeak class library look  
like magicians to me :-)

Thanks: John

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