2009-02-26
Qt Jambi first experience
Being long time KDE user and Java developer - I couldn't ignore Qt Jambi release. Of course I downloaded it and tried as soon as version 1.0 vas released. Yes, at first it was version 1.0, built with Qt 4.3. Only after some time Jambi got version as its Qt.
I was impressed even with first version, but it seemed a bit slow and not yet ready for every day usage. But last week there were some news about Qt 4.5 and LGPL license, so I downloaded last available version of Jambi and started few example apps.
And now I am really impressed! I used to think about Swing as fast and developer-friendly when developing some desktop applications, but now I know Qt is really two heads higher in desktop apps development. Jambi evolved and now there is no problem of setting LD_LIBRARY_PATH and other params, you can simply include jar file with Qt and Jambi libs to your classpath.
Then I started a bit bigger project to have complete application in Jambi. As long as there is no fast and stable notepads for Windows I wrote QEdit. You can see sources here.
Now, after I have some first experience with Jambi I can compare Jambi and Swing:
+ Jambi has better shortcuts system. You don't have to work with root panes and actionmaps, you can just ass some shortcut to your action.
+ QStatusBar. I thought about writing something similar for Swing few month ago, but here you can assign statusTip to your action and that tip will appear in status bar on rollover.
+ QSettings. It is much more usable than Properties for storing your settings.
+ QToolBar. Even if it is possible to do something similar in Swing - you will never spend so much time to do it like Qt can. You can download and run QEdit to see how you can move toolbars to different parts of main window and this position will be saved between sessions.
+ QFontDialog. Almost every Swing application have to implement Font Chooser themselves, while QFontDialog is almost the same in every application.
+ Components already have their scrollbars, you can just enable or disable them. I can't remember at least one case when you don't need to wrap JTextArea into JScrollPane.
+ Wide range of supported graphic formats and components adjust size of graphic automatically.
- Jambi can't see if wrapped C++ classes extend some other classes.
- Jambi QFile is very slow and locking file. I don't like when File object locks real file on file system, only io operation should block it. So don't try to use Qt Jambi for all your tasks at once.
- No way to extend or customize QFileDialog. Even style is not applied to QFileDialog.
- Signals in "action system"... It's just wrong in Java. Thanks that application fails on first start but not in time of invocation if something is wrong in source.
- You can't give both small and large icon to QAction. After providing 22x22 icons some of them looks too smooth in main menu.
- Lack of documentation. If you are not enough documentation and examples from Jambi distribution - even Google will not give you a lot.
- Looks like all the work is performed in blocking QApplication.exec() method. I can't find is there anything like SwingWorker for Qt or Jambi...
- There are lots of possible pitfalls when you are writing huge application, and Swing "experience base" is huge enough to help you in almost everything, plus Swing is pure Java where you can debug everything you want. But where to go with Jambi? There is support in Trolltech for commercial version...
2009-02-16
Java is faster than native
There is a myth that native is much faster than java. Lots of frameworks speculate this myth and using lots of native methods from java. But how often they are implementing same functionality and check native against true-java? They are often diving so deep in own fantasies about native performance that it is almost religion, they just don't accept facts. But how much it takes to JVM to invoke method from native library? And how much is it comparing to raw java interpretation?
I don't like to use things that I don't understand. Almost all methods from Math class is native, and I can't see sources of that classes. There are some functions that would be hard to implement, like Math.sin() or Math.cos(), but there are some easy-to-implement methods. This time I need functionality of method Math.pow(). It is not hard to implement it in java:
private double pow(double value, double pow) {
double result = value;
for (int i = 1; i < pow; i++) {
result = result * value;
}
return result;
}
And it is not hard to implement some raw test using case from current developed application:
private static final int times = 1000000;
public static void main(String[] args) {
// running test 10 times to "hotspot" it
for (int i = 0; i < 10; i++) {
// I know, I know, you can never
// preallocate long, but I like it:
long start = 0;
long end = 0;
start = System.currentTimeMillis();
for (int j = 0; j < times; j++) {
pow(10, 10);
}
end = System.currentTimeMillis();
System.out.println("pow: " + (end - start));
// cleaning JVM every time before next cycle:
System.gc();
System.runFinalization();
System.gc();
start = System.currentTimeMillis();
for (int j = 0; j < times; j++) {
Math.pow(10, 10);
}
end = System.currentTimeMillis();
System.out.println("math: " + (end - start));
System.gc();
System.runFinalization();
System.gc();
// and running once more to be sure in hotspot:
start = System.currentTimeMillis();
for (int j = 0; j < times; j++) {
pow(10, 10);
}
end = System.currentTimeMillis();
System.out.println("pow: " + (end - start));
System.gc();
System.runFinalization();
System.gc();
start = System.currentTimeMillis();
for (int j = 0; j < times; j++) {
Math.pow(10, 10);
}
end = System.currentTimeMillis();
System.out.println("math: " + (end - start));
System.gc();
System.runFinalization();
System.gc();
}
}
I just wanted to figure out how slow is my implementation, but results were totally unexpected!
run-single:
pow: 63
math: 797
pow: 78
math: 797
pow: 78
math: 781
pow: 78
math: 781
pow: 63
math: 781
pow: 63
math: 781
pow: 63
math: 797
pow: 63
math: 797
pow: 63
math: 797
pow: 63
math: 782
It's 10 times faster than Math.pow() when raising power of 10!!
Think different. Think faster!
2009-02-12
Chaos Dreadnought conversion
Games Workshop produces two kinds of kits - metal and plastic. I hate metal kits - it is hard to convert them, hard to keep them unbroken, hard to repair them if they're broken. And Chaos Dreadnought is metal model.
Modeling Plastic Chaos Dreadnought!
All you need - Plastic Space Marines Dreadnought, few Terminator torso bits and few decorative chaos bits. And may be some greenstuff.


2008-11-07
Swing and TreeTable component
TreeTable combines functionality of two components - Tree and Table. And it is really comfortable to show some hierarchical information like file system structure or many others.
TreeTable have great Qt implementation, it's fast, useful and pretty. It's a pity there is no standard Swing implementation of this component. But there are lots of third-party implementations. Let’s review them:
JEdit
JEdit uses TreeTable component for Open-Save dialog. It is extremely fast and pretty. But they did it for their own, with package-private constructor and double-linked to other JEdit components. To use it in other projects means to rewrite it almost from scratch, so JEdit is just a good demo of TreeTable possibilities for Swing.

SwingX
SwingLabs has their implementation. It is feature-rich and customizable. But it has some rendering bugs, much slower than JEdit version, amount of code is too big to extend it yourself and it linked a lot to other SwingX packages.

NetBeans
As Tim Boudreau told us, NetBeans only recently got a good implementation of TreeTable. And this implementation looks great! It works almost as fast as JEdit one, has no rendering bugs, needs only few classes to build it (but not all the framework as previous two implementations) and it's easy to use and customize. But one more problem - you may use it only under either GPL2 or CDDL, and you need to download NetBeans sources and copy org.netbeans.swing.outline package to your project to use it.

All of them extends JTable. I think it's not good, JTable is the biggest class I have ever seen, about 9000 lines of code, and SwingX implementation adds another 4000 lines. It is hard to debug and hard to customize to internals. Swing is so big because backward compatibility, but what sense of JTable compatibility for totally new component? How do you think, may be it is time to write Tree, Table and TreeTable LGPL implementation by ourselves using best practices from core swing, SwingX, JEdit and NetBeans?
2008-10-07
Comparing two collections
There is standard task when you have GUI table and database table, and you need to merge differences.
Most of people I know will do it like this:
Set source; // set of records from UI
Set target; // set of records in database
for (Object o : source) {
// if we have object in source without
// same object in target - it was added by user:
if (!target.contains(o)) {
target.add(o);
}
}
Iterator iterator = target.iterator();
while (iterator.hasNext()) {
Object o = iterator.next();
// if we have object in target without
// same object in source - it was removed by user:
if (!source.contains(o)) {
iterator.remove();
}
}
We have 2 full collection iterations. In most cases it will not cause big performance issue. But it looks bad and will cause performance problems with slow Collection implementations or with big amounts of data.
After using my brain few minutes I found the best way of comparing, with only one iteration:
Set source; // set of records from UI
Set target; // set of records in database
// just checking:
if (target.equals(source)) {
return;
}
Iterator iterator = target.iterator();
while (iterator.hasNext()) {
Object o = iterator.next();
if (source.contains(o)) {
// remove all checked objects for future
source.remove(o);
}
else {
// if source does not contains object -
// it was removed by user, removing it from target:
iterator.remove();
}
}
// all object left in source are added by user.
// Adding them to target:
target.addAll(source);
Simple enough, isn't it?
2008-08-15
KDE for Windows
KDE 4.1 is here, and windows.kde.org packed it for Win32 already. As long as there are lots of useful apps in KDE without good win32 alternatives - I installed it on my working XP machine.
While Amarok is still in deep alpha - I couldn't start it. But there are two apps I can't live without - KWrite and Kompare. Both of them have great user interface, and gives you all advanced possibilities you can imagine. There is no other free editor to support about 90 different source file types and full encoding support, with possibility to open file with one encoding and to save with any other. There is no good file comparition program with such pretty and usable interface as Kompare. If you are interested - give it a try!
I am still waiting for Krusader and Okular, but my life under windows is already much simpler.
Security circus
In big outsourcing offices there are lots of security policies, and most of them are stupid enough. Don't you think so?
On my current job there is policy to change passwords every 3 weeks. What for? My first password was something like "R00mpel$htit$hen", while all the next password are "Anykey1", "Anykey2", ..., "AnykeyN". Same for all guys in my team. So, is office security much stronger now?
2008-08-05
Java5 forever or Codename: No Future
Java6 exists almost two years now, and Java5 "is in its Java Technology End of Life (EOL) transition period". While I admire people, using top versions of Sun's Java, there are lots of folks, who are still using Java5. All of them have different reasons: someone just don't want to bother saying "Why should I?", someone have some strange compatibility or porting problems. Someone saying about business, about cost of migrating from Java5 to Java6.
But how long your project will exist on Java5? Year or two? You spent your money on your project, do you really want to join it's lifetime with Java5 lifetime?
Let me explain. You have project, you have N services and X users. If your organization has no evolution - everything is just fine. But if your project grows - you have N = N + 1 services and X = X + 50 users each half-year. Once your current hardware will not be enough, you will move to better hardware. On better hardware you will have new operating system that supports all your hardware (for example, Windows 2003 Server supports only 4 CPUs/CPU kernels). And what if there will be no Java5 for that operating system? Sun is not supporting Java3, Java4 and soon Java5 anymore, who will care about your problems and your needs? Red Hat? Or Microsoft? Currently, there is even no possibility to download Java3 directly from Sun, or there is no Java4 for x86_64 platform. Do you want to make your business on zombie products?
Sun gives you the best platform of our times. Sun gives you standards, public APIs, open and flexible platform. Sun gives you own implementation of it's platform, saying there are lots of them around. Sun also guarantee backward compatibility (Java4-Java5 is another step, I am talking only about Java5-Java6 now), and only possible compatibility problem - usage of sun.** API. But even here Sun gave you compiler warning: "sun.** is Sun proprietary API and may be removed in a future release", and it's some king of mental retardation to ignore warnings like this.
So, as for me - if you can't move from Java5 to Java6 - your project is dead, and you is guilty in its death, no matter how long will it take to make it smell like old corpse.
Subscribe to:
Posts (Atom)