ChainAccessor

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

ChainAccessor

DiegoLont
Hi all,

I regularly run into the trouble that using a chain accessor gives the error message:
        MessageNotUnderstood: receiver of “…” is nil.
I now spot it faster what I have done wrong here: I use a chain accessor on a un initialised value.

I have 3 typical scenario’s where I use a chain accessor:
        1. I have a variable that is a collection of some values, that I initialise always, and I want to access its properties.
        2. I want to display some extra info, or maybe even allow editing some details of a required “base” value.
        3. I want to display some extra info on a “base” value that might be initialised.

I propose that on reading, it returns a nil value, when the previous value is nil already. The write method I want to leave as is. Going back to my scenario’s:
1. In this case I guess returning an error would be proper, but on the other hand: I will get this hard error too when I try to write to this variable. So I will still find out I did something wrong (forgot initialisation) when I test properly.
2. In this case, the first time reading generates an error, as the user has not made a choice yet. Returning nil there would be the appropriate behaviour.
3. In this case, returning nil would be the appropriate behaviour, as it only displays information.

My question to you all would be:
Do you agree that the default behaviour should be to return nil, instead of generate an error? As this would be easier in use?

Alternatives:
> Modify the description, adding a property that indicates if an error in reading should be blocking or should be interpreted as “nil”.
> Create an accessor for each occurrences I have, thus avoiding using a chain accessor (i.e. by using a builder that replaces these accessors).

Cheers,
Diego


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki