Pages

2008-09-25

Delphi for Java developers

Why is there no book titled Delphi for Java developers?

I guess I'm not the only software engineer who has been forced to learn Delphi after Java. The reason is of course not that the company I'm working for at the moment is moving to Delphi, but rather that they have some programs written in Delphi that still needs maintenance.
Learning Delphi after Java give some interesting insights into programming language design. After I started to learn Delphi, I've started to appreciate Java more and more, just because Java is so clean and so simple. I've also started to see that language features that sounds nice when you first hear of them, can turn out to create really hard-to-read code. Here are some examples I'd like to mention:
  •  the with statement in Delphi. The with statement can save you for some typing, and could even make your code look a little more elegant, however, it's one of the features that makes Delphi code harder to read. (BTW: Here is something that you can do to make your code a little more elegant, and even save yourself some typing, hopefully without making it hard to read.) 
  • Another feature that Java "lacks" is global variables. (OK, I admit, when I was younger, I couldn't understand why people whined about global variables. Having to read and understand others peoples global variables really helps a lot on that understanding..)
  • You don't need parenthesis after function/method calls if you're not passing parameters. In Delphi it's not necessary to include parenthesis after a function or method call, if there is no parameters. Seems like it's not even laziness, but rather considered best practice. Sounds smart, but at least for my eyes, it isn't obvious that "SomeMethod" is a method call.
  • More than one public class can be defined inside a Delphi "Unit" (a Delphi source code file) . Even worse, the intefaces of the contained classes are at the top of the file, and the methods that makes the rest of the class can even be mixed at the bottom of the "Unit". Of course I guess mixing implementations is bad style, but guess what: If bad style compiles, chances are somebody is going to introduce it.
  • To make things even worse, Delphi doesn't have package trees or wildcard imports, so it's even more tempting to put many classes into one unit.
  • The Delphi IDE (of earlier versions) is composed of many top-level windows, instead of a main form. Today I heard someone talking about this as one of the features of older Delphi versions, but I clearly disagree. It is however better than gimp's interface in that if you activate one Delphi window, the rest of them are also activated.
For Delphi hackers who might read this: I guess my views are heavily influenced by the fact that I learnt Java first. If I've written something wrong, please write a comment about it, or even better: write a follow-up on your blog, cause I'm trying to learn Delphi, and I know there must be some reason why so many programs are written in Delphi, except for the speed.
Btw: Here is some interesting Delphi links I found a while ago:

2008-09-24

Another anti-virus solution

Tried vipre yesterday on a customer pc. After a 6 minute scan it found and removed the trojan (TDSServ) that neither spybot, trend or avg managed to remove. I think it is the worst trojan I've seen so far, hiding from the Windows API, redirecting requests for security related domains to various other domains, including, if I remember correctly, qxl.no and thefreedictionary.com (instead of the usual spam search engines and spam portals). So I had to read every security site through the google cache, or from another computer. :) The reason I found vipre? Sunbelt software had posted research materials mentioning the specific trojan on their web site. I guess there is a lesson for everyone who's thinking about seo here: go ahead, post relevant stuff on your webpage. It has a strange way of attracting readers that is actually interested in the stuff you sell. After finishing the job, I bought a license, even though the trial version had fixed the problem. I guess 30$ is cheap for avoiding all the hassle with hijackthis etc, etc and going home early.

2008-09-21

About Java, closures and attracting new developers, part II

(Warning: A web developers perspective.) I've been thinking of this since I wrote the post: About Java, closures and attracting new developers, where I tried to prove that the problem with Java is not related to the lack of closures. At the risk of offending the rest of you, here comes my explanation of why I don't use Java for my spare time projects, even if I like it.
  • The web server (I mostly use tomcat 6 at work) takes to long time to restart, so long time that it quickly becomes painful, especially when you add to this that:
  • you have to restart it every time you've changed a class.
  • The recommended web framework, JSF (JavaServer Faces) doesn't care about URLs. By default it will show the URL from the last page you visited.
  • JSF has a really unnecessarily complicated template language. I mean, I can't see the reason for having to use <h:panelgrid> when what you wanted is just <table>. Not to mention that there is no <div> tag in the default component set. Of course, you can just use a component set that has one, (or make your own if you have a couple of hours to spend,) but I guess you see my point.
  • JSF messes around with my id's, even if I've not asked it to do that. To get around that limitation you once again has to use a different component set (tomahawk comes to mind).
  • You don't have access to the javascript that is used. Of course this is touted as a benefit of using JSF, but in my opinion it's just a horrible violation of the rule about separation of concerns. What happens is that you can't just include that standard well-tested javascript library you want, which means you have to use jsf components again. And guess what: Those components are broken, and it always ends up with a lot of extra work for the designer.
  • And of course: JSF isn't the only problem with Java. Take something as simple as how to print a line of text to the console: "System.out.println()", or think about trying to open a file for reading. With execuse to every swede who reads this, we have a childish joke here in Norway that goes like this "How many swedes do you need to change a light bulb?" The answer is 1000, one to hold the bulb, and 999 to turn the house around. Same goes for Java, - how many objects do you need to read a file line by line? Or to resize a picture? (Yes, I know Fabrizio Giudici has tried to defend it, but I do not agree. Often, the Java API's seems way to low level, and my feelig is that sometimes you have to use one factory class on top of another. Also see next point on why this is more of a problem than it could have been.)
  • The documentation is also painfully unbalanced: There is a lot of javadoc generated API documentation everywhere, but I can't think of a single place to find something like askeet, -a well thought out demonstration of how to use the api or framework your're providing. (OK. I can remember to have seen som interesting blog posts over at http://weblogs.java.net. Example.)
But yes, I still use Java at work. And I still think Java is a great language, and a great platform. It just lacks a good, full stack web framework with great documentation, running on a fast server that doesn't need to be restarted many times an hour. (Edited: 2008-09-30)

Updated 2008-12-14: Symfony has done it again! More documentation available here: http://www.symfony-project.org/jobeet/1_2/Propel/en/

2008-09-11

A really great time logger

Are you already using KDE? If so, you're in luck, cause the best time logger I've ever seen has been available on KDE for years.

Karm (forget about the name, it's a KDE thing that almost every name starts with a K) logs the time you spend on each virtual desktop. Just place all programs related to each project on a separate desktop, and all private stuff (like instant messenger, gmail etc) on the last one. Then set up Karm to track time on the different desktops to the projects.

Also, if you leave the computer for more than a few minutes, when you come back, Karm will ask you if you want to include the time since last activity or not.

Just one more reason why I like Linux, and KDE in particular.

2008-09-05

Update: Ubuntu on GIGABYTE ga-73pvm-s2h


Earlier this year I installed a new computer with Silverstone SST-LC17 case, GIGABYTE ga-73pvm-s2h mainboard, 4 GB RAM and Intel Core 2 processor. The power supply was a Fortron Source Zen 300W. The computer was built from a recommendation from hardware.no, who also suggested that the pc should work with mythbuntu. After I've testet it, my conclusion is that it will need a better power supply. You can read more about the experience here.


I've now upgraded the machine to Ubuntu Hardy, and I'm happy to say that it was an even better experience this time, as sound worked out of the box to.


However I stil had to install Nvidea drives manually. Envy was still installed from last time, but the old version wouldn't work with Hardy. A quick search revealed that there's a new version of envy, named envyng, and that the new version has even made it into the ubuntu multiverse repository. Before I removed the old envy, I used it to remove the old Nvidea drivers. Installing the new envyng is just a matter of running sudo apt-get install envyng-gtk . (There is a qt version too, but installing that meant downloading more libraries so I chose the gtk version.)


Now, I'm struggling with getting kvm-based virtual hosts to run behind a bridged interface on this machine, as it's my personal server, camuflaged as HTPC to increase WAF : )


Hope this helps, and again, big thanks goes to everyone who blogs about technical stuff! (Oh, btw, if you know how to make kvm work with bridging on hardy heron, please post a comment here  with a link : )