Category: Java

  • Parser- und CST-Generator verfügbar

    Den Rest des Tages habe ich auf nerdischere Art und Weise genutzt und meinen Parser- und Syntaxbaumgenerator MetaGen in einen präsentablen Zustand gebracht. Es gibt ein Beispiel für die Auswertung einfacher algebraischer Ausdrücke und ein hübsches Tutorial am Beispiel einer Konfigurationsdatei. Das Ding erzeugt Java Quelltext und der erzeugte Code benötigt die antlr Laufzeitumgebung.

  • Top four Java Problems

    * The literal syntax is much too meagre. Ther is no Map, no Collection, no List, no multiline String, no expression substitution in Strings. * The standard libraries provide poor abstractions and little convenience. * There is no clean systax for block closures. * It’s statically typed without providing proper generics or some kind of…

  • Broken Java

    This morning I had to write the code to initialize a field to one year before today. It was *four* lines. And it is not type safe, but using magic int constants.

  • Java Quiz

    Suche elegante Möglcihkeit das untenstehende Idiom in generischer Form zu implementieren, da ich insbesondere das put gerne vergesse. Any Ideas? map = ….; //probably a loop here: key = ….; Element element; if (map.containsKey(key)){ element=(Element)map.get(key); } else{ element=new Element(); map.put(key,element); } //work with element

  • Beyond Java

    After my recent post about the advent of the sunset of java I’ve read Bruce Tate’s “Beyond Java”, which seems to fall into line with my argument. What I did particularly like about the book was the statement that Java is a language for system programming (which cached in on a lot of shortcomings of…

  • Commons Collections

    Today I had a glance at commons collections. I’m convinced, that the more mature parts of the commons are what sun forgot about. If you know and use them you’ve definitely got a competive advantage. But now for the code: public class CollectionsDemo { public static void main(String[] args) { List list= Arrays.asList(new String[]{“Hund”,”Katze”,”Huhn”}); List…

  • Exit mit throw statt return

    Wie hier schon zu lesen war bin ich ein großer Freund der Exception, auch als Kontrollstruktur (für den Ausnahmefall). Eben hatte ich wieder so einen Fall, in dem ich besser eine Exception geschmissen hätte ,statt mit false zu “returnen.” Das ging etwa so: public boolean myOperation(){ if (!preconCheck1){ log(“precon 1 failed”) return false; } if…

  • Stilfrage

    Ich habe folgende drei Variante einer Methode implementiert und hatte einen erbitterten Streit, welche denn die klarste und wartungsfreundlichste sei. Daher würde ich gerne mal wissen, wie Ihr das seht. Also kommentiert recht eifrig! Variante 1 private void updateActions(){ boolean kundeSelected = kundenAuswahl.getSelection()!=null; removeKunde.setEnabled(kundeSelected); } Variante 1a private void updateActions(){ removeKunde.setEnabled(kundenAuswahl.getSelection()!=null); } Variante 2 private…

  • Velocity Alternative

    Da bin ich gerade drübergestolpert: StringTemplate Sieht sehr interessant aus, für die Freunde der Codegenerierung…

  • Lokale Funktionen vs. Method To Object Refactoring

    Erinnert sich noch jemand, dass man im seligen Pascal Funktionen und Porzeduren lokal innerhalb von Funktionen definieren konnte? Ich habe gerade den Eindruck, dass das bei bestimmten Problemen (Transformationen von Objektstrukturen) ein ganz nützliches Instrument ist oder wäre, da ja heute Java Werkzeug der Wahl ist. Eine eigene Klasse erscheint mir manchmal zu heavy-weight. Ansonsten…