Fehlerbehandlung ist doch quatsch

Da stöbert man durch die aktuellen Artikel auf Nachrichten-Seiten und schwupps wundert man sich über die Fehler in der Fehlerbehandlung die viele Programmierer gerne machen.

Auch wenn ich grundsätzlich natürlich verstehen kann warum man die Fehlerausgabe, in diesem Beispiel in PHP, aktiviert so ist doch immer die Frage warum auf dem Produktivsystem und nicht in einem “identischen” Testsystem (Also einem Testsystem mit der gleichen Version und fast identischen Konfiguration).

Denn allein dadurch lassen sich schon solche Probleme wie in dem verlinkten Artikel beschrieben sicher umgehen.

Aber noch viel schlimmer als die von dem Autor des Artikels begangenen Fehler finde ich persönlich die Empfehlungen und Anmerkungen in den Kommentaren. Das geht von der Bezeichnung des Autors als “Unwissenden” bis hin zum “Bashing” der gewählten Programmiersprache.

Dabei ist die Lösung für dieses Problem doch ganz simpel.

Wenn ich mit der Programmierung einer neuen Software anfange, dann gehört zu den wesentlichen Grundsatzüberlegungen doch sowieso die Frage:

Wie gehe ich mit Fehlern um?

Im Rahmen dieser Frage fange ich regelmäßig meine Projekte damit an eine für den expliziten Fall angemessene Fehlerbehandlung zu basteln.

Allgemein

Jeder Programmierer fängt irgendwann einmal klein an. Lernen ist im Leben das A und O. In der Programmierung lernt man häufig durch Fehler, aber eben auch in den meisten anderen Lebenslagen. So heißt doch der bekannte Spruch: “Aus Fehlern lernt man.”

Aber wie finden wir die Fehler in der Programmierung und vor allem wann finden wir diese?

Beispiel PHP

Da in dem oben erwähnten Artikel explizit von PHP die Rede ist und auch die Kommentare darauf abzielen, werde ich mich vorerst auch nur mit dieser Sprache auseinandersetzen.

Ich selbst habe damals mit PHP/HTML/CSS/JavaScript angefangen, vor allem da man schnell sichtbare Ergebnisse erhält. (Was vermutlich ganz nebenbei auch der Grund für das faible von vielen Neulingen für PHP sein könnte)

Meine ersten Webseiten hatten damals natürlich auch viele Fehler und auch heute mache ich durchaus nicht selten einen Fehler und so manchen von diesen habe ich eventuell auch bis heute nicht gefunden. (Wenn man einen Fehler nicht findet, existiert er dann überhaupt?)

Aber was machen wir mit Fehlern die man finden kann und wo lassen wir diese Ausgeben?

In PHP gibt es dafür eine relativ gelungene Lösung auch ohne die php.ini anzupassen so dass alle Fehler in den Error-Log geschrieben werden.  Denn diese Error-Log-Lösung ist bei den meisten Webhostern leider nicht so einfach, man hat häufig keinen Zugriff auf die Logs und wenn dann häufig nur auf Anfrage. Aber bevor ich mich über die Error-Log-Politik der Webhoster auslasse liefere ich doch lieber eine Lösung die unabhängig vom Hoster ist.

Das Stichwort in PHP lautet set_error_handler, denn diese kleine aber feine Funktion ermöglicht es dem Programmierer seine eigene Fehlerbehandlung für die meisten Laufzeitfehler zu entwickeln. Somit ist es möglich, selbst wenn kein Zugriff auf die PHP-Error-Logs besteht, eigene Error-Logs in Produktivsystemen zu erstellen, aber noch viel wichtiger lässt sich auf diese Weise in der Entwicklung auch die Ausgabe der Fehler optimieren.

Für eine Entwicklungsumgebung freut man sich vermutlich wenn die Fehler gesammelt an einer Stelle in dem genutzten Template erscheint, in einem Produktivsystem ist es wohl wünschenswerter in einer Datei. (Die gleiche Idee steckt übrigens hinter display_errors aber leider nicht so schön einfach anpassbar)

Auch das Übermitteln dieser Fehler an den Entwickler lässt sich damit sehr einfach realisieren. (Sofern man kein Mail-Limit durch den Hoster hat, oder der Entwickler eine eigene Error-Reporting-Möglichkeit, z.B. mittels Webseite, implementiert hat)

Außerdem lässt sich dies mittels einer einfachen Konfiguration (Dateibasiert, Datenbankbasiert, wie auch immer man Konfigurationen speichern mag) nach belieben einstellen, denn der Entwickler ist ab diesem Zeitpunkt Herr der Ausgabe.

Ist es nicht das was eigentlich wünschenswert ist? Der Entwickler der Software bestimmt wie die Fehler an wen übermittelt werden. Erinnert mich stark an die Variante die in vielen anderen Programmiersprachen ebenfalls genutzt wird. Ist PHP doch gar nicht der große böse Buhmann was das Debugging angeht?

Fazit

Ich persönlich bin der Ansicht, dass in keinem Fall die Programmiersprache dafür herhalten muss wenn die Programmierer sich einfach nicht genug auskennen.

Mit dieser Aussage spreche ich sowohl die Programmierer an die Hinweise übersehen und/oder ignorieren, als auch diejenigen die eine Programmiersprache schlechter reden als sie eigentlich ist. PHP kann viel und macht genau das was der Programmierer verlangt, wenn man sich damit auseinandersetzt. Aber das gleiche gilt auch für Java, C++, C# und jegliche anderen Programmiersprachen.

Auch wenn in vielen Programmiersprachen der Compiler schon die ersten Fehler findet, so ist es doch meist dem Entwickler überlassen wie er Laufzeitfehler behandelt.

PS

Falls jemand Interesse haben sollte, in einem meiner Projekte habe ich eine simple Variante der Fehlerbehandlung in PHP implementiert mittels set_error_handler. Zu finden ist diese online auf Github.

Education is not for free

Working for education… this is a joke a lot of countries actually practice. But it is not the governments fault entirely. Of course the government could say they would take more taxes and you would not have to pay for education individually but that is not the right way.

The right way is to get people who have had a life full of experience to tell others about it.

Tell children about the language you have used, tell children about the troubles you had. Tell them how to do your job better than you did… by telling them what you have learned.

Education is important.

Make a difference but educating those who cannot educate themselves. You do not need a masters degree to do that. You do not need to be called a professor to do that. What you need is to be human enough to help other humans, help the world.

Without education this entire civilization as we call it is going down. No education means no future. So start helping today, help in your own way.

Do not request payment to save the future of the entire human race. Educate whenever you can. Share your experience, share your thoughts. Not because you feel better but because you can help.

What a mess!

To put it simple:

The german educational system is a mess!

I am not just talking about the change from 13 years of school to 12, but I am also talking about the further education including university.

Right now I am in my second semester of business information systems(bis) and it seems like there might be some confusion on the teaching part of the branch of study.

The current students on my course of studies have to learn about 800 DIN A4 pages of business economics whereas the current students in business administration(BA), which represents the major of learning about business economics, have a summed up number of 18 pages to study. I am aware that my major is a combination of the two fields of computer engineering and business administration but it seems like the professors teaching the subjects actually are not. How can it be possible to make those who do basically two degrees at the same time learn about 45 times as much as those who just major in one degree, especially if the course I am talking about is their main focus during their time at university. This is sick.

Throughout my university and from peope at other universities, too, I have heard similar things on different subjects/courses. How is it possible that this is a fair and even competition.

A friend of mine just told about an hour ago that the university actually stated to try to clear up their majors by a certain degree, but it seems like they do not do that for every subject to the same amount. On the example shown above the average grades in business administration are at about the level of 2.1 which is fairly good, whereas the average grade of my field of studies is at about 4.0.

In my eyes this is not quite what it should be like. But well who decides such things? Not us, the students.

How does a computer learn?

Since I just recently bought the book OnIntelligence by Jeff Hawkins and have not really started reading, it seems to be about time to share some of my understanding of the learning patterns of the brain.

So far I have spent some thoughts on how a computer could learn, by learning I am also talking about recognizing patterns and taking these to predict future events or in a simple case words.

This simple case is where I always start off with since it does not seem to be to far away from the first things a human learns. Apart from walking, which I cannot use since I am missing some essential hardware. So understanding how the brain learns by understanding how it learns language would be a good approach.

The first time I thought about the learning process of the brain in computational terms was during my time in High School (well since I live in Germany: Gymnasium) as we had an in class discussion about the evolution of language and we also talked about how computers would be able to learn and if they would be at all.

My final solution on this looked at that time just the same that it does now. It even comes up with a way to predict the next words and it makes it clear why it is difficult for people who have learned a lot have a hard time learning new stuff.

The solution looks somewhat like storing every newly learned word in the memory (may be represented by a MySQL database) and connecting it to a number that represents the number of times the word was ever recognized, this number will be initialized to 0. Every time the word is read/heard after that, the number in the memory will be increased by 1 so if specific words come up more often they will be the first to be accessed. For example the word “hello” might be used most times, so upon creating a new sentence with a new person it might be considered to be an essential part of sentences.

The next step would be to link the words to other words within a sentence. This is probably a bit more difficult but can be done within databases. For each pair of words that was used by someone the AI (well programmed brain) would have to save a new connection between these words. So basically saving those two indexes of a database in another table.

Basically we have just tried to create a brain. So far it can only save words but not really speak any usefull sentence. There is one thing that people talking about an AI never really leave a comment on. Every human being, may it be a child or an adult, is being tought things. In the early years of our lives we even have a system to teach children to understand grammar and vocab. It might be in mathematics or in some language.

So to have a functional programmed brain, one will have to teach it. For human beings we spend about 10 years on education. So to get the same results we would need about 10 years of education to teach the programm about the same amount of things.

This is the main thing to think about. Once someone creates a programmed brain (it may or may not be based upon my model) we will have to teach it the basic things. Maybe it would be usefull to send them to school, although this might a bit weird for the other students.

This is what I think of how a computer learns. I hope some of you have come across some new ideas but I will now go ahead and read OnIntelligence to find out what thoughts Jeff Hawkings had on this topic.