2007-12-18

How not to use static class members

Recently I came across a new experience which I consider a good example of "How not to use static class members".

Static class members are members (attributes and methods) which are shared between all instances of a class.

I.e.: If one instance changes the value of a static attribute, all other instances know this new value immediately.

Static members -particularly attributes- are shurely useful for configuration purposes, where all instances share a really really common knowledge with each other.

Static members are also indeed necessary for patterns like Singleton or Factory.

They are absolutely necessary to declare constants.

BUT: Static members are fatal if their usage include a runtime aspect.

I experienced that, when I inherited some code which extended the JUnit Framework to do validation on a loaded Model. Each validation was declared as test method of a so called "ValidationCase". As JUnit implicitly creates new instances for each test method to be called as test case.
So when running a specific test class, there are a bunch of instances of this class. For the validation now they had to share the model element to be tested.

The quick answer to this problem was: put it into a static member, all instances will know it then. Advantage: The location where these instances were created was inside the JUnit framework and didn't need to be touched.

BUT:
The error in this notion was: Not all instances of a test class share this model element. (As there are more model elements which are tested later and before by the same test class).

So the rule is: Only all instances of the test class which exist at a given time share this knowledge. At other times the share contains other information, shared by all instances actually existing then.

It worked well as long as only one model element was validated at a time.
The problem of this approach occured when once the validation system was extended to call a validation of one model element out of a validation of the other.

Now there were two groups of instances, one for element A, one for element B. But when B was under test, all instances shared the reference to B. And the reference to A was lost. Overwritten at a point in time.

Even this worked, as long as the validation of B happened to be the last action in the test of A, and the A reference was never needed afterwards.

But it was obvious that this card house once would collapse....

So: Everytime you introduce a static variable into a class, check carefully if its value is really valid for all instances of this class, even over time.
Avoid using static members out of well known pattern (like constants, Singleton, Factory ...).

2007-11-08

Hacker's Emblem

So since today you find a new simple little logo on this site:

hacker emblem

What is it? What is it about?
Why do I display it here?

I will answer the last question first:
Because I am a software developer, grew up with Unix (and now Linux), saw the upcoming of the Internet and the Hacker culture (see also: History) and strongly sympathise with the paradigm of 'free' like used in 'free software'. This logo symbolises how I now understand life and society, perhaps also the universe and all the rest ;-) .

The other questions are well explained here:
The Hacker Emblem and The Emblem's FAQ

and in german:
Das Hacker Emblem und Häufig gestellte Fragen zum Glider
Daneben: Was ist ein Hacker? - leider sind andere vormals vorhandene deutsche Übersetzungen von ESR's Texten inzwischen nicht mehr verfügbar.

2007-10-12

(K)ubuntu und -studio und so....

So, nachdem ich damals mit Suse 6.3 und Debian 3.0 mit Linux in eine Pause gegangen bin, geht's jetzt mal wieder los. Warum?

Vier Gründe:
  • Vista kommt mir nicht auf die Platte, und da XP irgendwann doch mal ausläuft, muss ich schauen, was danach kommt. M$ ist es möglichst nicht!
  • Ich will mal endlich anfangen, mehr Musik auf meinem Rechner zu basteln, und Ubuntu hat mit der Studio-Version ja nun was passendes für mein Budget auf die Welt losgelassen.
  • Ich war durch meinen Unix-geleiteten Werdegang ja immer sehr Linux-affin, jetzt gehe ich also back to the roots.
  • ... äh ... hab ich vergessen. Setz einfach was ein ...

Nachdem ich Kubuntu nun ohne größere Probleme (nur mit einer durchwarteten Nacht) auf meinem PII 400 MHz mit 128 MB RAM laufen habe und das Dingen ganz locker meinen alten Epson Stylus 400 Printer und meinen HP PSC 1110 all-in-one angesprochen hat, fühlt es sich ganz gut an, das auch auf richtigen Rechnern zu installieren.

Demnächst wird es hier also ein paar Erlebnisberichte zu Linux in Rover's Camp geben.

2007-08-21

Freier Artikel



Dieser Artikel ist absichtlich frei und enthält lediglich Text der erklärt, dass dieser Artikel absichtlich frei ist und lediglich Text enthält, der dies erklärt und ansonsten leer wäre und wäre ansonsten leer

2007-03-20

DreamTimeException

Für Java-Kenner ...


[FATAL] Fatal system error: End of virtuality reached,
falling back to real world
StackTrace:
au.inhabit.DreamtimeExeption: Broken dreamtime
at Office
at 08:15
at Monday
aborigined by:
org.det.absent.VirtualityException
at org.det.Brain.dream() (Brain.human: 42)
at org.det.Me.awareness()(Me.human: 0)
caused by:
org.det.body.OutOfBrainException