(P)Fund(s)stück der Woche

Eine Debugger-Object, daß scheinbar suizidgefährdet ist.


class Debugger{

[...]
	function runError($content,$typ){		
		
		 switch($typ){
		 	case E_USER_ERROR:
		 	 	unset($this);
		 		trigger_error($content, E_USER_ERROR);
		 		die();
		 		break;
		 	case E_USER_NOTICE:
		 		trigger_error($content, E_USER_NOTICE);
		 		break;
		 	case E_USER_WARNING:
		 		trigger_error($content, E_USER_WARNING);
		 		break;
		 	default:
		 		unset($this);
		 		trigger_error($content, E_USER_ERROR);
		 		die();
		 }
	}

}

Man nehme mal daß wir der Methode runError einen E_USER_ERROR (256) übergeben, schaun wir doch mal, was da passieren würde.

$deb = new $Debugger() ;
$deb->runError(‚die hard!‘,E_USER_ERROR);

Der switch findet ordnungsgemäß raus, das wir zum case-Block:E_USER_ERROR müssen und tötet sich erstmal selber … versucht es zumindest, denn im Falle eines Erfolges würde ja sonst das darauffolgende „trigger_error()“ nicht mehr ausgeführt werden.
Wird sie aber, da nur kurzzeitig das Object sich selber verliert dann sich aber seiner Existens wieder besinnt und wie befohlen einen Fehler wirft. In diesem Falle einen E_USER_ERROR was im Falle dieses Scriptes auch den Effekt des sofortigen Todes zur Folge hat.

Aber …
…sollte auch nur kleines Fünkchen Leben noch in dem Script selber stecken, wird mit dem anschließenden „die()“ auch garantiert, daß die komplette (jetzt schon tote) Ausführung auch wirklich beendet wird. Nachdem nun das Script zweimal gestorben ist, das erste zählen wir mal als mißglückten Suizidversuch, darf das Script dann wiederum ordnunggemäß aus dem switch springen und somit die Methode beenden.

Fein, alles tot (garantiert!!!) und fertig …

Ergo: Wenn du suizidgefährdete Klassen baust, sorge lieber „mehrfach“ dafür, daß sie nicht heile aus der Sache rauskommen!

so far – tucci

Why is programming fun?

Why is programming fun? What delights may its practioner expect as his reward?

First is the sheer joy of making things. As the child delights in his mud pie, so the adult enjoys building things, especially things of his own design. I think this delight must be an image of God’s delight in making things, a delight shown in the distinctness and newness of each leaf and each snowflake.

Second is the pleasure of making things that are useful to other people. Deep within, we want others to use our work and to find it helpful. In this respect the programming system is not essentially different from the child’s first clay pencil holder „for Daddy’s office.“

Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts and watching them work in subtle cycles, playing out the consequences of principles built in from the beginning. The programmed computer has all the fascination of the pinball machine or the jukebox mechanism, carried to the ultimate.

Fourth is the joy of always learning, which springs from the nonrepeating nature of the task. In one way or another the problem is ever new, and its solver learns something: sometimes practical, sometimes theoretical, and sometimes both.

Finally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. (…)

Yet the program construct, unlike the poet’s words, is real in the sense that it moves and works, producing visible outputs separately from the construct itself. It prints results, draws pictures, produces sounds, moves arms. The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be.

Programming then is fun because it gratifies creative longings built deep within us and delights sensibilities we have in common with all men.

Fred Brooks, The Mythical Man-Month, Herrscher des Brook’schen Gesetzes

Sowas hat man auch selten…

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# Internal Error (4A41564123414C4C530E4350500015), pid=5340, tid=1388
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode)
# An error report file with more information is saved as hs_err_pid5340.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#