Friday, June 12, 2009

JAVArsowia 2009

Next edition of JAVArsovia conference is getting closer :) Schedule looks amazing! Four tracks, and everything for free! What a pity I (probably) can't go there this year :( I would love to see presentations on testing and TDD (quite many presentations related to testing this year), Apache Wicket, Android, JVM virtualisation...

I know some speakers, not all of them, but the ones I know are great, so I assume the others are the same :) Also I wouldn't miss evening meeting, drinking beer, talking with fellow geeks and meeting new ones.

Well, I won't be there, but YOU still can :) I am pretty sure you won't regret it :)

Tuesday, June 9, 2009

Encoding movies (in ubuntu)

Example command to encode movies in ubuntu.
mencoder input-movie.avi -o output-movie.avi -oac mp3lame -mc 0 -ovc x264 -x264encopts bitrate=45000
You need to have mencoder installed. mp3lame is audio codec, x264 is video codec. To see other possible codecs type
mencoder -ovc help -ova help 
-mc 0 is for not messing with audio synchronization. Without it mencoder tries to synchronize audio with video, and it can break the synchronization. So if in source movie audio was synchronized well include this option. After -x264encopts there are x264 codec options. Other codecs have other options.

Mencoder howto site was helpful while looking for all this information.

Sunday, May 31, 2009

JavaFX is statically typed. Scala is statically typed.

Sometimes people are suprised when they read or hear that Scala and JavaFX are statically typed languages. Probably it is because in this languages you can declare variables without explicitly telling the type, like this:
//It looks exactly the same in JavaFX and Scala
var a = "string";
No type is given, yet compiler knows a is String (at compile time). How does it know? Well, we just assigned value of type String to it, didn't we? When declaring some variable and immediately assigning value to it, you don't have to add type to the declaration.

Saturday, May 23, 2009

Be careful binding to functions in JavaFX

In JavaFX (I'll call it JFX from now) there is possibility to bind variables. You can bind variable to another variable:
var src = 4;
def dst = bind src;
println(dst);
src = 42;
println(dst);
it'll print:
4
42
Maybe you noticed I used var for one variable and def for another. It could be as well var in both cases. Bind makes dst is updated every time it is read. Here we bound variable to another variable, but we can bind it to any expression:
var factor = 3;
var multiplier = 3;
def dst = bind getValue(multiplier);
println(dst);
multiplier = 5;
println(dst);

function getValue(p:Integer) {
 p * factor;
}
What it gives us?
9
15
Still everything is quite clear, isn't it? First value of dsc is 3*3, which is 9, than multiplier is changed and we get 5 * 3, which is 15. Let's now change factor, not multiplier:
var factor = 3;
var multiplier = 3;
def dst = bind getValue(multiplier);
println(dst);
factor = 5;
println(dst);

function getValue(p:Integer) {
 p * factor;
}
And we get:
9
9
Now this is wrong! First we want 3*3 which is 9, so it is ok, but then we change factor and expect 3*5, which is 15, but we still get 9. What's up? Well, dsc is bound to function. JFX remembers our function was called last time with parameter 3, and returned 9. Second time (second read of dst) it is also called with parameter 3, so JFX doesn't call it again, but just gives us cached value. But there is something we can do about it, and it is the bound keyword:
var factor = 3;
var multiplier = 3;
def dst = bind getValue(multiplier);
println(dst);
factor = 5;
println(dst);

bound function getValue(p:Integer) {
 p * factor;
}
And now it prints:
9
15
Just as expected. bound keyword makes JFX analyse the function and checks which variables can affect return value. In this case it can recoginze return value is dependent not only on input parameter, but also on factor variable, so when variable changes, JFX calls the function again even if the parameter doesn't change. Now consider a little different code:
var factor = 3;
var multiplier = 3;
def dst = bind getValue(multiplier);
println(dst);
Thread.currentThread().sleep(5);
multiplier = 5;
println(dst);
Thread.currentThread().sleep(5);
println(dst);

function getValue(p:Integer) {
 System.currentTimeMillis();
}
Note that function is not bound again. sleep(5) is there to make sure two calls won't happen in the same millisecond. So it can give us:
1243112189488
1243112189496
1243112189496
(of course you'll get different values if running it at different time) First is number of milliseconds, second is again proper number of milliseconds, because function parameter value has changed and JFX called function again, and then second value is repeated, because parameter value didn't change and function return value is taken from cache. But what happens when we'll use bound? Let's see:
var factor = 3;
var multiplier = 3;
def dst = bind getValue(multiplier);
println(dst);
Thread.currentThread().sleep(5);
multiplier = 5;
println(dst);
Thread.currentThread().sleep(5);
println(dst);

bound function getValue(p:Integer) {
 System.currentTimeMillis();
}
And we get:
1243112415228
1243112415228
1243112415228
What? All three values are the same? So adding bound even made things worse! How is it possible? Well, bound makes JFX not only can recognize which variables affect return values, but also which function parameters doesn't affect it. So now JFX is aware that p doesn't affect return value of the function and it calls the function only on the first time. Then it takes value from cache, regardless parameter has changed or not. Conclusion: Be careful when using functions for binding variables. Be extremely careful when using functions dealing with current time (or better just don't do it ;)).

Friday, May 22, 2009

JavaFX for linux

There is no official release of JavaFX for linux. Yet you can use it thanks to Silveira Neto. Here is his blog entry with plugins for Netbeans.

All you need to do is download the plugins, extract and install in Netbeans 6.5.x (doesn't work on 6.7 beta). You also need java 1.6 update 13.

Sunday, May 17, 2009

Key promoter for Eclipse

Did you ever miss key promoter in Eclipse? I did. Fortunately I found one: Mousefeed

Whenever you do some action with your mouse, and there is keyboard shortcut for this action, the shortcut is displayed:

English from now on

Z tych samych przyczyn co Paweł Szulc, przechodzę na angielski. Mam nadzieję, że nie ubędzie mi przez to czytelników.