Chris Oliver's Weblog

Tuesday Jul 10, 2007

Bidirectional binding

In addition to corrections to local variable binding the next update of the JavaFX interpreter will include extended bidirectional binding, including of logical negation, unary minus, arithmetic, and sequence indexing. Here's a JavaFXPad example you can try out:


// logical negation
var a = true;
var b = bind not a;
assert b == false;
b = true;
assert a == false; // passes

// arithmetic
var x = 10;
var y = bind -x + 100;
assert y == 90;
y = 40;
assert x == 60; // passes

// sequence elements
var seq = [1, 2, 3];
var elem1 = bind seq[1];
elem1 = 500;
assert seq == [1, 500, 3]; // passes
delete seq[1];
assert elem1 == 3; // passes
insert 0 as first into seq;
assert elem1 == 1; // passes
var value = bind elem1;
value = 999;
assert seq == [0, 999, 3]; // passes

Comments:

Is there a way to use only one-way or one-time binding?

Posted by Kevin on July 10, 2007 at 02:16 PM PDT #

One time binding... Isn't that an assign? Like: var a = true; var b = not a; B was binded to a once.

Posted by Tom on July 10, 2007 at 11:43 PM PDT #

In 1970, it was proven that Hilbert's tenth problem is unsolvable. It seems that the power of JavaFX transcends mathematics!

Posted by Neal Gafter on July 11, 2007 at 09:14 AM PDT #

what is the value of x and y ?
var x = 10;
var z = 10;
var y = bind x+z;

y = 5;

println(x);
println(z);

cheers,

Posted by Rémi Forax on July 11, 2007 at 01:58 PM PDT #

@remi If you tried it, you'd see the assignment to y is rejected in this case, since y = x + z doesn't have a 1-place inverse function.

Posted by chris oliver on July 11, 2007 at 02:20 PM PDT #

@neal

I'm not sure your sarcasm is warranted. JavaFX isn't purporting to do anything that's mathematically impossible.

Bidirectional binding as far as supported is just an abstraction of the operational model you have anyway with property change listener patterns.

There are legitimate uses, e.g. with "bidirectional" widgets like text fields, check boxes, and radio buttons, where solvable equations provide a convenient mechanism for expressing such behavior.

Of course, you can also create cases that are unsolvable in which case you'll get a compile-time or runtime error.

At least, in such cases, JavaFX automatically detects the error, which is an improvement over the manual programmer managed property change listener approach, I think.

Posted by chris oliver on July 11, 2007 at 02:47 PM PDT #

As I recall, Hilbert's tenth problem is defined over the set of all integers, or equivalently over the set of all naturals. Over any finite subset it would seem obvious that the solvability of any Diophantine equation could be determined in a finite number of steps simply by trying every possible solution. Since computers have annoyingly finite memory, I don't really see the problem. </maths pedant>

Posted by MartinM on July 12, 2007 at 01:18 AM PDT #

I love the idea of an open/open-source technology in this niche, such as JavaFX. That said I think working on JavaFX Script features, such as this one, is huge mistake. Fancy features are not needed there. If JavaFX gets any traction, it will be via code emtited by some tool anyway. That, and nobody wants to learn yet another language for these things, so just build out something super minimal; just enough to support what the tool needs. Put energy into (a) fast Java startup time (ok, that's be worked on), and (b) building out the tools that emit this stuff. I really want something open in the JavaFX niche to succeed, but I have a very bad feeling about these language features. It looks exactly like a grad student dorking around with some one-off language for fun, but without really weighing if there's an audience.

Or put another way: working on language features is fun, and working tools is a lot of work and a bore. But it sure looks like tools are what's needed, not more language features.

Posted by Nick Parlante on July 12, 2007 at 02:50 PM PDT #

Why is it that everyone wants to join the open source army as a general and not a foot-soldier? @Nick if you want open source tools for JavaFX, go build them. That would be a much more productive use of your time than trying to direct the efforts of others. @Chris although I don't think bi-directional binding will work out in the long run, thanks for at least trying to experiment with features that could make us more productive.

Posted by Spiff on July 12, 2007 at 06:06 PM PDT #

I think this looks pretty cool. I've always found the PropertyChangeListener a bit cumbersome so I hope this will work better. Off-topic question; Is there a grammar file for Java FX Script available somewhere? I was thinking about creating a Java FX plugin for IntelliJ.

Posted by Erik on July 13, 2007 at 04:18 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Calendar

Feeds

Search

Links

Navigation

Referers