- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Running ScalaTest tests from JUnit under NetBeans?
Sun, 2011-04-24, 14:21
I’m using NetBeans 6.9.1. I’m trying to use ScalaTest 1.3 to manage the unit tests of my project and also integrate the running of those these with the NetBeans built in support for JUnit 4.5. My problem is that NetBeans does not recognize the tests. It tells me there are no tests to run. Here is an sketch of one of my test suites:
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{Assertions, FunSuite}
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class ExampleSuite extends FunSuite with Assertions with ShouldMatchers {
test(“Some Excellent Test”) {
// Blah, blah, blah
}
}
My understanding is that the @RunWith annotation is intended to indicate to JUnit how the test should be run. This allows JUnit to execute the test and understand its results. I’m not a JUnit expert by any means but that’s how I interpret the documentation that I’ve seen. Apparently, however, NetBeans’ built-in JUnit support isn’t smart enough to handle the annotation.
Now I recall hearing somewhere (on this list?) that scalac does not actually embedded the annotations into the generated class files. If that is so, it would explain why JUnit is having trouble finding it. However, that can’t be the full story because then the @RunWith annotation wouldn’t work at all.
A couple of other observations: First, my test code compiles fine. Second, if I write a JUnit test (in Scala) NetBeans can launch it fine. For example
import org.junit._
class ExampleTest {
@Test
def someExcellentTest = {
// Blah, blah, blah
}
}
I’d rather use ScalaTest more directly because of its nice features. Is this something that just doesn’t work in NetBeans or am I doing something wrong?
Thanks
Peter
Sun, 2011-04-24, 19:47
#2
Re: Running ScalaTest tests from JUnit under NetBeans?
Hi Peter,
I'm away from a computer and can't try this. Sounds like the issue is
with how Tools like NetBeans or Eclipse recognize a class as a test
class, since there is no base class in JUnit4 (in JUnit 3, every test
class extended TestCase). Looking for an annotation is how it should
be done, and so it should work with just JUnitRunner. That it doesn't
sounds like a NetBeans "bug" to me.
Some tools look for classes whose name ends in Test. One thing you
could try is renaming ExampleSuite to ExampleTest. Another thing to
try is to declare an unused method with a @Test annotation:
@Test def yesImATestClass() {}
Unless you're using JUnitSuite, ScalaTest will do nothing with that
method. If it gets tools to recognize your class but has no effect
when running the class, that would solve your issue. You could then
put this @Test method in a trait and mix it in to all your suite
classes.
Please let me know if either of these solve the problem.
Thanks.
Bill
----
Bill Venners
Artima, Inc.
http://www.artima.com
On Apr 24, 2011, at 6:21 AM, "Peter C. Chapin"
wrote:
> I’m using NetBeans 6.9.1. I’m trying to use ScalaTest 1.3 to
> manage the unit tests of my project and also integrate the running o
> f those these with the NetBeans built in support for JUnit 4.5. My p
> roblem is that NetBeans does not recognize the tests. It tells me th
> ere are no tests to run. Here is an sketch of one of my test suites:
>
>
>
> import org.junit.runner.RunWith
>
> import org.scalatest.junit.JUnitRunner
>
> import org.scalatest.{Assertions, FunSuite}
>
> import org.scalatest.matchers.ShouldMatchers
>
>
>
> @RunWith(classOf[JUnitRunner])
>
> class ExampleSuite extends FunSuite with Assertions with
> ShouldMatchers {
>
> test(“Some Excellent Test”) {
>
> // Blah, blah, blah
>
> }
>
> }
>
>
>
> My understanding is that the @RunWith annotation is intended to
> indicate to JUnit how the test should be run. This allows JUnit to
> execute the test and understand its results. I’m not a JUnit expert
> by any means but that’s how I interpret the documentation that
> I’ve seen. Apparently, however, NetBeans’ built-in JUnit support
> isn’t smart enough to handle the annotation.
>
>
>
> Now I recall hearing somewhere (on this list?) that scalac does not
> actually embedded the annotations into the generated class files. If
> that is so, it would explain why JUnit is having trouble finding it.
> However, that can’t be the full story because then the @RunWith anno
> tation wouldn’t work at all.
>
>
>
> A couple of other observations: First, my test code compiles fine.
> Second, if I write a JUnit test (in Scala) NetBeans can launch it
> fine. For example
>
>
>
> import org.junit._
>
>
>
> class ExampleTest {
>
> @Test
>
> def someExcellentTest = {
>
> // Blah, blah, blah
>
> }
>
> }
>
>
>
> I’d rather use ScalaTest more directly because of its nice features.
> Is this something that just doesn’t work in NetBeans or am I doing
> something wrong?
>
>
>
> Thanks
>
>
>
> Peter
>
>
Sun, 2011-04-24, 22:37
#3
RE: Running ScalaTest tests from JUnit under NetBeans?
> Some tools look for classes whose name ends in Test. One thing you could try
> is renaming ExampleSuite to ExampleTest.
That did the trick. When I renamed the test class to include "Test" at the end of its name NetBeans was able to run the test just fine.
Thanks!
Peter
Mon, 2011-04-25, 02:57
#4
Re: Running ScalaTest tests from JUnit under NetBeans?
Hi Peter,
On Sun, Apr 24, 2011 at 2:29 PM, Peter C. Chapin wrote:
>
>> Some tools look for classes whose name ends in Test. One thing you could try
>> is renaming ExampleSuite to ExampleTest.
>
> That did the trick. When I renamed the test class to include "Test" at the end of its name NetBeans was able to run the test just fine.
>
Glad that worked. I have as yet not quite figured out which tools do
what to detect JUnit test classes. I think a "Test" suffix is a bit
unfortunate for ScalaTest suites because a collection of tests in
ScalaTest is called a suite not a test, and a "spec" is a special kind
of suite. So the more natural way to name test classes in ScalaTest is
using either a Suite or Spec suffix.
On the other hand, one thing that may be good about looking for one or
more suffixes is that it could speed up discovery. That might be why
these tools look for a suffix instead of introspecting and looking all
over the place, including members inherited from supertypes, for JUnit
annotations. I may try an experiment to see whether adding a Runner
flag for ignoring during discovery any class files whose class name
doesn't end in Suite or Spec, or possibly other user-provided
suffixes, would speed up discovery enough to justify adding the
feature.
Bill
> Thanks!
>
> Peter
>
>
>
Mon, 2011-04-25, 04:27
#5
Bind capability like javafx
JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
Mon, 2011-04-25, 07:07
#6
Re: Bind capability like javafx
Am 25.04.2011 05:24, schrieb coach3pete:
> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
use a function that calculates A, based on B:
val a = () => "hello "+b
then you can pass a around and it "changes" when b changes
Mon, 2011-04-25, 22:57
#7
Re: Bind capability like javafx
In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Mon, 2011-04-25, 23:07
#8
Re: Bind capability like javafx
In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:
In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Tue, 2011-04-26, 00:57
#9
Re: Bind capability like javafx
Right, JFX "bind" creates and registers the listener/reactor under the hood. Looks like https://github.com/nafg/reactive is trying to do this at the library level for Scala. So I should be able to do something like below...but getting errors.
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is:.:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}}<console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is:.:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}}<console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:
In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Tue, 2011-04-26, 01:37
#10
Re: Bind capability like javafx
I don't think this is doable, because properties of swing are not signals(?) themselves, I read a bit of the paper, and If I understood correctly, and scala.reactive is an implementation of that, then in order for the example to work, you would need a redesign (or a huge wrapping) of swing, to make all the bean properties signals(?)
Note: (?) is used to denote what I am not sure about :-)
Cheers
On Mon, Apr 25, 2011 at 8:52 PM, Erik Peterson <ep@ardec.com> wrote:
Note: (?) is used to denote what I am not sure about :-)
Cheers
On Mon, Apr 25, 2011 at 8:52 PM, Erik Peterson <ep@ardec.com> wrote:
Right, JFX "bind" creates and registers the listener/reactor under the hood. Looks like https://github.com/nafg/reactive is trying to do this at the library level for Scala. So I should be able to do something like below...but getting errors.
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is: .:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}} <console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Tue, 2011-04-26, 02:07
#11
Re: Bind capability like javafx
Ahhh yes, minor detail ;-) Looks like this is something that requires changes at the language level to support. Thanks all!
On Apr 25, 2011, at 6:28 PM, Rodrigo Cano wrote:
Erik Petersonm: (281) 804-9023ep@ardec.com
On Apr 25, 2011, at 6:28 PM, Rodrigo Cano wrote:
I don't think this is doable, because properties of swing are not signals(?) themselves, I read a bit of the paper, and If I understood correctly, and scala.reactive is an implementation of that, then in order for the example to work, you would need a redesign (or a huge wrapping) of swing, to make all the bean properties signals(?)
Note: (?) is used to denote what I am not sure about :-)
Cheers
On Mon, Apr 25, 2011 at 8:52 PM, Erik Peterson <ep@ardec.com> wrote:
Right, JFX "bind" creates and registers the listener/reactor under the hood. Looks like https://github.com/nafg/reactive is trying to do this at the library level for Scala. So I should be able to do something like below...but getting errors.
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is: .:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}} <console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Erik Petersonm: (281) 804-9023ep@ardec.com
Tue, 2011-04-26, 09:17
#12
Re: Bind capability like javafx
hi,
there was a java jsr for this feature before it got implemented into jfx compiler. i think it was something about property change listeners / bindings. you might want to try that jsr in scala. as far as i remember, there were quite some performance issues though.
jiri
On Tue, Apr 26, 2011 at 2:56 AM, Erik Peterson <ep@ardec.com> wrote:
--
web: http://www.dredwerkz.cz
group: http://groups.google.com/group/dr3dwerkz
music: http://profile.ultimate-guitar.com/g0dd4rd/
twitter: http://twitter.com/#!/g0dd4rd
profile: http://www.google.com/profiles/g0dd4rd
icq: 218 659 431
there was a java jsr for this feature before it got implemented into jfx compiler. i think it was something about property change listeners / bindings. you might want to try that jsr in scala. as far as i remember, there were quite some performance issues though.
jiri
On Tue, Apr 26, 2011 at 2:56 AM, Erik Peterson <ep@ardec.com> wrote:
Ahhh yes, minor detail ;-) Looks like this is something that requires changes at the language level to support. Thanks all!
On Apr 25, 2011, at 6:28 PM, Rodrigo Cano wrote:I don't think this is doable, because properties of swing are not signals(?) themselves, I read a bit of the paper, and If I understood correctly, and scala.reactive is an implementation of that, then in order for the example to work, you would need a redesign (or a huge wrapping) of swing, to make all the bean properties signals(?)
Note: (?) is used to denote what I am not sure about :-)
Cheers
On Mon, Apr 25, 2011 at 8:52 PM, Erik Peterson <ep@ardec.com> wrote:
Right, JFX "bind" creates and registers the listener/reactor under the hood. Looks like https://github.com/nafg/reactive is trying to do this at the library level for Scala. So I should be able to do something like below...but getting errors.
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is: .:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}} <console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Erik Petersonm: (281) 804-9023ep@ardec.com
--
web: http://www.dredwerkz.cz
group: http://groups.google.com/group/dr3dwerkz
music: http://profile.ultimate-guitar.com/g0dd4rd/
twitter: http://twitter.com/#!/g0dd4rd
profile: http://www.google.com/profiles/g0dd4rd
icq: 218 659 431
Tue, 2011-04-26, 11:47
#13
Re: Bind capability like javafx
On 26/04/2011 10:09, Goddard Jiri wrote:
> there was a java jsr for this feature before it got implemented into jfx compiler. i think
> it was something about property change listeners / bindings. you might want to try that
> jsr in scala. as far as i remember, there were quite some performance issues though.
Yes, in JavaFX, the word was to avoid abusing of binding because of the performance hit...
It is too tempting to put it everywhere... and see a dramatic slow down of the application.
They went through some optimizations near the latest versions, though.
Note that the JavaFX compiler is still open source... And I think they reimplemented it in
pure Java since that's the way JavaFX 2 went, but it is not open source yet.
The 'on replace' idiom was interesting too.
Tue, 2011-04-26, 21:47
#14
Re: Re: Bind capability like javafx
I also wondered about binding, like I had enjoyed in JavaFx. For
Scala, I would really like to see a compiler plugin that adds
assignment observability hooks. On top of this any number of binding
libraries could be built up. Then when it was working/more popular it
might even get accepted into the language. But like so many "ideas",
I haven't wanted it enough to justify spending the time.
Here is an old post on the subject from 1/24/10 on the Debate List:
........................................................................................................
I am relatively new to Scala. I apologize if my question/suggestion
has already been flogged to death, but after a quick search I didn't
find much.
I would just like to offer a few ideas about binding. Like JavaFx,
but not quite.
I have been thinking about this for quite a few years and have come to
the conclusion that there is no single approach to binding at a high
level. Several years ago I wrote my own binding library for Java that
describes interesting relationships between entities in a way that
provided what I wanted for desk top development. (But, obviously, I
couldn't do the detection of changes in entities within plain Java.
You have to resort to AOP, byte code manipulation, or just hand
wiring.) The interesting thing is that over the past few years there
have been other solutions that have come along that all do it
differently based on the authors perspective and the platform that is
being targeted.
My suggestion is that Scala offer the simplest possible binding
facilitation as part of the language, and then in the spirit of
scalability allow others to write binding behavior as libraries.
My thoughts in rough form are:
First, provide a way to enhance vars with optional, integrated change
notification. I.e. something like
bindable var foo = 0
I don't really care about how the syntax would look, so much as the
ability to tell a var that at some time in the future, I may decide
that I want notification of reassignment.
Second, the implicit ability to add/remove multiple observers to vars
that have been so declared.
Third, the ability to plug in an alternate notification/registration
strategy. When an assignment happens, the default strategy would just
notify everything in the same order that observers where added. But
an alternate strategy could handle all kinds of prioritization,
filtering or smart recursion.
Fourth, if you make behavioral groups, where each group can have a
separate strategy, then the first and third point get even more
flexable, so that a library or module can use its own definition of
what binding ought to do. Something like,
bindable(grp) var foo = 0
Fifth, if you also add a kind of related functionality to also get
notification of when a var is read, then you can write clever little
networks of minimal computation, auto-updating values. (Like a
spreadsheet does, but more implicit.) With the support of language
features you could achieve this much more naturally.
I understand that there are probably lots of hairy issues involved in
making a generic feature, but maybe there is a good solution.
With tools like this, a lot of current listener/ notification code
could be simplified drastically. I think that Scala could offer a
better binding than JavaFx
Tue, 2011-04-26, 21:57
#15
Re: Re: Bind capability like javafx
what exactly would be the benefit over a class that can wrap a value,
manage listeners and be implicitly unwrapped if a method of the
contained value is called?
i don't see one yet
Am 26.04.2011 22:38, schrieb JamesJ:
> I also wondered about binding, like I had enjoyed in JavaFx. For
> Scala, I would really like to see a compiler plugin that adds
> assignment observability hooks. On top of this any number of binding
> libraries could be built up. Then when it was working/more popular it
> might even get accepted into the language. But like so many "ideas",
> I haven't wanted it enough to justify spending the time.
>
>
> Here is an old post on the subject from 1/24/10 on the Debate List:
> ........................................................................................................
>
> I am relatively new to Scala. I apologize if my question/suggestion
> has already been flogged to death, but after a quick search I didn't
> find much.
>
> I would just like to offer a few ideas about binding. Like JavaFx,
> but not quite.
>
> I have been thinking about this for quite a few years and have come to
> the conclusion that there is no single approach to binding at a high
> level. Several years ago I wrote my own binding library for Java that
> describes interesting relationships between entities in a way that
> provided what I wanted for desk top development. (But, obviously, I
> couldn't do the detection of changes in entities within plain Java.
> You have to resort to AOP, byte code manipulation, or just hand
> wiring.) The interesting thing is that over the past few years there
> have been other solutions that have come along that all do it
> differently based on the authors perspective and the platform that is
> being targeted.
>
> My suggestion is that Scala offer the simplest possible binding
> facilitation as part of the language, and then in the spirit of
> scalability allow others to write binding behavior as libraries.
>
> My thoughts in rough form are:
>
> First, provide a way to enhance vars with optional, integrated change
> notification. I.e. something like
> bindable var foo = 0
> I don't really care about how the syntax would look, so much as the
> ability to tell a var that at some time in the future, I may decide
> that I want notification of reassignment.
>
> Second, the implicit ability to add/remove multiple observers to vars
> that have been so declared.
>
> Third, the ability to plug in an alternate notification/registration
> strategy. When an assignment happens, the default strategy would just
> notify everything in the same order that observers where added. But
> an alternate strategy could handle all kinds of prioritization,
> filtering or smart recursion.
>
> Fourth, if you make behavioral groups, where each group can have a
> separate strategy, then the first and third point get even more
> flexable, so that a library or module can use its own definition of
> what binding ought to do. Something like,
> bindable(grp) var foo = 0
>
> Fifth, if you also add a kind of related functionality to also get
> notification of when a var is read, then you can write clever little
> networks of minimal computation, auto-updating values. (Like a
> spreadsheet does, but more implicit.) With the support of language
> features you could achieve this much more naturally.
>
> I understand that there are probably lots of hairy issues involved in
> making a generic feature, but maybe there is a good solution.
>
> With tools like this, a lot of current listener/ notification code
> could be simplified drastically. I think that Scala could offer a
> better binding than JavaFx
>
Tue, 2011-04-26, 23:27
#16
Re: Re: Bind capability like javafx
Wrapping is OK. I am currently using a similar strategy where I need
it. But having used both Scala and JavaFx my answer would be that
wrapping does not have the elegance or clarity of intent of language
level support. (But I would still take Scala any day over JavaFX)
On Tue, Apr 26, 2011 at 2:52 PM, HamsterofDeath wrote:
> what exactly would be the benefit over a class that can wrap a value,
> manage listeners and be implicitly unwrapped if a method of the
> contained value is called?
> i don't see one yet
Tue, 2011-04-26, 23:57
#17
Re: Re: Bind capability like javafx
On Tue, Apr 26, 2011 at 3:20 PM, JamesJ <james@kybios.com> wrote:
Is it my turn to paste this URL? :)
http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf
-0xe1a
Wrapping is OK. I am currently using a similar strategy where I need
it. But having used both Scala and JavaFx my answer would be that
wrapping does not have the elegance or clarity of intent of language
level support. (But I would still take Scala any day over JavaFX)
Is it my turn to paste this URL? :)
http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf
-0xe1a
Wed, 2011-04-27, 05:57
#18
Re: Re: Bind capability like javafx
Wrapping? So with the example below, you would create a "BindableLabel" class as an extension of Label with an addListeners() etc. to react and update the text field when var name changes? Is that the pattern we're talking about?
var name = "Bob"
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => "hello "+ name
}}
On Apr 26, 2011, at 4:20 PM, JamesJ wrote:
> Wrapping is OK. I am currently using a similar strategy where I need
> it. But having used both Scala and JavaFx my answer would be that
> wrapping does not have the elegance or clarity of intent of language
> level support. (But I would still take Scala any day over JavaFX)
>
> On Tue, Apr 26, 2011 at 2:52 PM, HamsterofDeath wrote:
>> what exactly would be the benefit over a class that can wrap a value,
>> manage listeners and be implicitly unwrapped if a method of the
>> contained value is called?
>> i don't see one yet
Wed, 2011-04-27, 06:37
#19
Re: Re: Bind capability like javafx
By wrapping I am just saying its possible, although the necessary work to consider all swing its just useless I think. Same thing that happened for scala.swing, there are lots of components that still lack wrapping, and I am not even mentioning things la swingx that could also be treated as standard swing now a day. So insyou tead of that, I think I would attempt a reflection generalization for beans (you know, using BeanInspector to find out about properties and listeners and stuff), adding property change listeners, and expose found porperties via signals. Imagine a trait could do just this when mixed into a JComponent, then signals could be named via symbols or something like that, but you loose static typing, because whether or not a signal actually exists will be found out upon execution, which is highly undesirably. And now we are back to the initial solution of wrapping, that had its own problems :-).
Those are mi thoughts about the problem. We will not have swing in a FRP way unless some kind of compiler magic happens, which could be undertaken by a compiler writer but who knows.. java programmers are not very much into desktop application I have read, and I have also read that javafx2 will actually attempt to revert this situation. Given this, javafx2, which will bring many major updates like a new windowing system outside of awt, and a new rendering pipeline called Prism, is supposed to provide a binding mechanism, so I thing that we should wait some time before taking some big effort on providing a nice API over swing.
Any other thoughts on the topic?
Cheers.
On Wed, Apr 27, 2011 at 1:49 AM, coach3pete <ep@ardec.com> wrote:
Those are mi thoughts about the problem. We will not have swing in a FRP way unless some kind of compiler magic happens, which could be undertaken by a compiler writer but who knows.. java programmers are not very much into desktop application I have read, and I have also read that javafx2 will actually attempt to revert this situation. Given this, javafx2, which will bring many major updates like a new windowing system outside of awt, and a new rendering pipeline called Prism, is supposed to provide a binding mechanism, so I thing that we should wait some time before taking some big effort on providing a nice API over swing.
Any other thoughts on the topic?
Cheers.
On Wed, Apr 27, 2011 at 1:49 AM, coach3pete <ep@ardec.com> wrote:
Wrapping? So with the example below, you would create a "BindableLabel" class as an extension of Label with an addListeners() etc. to react and update the text field when var name changes? Is that the pattern we're talking about?
var name = "Bob"
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => "hello "+ name
}}
On Apr 26, 2011, at 4:20 PM, JamesJ wrote:
> Wrapping is OK. I am currently using a similar strategy where I need
> it. But having used both Scala and JavaFx my answer would be that
> wrapping does not have the elegance or clarity of intent of language
> level support. (But I would still take Scala any day over JavaFX)
>
> On Tue, Apr 26, 2011 at 2:52 PM, HamsterofDeath <h-star@gmx.de> wrote:
>> what exactly would be the benefit over a class that can wrap a value,
>> manage listeners and be implicitly unwrapped if a method of the
>> contained value is called?
>> i don't see one yet
Wed, 2011-04-27, 07:17
#20
Re: Bind capability like javafx
Hi, the error you are seeing is a regular scala mistake (perhaps made worse by not knowing how to use reactive).
Specifically, the line:
text = name.map[String, Signal[String]](_)
has a few issues.
Imagine name was not a Var[String], but a Seq[String]:
val name = List("Bob")
name.map(_)
I'm guessing you want to map with the identity function (x=>x). However _ does not mean this. It's confusing because _.toString is short for x=>x.toString. But _ is not short for x=>x.
Secondly, again with the List analogy, mapping with the identity function is not helpful: You have a Seq[String] and you get a new Seq[String] with the same semantics. I'm guessing that you want to tell scala-swing to assign the contents of the Var to 'text'. But name.map(...) will only return a new Signal, which of course cannot be assigned to text. So what you need to do is either:1) Write a reactive-swing wrapper. :) (A lot more work, but useful to the community.)2) Tell name to assign its contents to text:
object BindApp extends SimpleSwingApplication with Observing {// ...for(n <- name) text = n // syntactic sugar for name.foreach(text = _)text = name.now // This line might not be necessary. If it still is then it should become unnecessarily shortly G-d willing
On Mon, Apr 25, 2011 at 7:52 PM, Erik Peterson <ep@ardec.com> wrote:
Specifically, the line:
text = name.map[String, Signal[String]](_)
has a few issues.
Imagine name was not a Var[String], but a Seq[String]:
val name = List("Bob")
name.map(_)
I'm guessing you want to map with the identity function (x=>x). However _ does not mean this. It's confusing because _.toString is short for x=>x.toString. But _ is not short for x=>x.
Secondly, again with the List analogy, mapping with the identity function is not helpful: You have a Seq[String] and you get a new Seq[String] with the same semantics. I'm guessing that you want to tell scala-swing to assign the contents of the Var to 'text'. But name.map(...) will only return a new Signal, which of course cannot be assigned to text. So what you need to do is either:1) Write a reactive-swing wrapper. :) (A lot more work, but useful to the community.)2) Tell name to assign its contents to text:
object BindApp extends SimpleSwingApplication with Observing {// ...for(n <- name) text = n // syntactic sugar for name.foreach(text = _)text = name.now // This line might not be necessary. If it still is then it should become unnecessarily shortly G-d willing
On Mon, Apr 25, 2011 at 7:52 PM, Erik Peterson <ep@ardec.com> wrote:
Right, JFX "bind" creates and registers the listener/reactor under the hood. Looks like https://github.com/nafg/reactive is trying to do this at the library level for Scala. So I should be able to do something like below...but getting errors.
scala> :cp reactive-core_2.8.1-0.1.jar Added '/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar'. Your new classpath is: .:/Users/ep/git-repos/3rdparty/scala-reactive/reactive/reactive-core/target/scala_2.8.1/reactive-core_2.8.1-0.1.jar
scala> import scala.swing._ import scala.swing._
scala> import reactive._ import reactive._
scala> object BindApp extends SimpleSwingApplication { | val name = Var("Bob") | override def main(args: Array[String]) { | startup(args) | Thread.sleep(5000) | name ()= "Tom" | Thread.sleep(5000)} | def top = new MainFrame { | title = "Bind App" | contents = new Button { | text = name.map[String, Signal[String]](_) | }}} <console>:21: error: missing parameter type for expanded function ((x$1) => name.map[String, Signal[String]](x$1)) text = name.map[String, Signal[String]](_)
On Apr 25, 2011, at 3:58 PM, Rodrigo Cano wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a.What is the difference?, how can you tell that a did change if not by calling it?If what you mean is that, the text property for a given label gets auto updated changing the display, then what you need is not binding in the terms of HamsterOfDeath's example (which is completely valid), but a notification of the change propagated to listeners (or reactors). You should check what was proposed by Adam Rabung.
On Mon, Apr 25, 2011 at 6:36 PM, coach3pete <ep@ardec.com> wrote:In your example, "a" only updates when it is called. JavaFX bind would update a when b is changed--no need to call a. Take a look at the pseudo code below. If bind{} were available, whenever name changed, the expression ("hello" + name) would change and the text label would update automatically.
object BindApp extends SimpleGUIApplication {
var name = "Bob"
override def main(args: Array[String]) {
startup(args)
Thread.sleep(2000)
name = "Tom"
Thread.sleep(2000)
}
def top = new MainFrame {
title = "Bind App"
contents = new Label {
text = () => bind {"hello "+ name}
}}}
Here is an actor based polling way to "bind". Every 500ms a timeout is generated and the label gets updated. Works, but ugly.
case object Updater extends Actor{
def act() {
loop {
reactWithin(500) {
case TIMEOUT => {
App.exTimeLabel.text = App.session.curItem + ": " + App.session.curItem.remaining.toString + "/" + App.session.curItem.duration
App.sessionTimeLabel.text = "Session: " + App.session.remainingTime + "/" + App.session.totTime.toString
}
}
}
}
}
On Apr 24, 2011, at 11:58 PM, HamsterofDeath wrote:
> Am 25.04.2011 05:24, schrieb coach3pete:
>> JavaFX script had a very useful ability to bind variable A to B, such that when B value changed, so did the A value. How might this be done in scala?
>
> use a function that calculates A, based on B:
>
> val a = () => "hello "+b
>
> then you can pass a around and it "changes" when b changes
>
Erik Peterson
m: (281) 804-9023
ep@ardec.com
Just to add: I had the very same trouble under Eclipse. So I've been
using org.scalatest.tools.Runner ever since.
I've got just the assumption that tests are not recognized because
they are not in the folder corresponding to the package name as valid
for java sources? Sorry, but I've not yet checked this.