storeString vs. printString

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

storeString vs. printString

Mathieu SUEN
Hi squeakers,

I have an extremly simple question.

What is the diffrence between #storeString and #printString?

In ArrayTest I suggest to add the following statement:

 self assert: literalArray storeString = '#(1 true 3 #four)'

And it don't pass the test (failure)
This is because the #storOn: don't do the write things (i.e. add a space at the end of the Array #(1 2 3 ) vs. #(1 2 3).
I think that #printOn: do a better Job. Don't he?

cheers,
Math

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

Re: storeString vs. printString

Bert Freudenberg-3
Am 04.07.2006 um 10:17 schrieb Mathieu SUEN:

> Hi squeakers,
>
> I have an extremly simple question.
>
> What is the diffrence between #storeString and #printString?

#printString (implemented by #printOn:) creates a human-readable  
description of your object. #storeString (or, more precisely,  
#storeOn:) is a machine-parsable serialization of your object.  
"Storing" writes out code that recreates the object when later read  
back in (using #readFrom:). So a test for correctness of storing  
would mean to compare the original and the read-back object.

In the case of literal objects, both representations are usually  
equivalent. But try this:

        a := {1. 2@3. #four}.
        a storeString -> a printString

which gives

         '(Array with: 1 with: 2@3 with: #four)' -> '#(1 2@3 #four)'

Only the storeString can be correctly read back in

        Object readFrom: a storeString

- Bert -

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