Background

English

Integer handling in Java vs. Ada

18. March, 2008 • Jesper Dahl Nyerup

For those of you not in the loop, I attend a Diploma Programme in Computer Science in a school located in southern Denmark. The programming curriculum in the last couple of semesters have consisted mainly of courses in Java and Ada (and Spark, which, basically, is Ada with handcuffs).

Lately, I’ve grown more and more fond of Java, primarily for the following three reasons:

  1. The object (or class?) oriented paradigm suits me well, and this is very well implemented in Java.
  2. Sun’s Java API is as consistent and simple to use as it is vast and well documented.
  3. The garbage collection is brilliant and, as far as I have discovered, very well functioning.

But of course my fondness has a fly in the ointment. Java’s integer handling resembles those of many other programming languages, with the exception that the class Integer is a wrapper class for the primitive type int. But this particular area is, to say the least, ingeniously thought out in Ada, and I can’t help but miss this functionality when I’m coding in Java.

In Ada, creating a new integer-type with a delimited range for a specific purpose, is as simple as:

type My_Integer is new Integer range 26 .. 42;

And declaring an array with this new type as range, for instance, is even more trivial:

My_Array : array (My_Integer) of Some_Class;

This also works well with enumerated types:

type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

And, I assure you, doing the following declarations and assignments will very quickly become quite addictive:

Work_Day : constant array (Day) of Boolean :=
    (Mon .. Fri => True,
     others => False);

Consumed_Cups_Of_Coffee : array (Day) of Natural :=
    (Mon => 10,
     Tue .. Fri => 7,
     Sun => 2,
     others => 3);

This is an immensely powerful feature, and I didn’t know I missed it in other languages before I tried it in Ada.

I don’t presume to know how this would be implemented in Java. I realize that this cannot be accomplished, simply by being able to inherit from the class Integer, as this merely wraps around the int-type, and thus would lack an integer type delimited to the suitable range.

But then what? Solving this pickle would surely make a lot of code a lot more elegant and readable. Any ideas are more than welcome.

EnglishKommentarer (5)

KDE systray behaviour in XFCE-panel and FVWM

29. February, 2008 • Jesper Dahl Nyerup

Googling for a solution, I have come across many questions and only a few somewhat conclusive answers regarding this subject. Thus, I write this post in english, hoping that someone will be able to benefit from my experience.

I am pretty fond of the FVWM window manager, as it is fairly light weight and immensely flexible and configurable. On my laptop, however, I like having an omnipresent system panel, that keeps track of my battery state, wifi signal strength, email-notifier, and so on. I tried out »FVWM buttons«, but it doesn’t seem to be my thing. XFCE4-panel has so far been the answer, but lately an issue has been bugging me.

I use quite a few KDE applications on a regular basis, and some of them docks nicely in the systray, enabling me to ignore them when I’m not working directly with them. This doesn’t work with the systray in XFCE4-panel, when running in FVWM, though. Instead I get little windows with nothing but the systray icon. Annoying as hell.

Yesterday I came upon a little utility called stalonetray (stand-alone-tray). It is, as the name implies, a small systray that stands by it self, and my KDE applications actually docked in it!

Now, all that was left was to somehow persuade stalonetray to live in my XFCE4-panel instead of on its own. This was done fairly easy with two utils: XfApplet and gnome-swallow-applet. XfApplet enables the XFCE4-panel to hold gnome-applets, and gnome-swallow-applet easily “swallows” an application and puts it on the panel.

xfce4-panel
This works perfectly. The screenshot above shows my panel, when I’m working with KBluetooth, Kvpnc and Amarok (Hint: the -p-switch makes stalonetray use its parent as background, which makes it blend in pretty smooth).

My laptops is running Debian Testing, and the following debian packages (besides fvwm and xfce4-panel) were used to solve the problem:

  • xfapplet
  • gnome-swallow-applet
  • stalonetray

Feel free to post installation instructions for other distros.

EnglishSkriv kommentar

Sprog

Tidligere indlæg

Tjenester

Facebook Twitter LinkedIn LastFM Skype

Jesper Dahl Nyerup • Engbakken 10, Skuldelev, 4050 Skibby • Epost: jesper@dahlnyerup.dkXMPP: jesper@dahlnyerup.dk