[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: Re: value of assignment (Re: Order of the value of an expression
From: Mathieu Bouchard <matju () sympatico ! ca>
Date: 2003-02-12 20:55:51
[Download RAW message or body]
On Wed, 12 Feb 2003, Pit Capitain wrote:
> Yes, this is true. I see your point. But, at least for me, after
> o.quality = 999'999
> it feels strange that
> o.quality == 100
> The auto-adjust code might be handy if you always know what you're
> doing, but it could also hide some errors in your program. I think if
> I'd want to auto-adjust instead of raising an error, I would code it
> like this:
> def adjust_to_percent( value )
> [[value,0].max,100].min
> end
> percent = o.quality = adjust_to_percent( 999'999 )
> to make it obvious whats going on.
This is the old debate between implicitness and explicitness. I am not
sure whether I would actually code that way. I'm always keeping
automatically generated GUI's in mind, and for some reason I had thought
that making it auto-adjust would be good, but now I'm no longer very
sure... My actual solution to that problem is more like:
1. Make a type declaration for the :quality property. Its type would be
either 0..100 or And[Integer,0..100] depending on circumstances.
2. Optionally check the validity of the value assigned to the property. I
consider it a good thing to modularize type-checking out of
type-declaration, which explains the "optional" here. The reason for that
modularization is that type-decls are useful in other circumstances
(marshalling... runtime help... automatic GUI generation... etc)
3. Actual policies of auto-adjust (and other recovery strategies) are a
responsibility of the GUI controls (or of a common library of policies
being used by the GUI library)
I've been thinking almost like this for a while but hadn't taken the time
to clarify my ideas...
I'm still not to sure about the auto-adjust, because automatic casting is
one kind of auto-adjust (it's just that it recreates the value as being of
a different class instead of the same class), and I'm not necessarily
willing to make it go away, and think that all kinds of auto-adjusting
should be done at the same level.
Many general software design questions still unsolved...
________________________________________________________________
Mathieu Bouchard http://artengine.ca/matju
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic