I wonder whether I will be able to like JavaFX! Have I been spoilt already by Groovy (it does, virtually, the same thing)? Maybe, but I managed to accept the long winded Java language well after Perl’s expressive power had spoilt me. I learned to love Java for its platforms and immense libraries, so what can I love about JavaFX?
You ask “what do you want?”. Well I want to have my cake and eat it, “damn it”! Ah, yes, maybe a little rant warning starts here.
In Java if I want to have a list of the English alphabet (say to seed my new GUI tabbed panes), I could do something like this
import java.util.*;
public class LettersJ {
private ArrayList<Character> letters = new ArrayList<Character>();
LettersJ() {
for(char ch= 'a'; ch<='z'; ch++){
letters.add(ch);
}
}
ArrayList<Character> getList() {
return this.letters;
}
public static void main(String[] args) {
LettersJ l = new LettersJ();
System.out.println(l.getList());
}
}
Well my fingers hurt already, carpal tunnel and RSI all flaring up. Java is long winded. No doubt a keener Java junky will send me a better version, but my point is to come.
In Groovy I wrote
def letters=['a'..'z']
letters.each { print it };
both give me the list I want, and printing produces the same
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
OK, my fingers obviously don’t hurt so much writing Groovy. What else?
What the hell happened with JavaFX? OK, I know I just started learning FX, and maybe I will be made to eat my words, but how do I do something so simple when sequences and ranges seem to be all for numbers (for blah in [1..10] not ['a'..'z')!
What's worse, where is my easy transition into JavaFX? I can't compile Java within my JavaFX script! OK, lets look at that Groovy again, that shows you what my rant is about.
def letters=['a'..'z']
letters.each { print it };
println "";
def lis = new LettersJ();
print (lis.getList());
public class LettersJ {
private ArrayList<Character> letters = new ArrayList<Character>();
LettersJ() {
for(char ch= 'a'; ch<='z'; ch++){
letters.add(ch);
}
}
ArrayList<Character> getList() {
return this.letters;
}
}
This is all compiled by “$ groovyc tst.groovy” and runs like so
$ groovy tst.groovy
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
My point? I don’t have to know how to program in Groovy to get going! Remember going from C to C++? OK, that was a stupid move admittedly, but the point remains, one is immediately producing results. Write it the way you know how, grow skills incrementally, one can learn and do at the same time!
Well in JavaFX I can compile my Java class as is (external to JavaFX, just in a file.java) and from a separate JavaFX script make use of it by doing this
var lis = new LettersJ(); print (lis.getList());
A storm in my emotional tea cup? Maybe. But do you see my point? They are not integrating anything like I would expect or wish!
ADDENDUM: It’s even less flexible than I thought, I must switch the ArrayList<Character> to ArrayList<String>, as JavaFX has only five basic data types. This works but hey, the languages are starting to stand apart! My question, is it worth it? I can mix TCL and C if I want this sort of incompatible tooling!



Pingback: Groovy and JavaFX, more useful together? « LEXECORP
FYI if you want an array, don’t put [] around the sequence but
Use (‘a’..’z')
$ cat each.groovy
(‘a’..’z').each { print “” }
$ groovy each.groovy
<a><b><c><d> … <z>
Alex
Pingback: Closer To The Ideal » Blog Archive » Why do we need JavaFX when we have Groovy?