svenvc / ston

STON - Smalltalk Object Notation - A lightweight text-based, human-readable data interchange format for class-based object-oriented languages like Smalltalk.
MIT License
135 stars 32 forks source link

Avoid writing variables with nil as value? #8

Closed tinchodias closed 10 years ago

tinchodias commented 10 years ago

Hi Sven,

I am writing a lot of Ring definitions. For example, a method Ring definition is written like this:

'RGMethodDefinition {
    #annotations : IdentityDictionary {
        #className : #Integer,
        #statusKey : #active,
        #isMetaSide : false
    },
    #name : #''bitAnd:'',
    #parent : nil,
    #protocol : nil,
    #sourceCode : nil,
    #stamp : nil,
    #package : nil
}'

(Generated with STON toStringPretty: (Integer >> #bitAnd:) asRingDefinition)

This is a design problem of Ring, clearly not STON's fault. But since nil is the default value for instance variables, I wonder if it doesn't make sense to avoid writing them. I mean, the result might be:

'RGMethodDefinition {
    #annotations : IdentityDictionary {
        #className : #Integer,
        #statusKey : #active,
        #isMetaSide : false
    },
    #name : #''bitAnd:''
}'

What do you think?

Maybe its a better solution if Ring does it by itself, hooking how its instances are written.

Cheers, Martín

svenvc commented 10 years ago

Hi Martin,

In StHub or mc.stfx.eu

Name: STON-Core-SvenVanCaekenberghe.45 Author: SvenVanCaekenberghe Time: 14 November 2013, 12:02:29.390375 am UUID: 46c8ccc1-35f1-4f1b-be48-ff873ef99f2f Ancestors: STON-Core-SvenVanCaekenberghe.44

Changed the implementation of STONWriter>>#writeObject: to skip nil instance variables unless Object>>#stonShouldWriteNilInstVars is overridden to be true

Name: STON-Tests-SvenVanCaekenberghe.42 Author: SvenVanCaekenberghe Time: 14 November 2013, 12:02:58.546038 am UUID: 965f5e06-6db6-46d3-8724-cb9501357f95 Ancestors: STON-Tests-SvenVanCaekenberghe.41

Changed the implementation of STONWriter>>#writeObject: to skip nil instance variables unless Object>>#stonShouldWriteNilInstVars is overridden to be true

I did write another message but it seems to have been lost, I think the changes speak for themselves.

Sven

svenvc commented 10 years ago

Hi Martin,

In StHub or mc.stfx.eu

Name: STON-Core-SvenVanCaekenberghe.45 Author: SvenVanCaekenberghe Time: 14 November 2013, 12:02:29.390375 am UUID: 46c8ccc1-35f1-4f1b-be48-ff873ef99f2f Ancestors: STON-Core-SvenVanCaekenberghe.44

Changed the implementation of STONWriter>>#writeObject: to skip nil instance variables unless Object>>#stonShouldWriteNilInstVars is overridden to be true

Name: STON-Tests-SvenVanCaekenberghe.42 Author: SvenVanCaekenberghe Time: 14 November 2013, 12:02:58.546038 am UUID: 965f5e06-6db6-46d3-8724-cb9501357f95 Ancestors: STON-Tests-SvenVanCaekenberghe.41

Changed the implementation of STONWriter>>#writeObject: to skip nil instance variables unless Object>>#stonShouldWriteNilInstVars is overridden to be true

I did write another message but it seems to have been lost, I think the changes speak for themselves.

Sven

On 13 Nov 2013, at 16:52, tinchodias notifications@github.com wrote:

Hi Sven,

I am writing a lot of Ring definitions. For example, a method Ring definition is written like this:

'RGMethodDefinition {

annotations : IdentityDictionary {

    #className : #Integer,
    #statusKey : #active,
    #isMetaSide : false
},
#name : #''bitAnd:'',
#parent : nil,
#protocol : nil,
#sourceCode : nil,
#stamp : nil,
#package : nil

}'

(Generated with STON toStringPretty: (Integer >> #bitAnd:) asRingDefinition)

This is a design problem of Ring, clearly not STON's fault. But since nil is the default value for instance variables, I wonder if it doesn't make sense to avoid writing them. I mean, the result might be:

'RGMethodDefinition {

annotations : IdentityDictionary {

    #className : #Integer,
    #statusKey : #active,
    #isMetaSide : false
},
#name : #''bitAnd:''

}'

What do you think?

Maybe its a better solution if Ring does it by itself, hooking how its instances are written.

Cheers, Martín

— Reply to this email directly or view it on GitHub.

tinchodias commented 10 years ago

Neat! Thanks a lot :)