[MacRuby-devel] [MacRuby] #409: Attribute setter should be accepted as KVO setter
MacRuby
ruby-noreply at macosforge.org
Sat Oct 31 10:37:28 PDT 2009
#409: Attribute setter should be accepted as KVO setter
---------------------------------+------------------------------------------
Reporter: neeracher@… | Owner: lsansonetti@…
Type: enhancement | Status: new
Priority: minor | Milestone:
Component: MacRuby | Keywords:
---------------------------------+------------------------------------------
Comment(by dylan@…):
*poke* I just ran into this one and traced it down. Any updates ?
I've attached a project that shows a naive implementation with bindings
that shows how someone could get into trouble with this.
I think this is a little more severe than it appears at first glance. It
violates the principle of least surprise in a big way; even something a
simple as adapting example code to a new Mac interface will run afoul of
this pretty quickly.
Even if you're familiar with both Ruby and ObjC this generates some
confusion since you can no longer use idiomatic ruby to change your model
if you want it bound to the UI at any future date. You currently have to
get used to always using the ObjC setValue way.
If you're not familiar with both you're going to be scratching your head
for a while.
This is also insidious since your model unit tests will pass and only the
less easily testable UI will fail, unless you set up explicit bindings
tests for each property.
That said, this may not be as simple a fix as it appears. My gut feeling
was to override attr_accessor and writer to generate a value= method that
just calls setValue. This works 95% of the time, but gets murky when you
want to create a custom setter. Which do you override ? Do you always have
to call setValue from your value= method ? How should it be documented if
that's the case ? Of course, you still have that confusion the way it
exists now. Going to implement value= and then finding that your bindings
don't call that method, for instance.
--
Ticket URL: <http://www.macruby.org/trac/ticket/409#comment:1>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list