2. Goldene Regeln

Wer größere Sachen schreibt, sollte diese Regeln kennen:

Whenever possible, steal code

Brooke’s law: Plan to throw one away, you will anyhow

If you lie to a computer, it will get you

Make it work first before you make it work fast

If you have too many special cases, you are doing it wrong

Get your data structures [classes] right first, and the rest of the program will write itself

When in doubt, use brute force

Wenn du es nicht auf Deutsch sagen kannst, kannst du es auch nicht programmieren

nach: Bentley, J. (1988), More Programming Pearls, Addison-Wesley

Noch ein paar mehr Zitate von Größen, die ich bemerkenswert finde:

If it doesn’t solve some fairly immediate need, it’s almost certainly over-designed. – Linus Torvalds (2004)

Projects promoting programming in “natural language” are intrinsically doomed to fail. – Edsger Dijkstra (1975)

Computer science still seems to be looking for the magic bullet that will cause people to write correct programs without having to think. Instead, we need to teach people how to think – Larry Wall (1999)

Indeed, pleasure has probably the main goal all along. But I hesitate to admit it, because computer scientists want to maintain their image as hard-working individuals who deserve high salaries. – Don Knuth

Rule: “You shouldn’t have to open up a black box and take it apart to find out you’ve been pushing the wrong buttons!” Corollary: “Every black box should have at least TWO blinking lights: Paper Jam and Service Required (or equivalent).” – Steven Majewski

You need to realize that your system is just going to be a module in some bigger system to come, and so you have to be part of something else, and it’s a bit of a way of life. – Tim Berners-Lee

You write a great program, regardless of language, by redoing it over & over & over & over, until your fingers bleed and your soul is drained. But if you tell newbies that, they might decide to go off and do something sensible, like bomb defusing – Tim Peters

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. – Brian Kernighan

If you can’t do a first version in six months with a team of six people it is a sign that you don’t really know what you want. – Jack Diederich (2006)

But it could all be Quatsch, Quatsch mit Soße – Robert Weinberg (2006)

It’s hard to make a mistake by having too many short and simple functions. And much too easy to make them when you have too few – Thomas Bartkus (2006)

Schöner Code

Manche dieser Regeln kennen wir schon aus Python, andere sind dort nicht nötig, weil sie sich von selbst ergeben. So oder ähnlich möchte man das aber in jeder Programmiersprache haben, ob nun Maschinensprache oder Prolog.

  • “Indentation” (Syntax-sensitive Editoren, verschiedene Stile, Konsistenz)
  • Variablennamen (Aussagekräftig und nicht zu lang, user_input vs. userInput – jedenfalls kleinschreiben, Makros immer groß) – es gibt eine Philosophie, die vorschreiben möchte, dass aus dem Namen einer Variable ihr Typ hervorgehen soll. Das ist Unfug: Wer Code schreibt, in dem die Deklaration nicht ohnehin sehr schnell gefunden werden kann, hat mit oder ohne eine solche Konvention verloren, alle anderen können den Typ an der Deklaration erkennen
  • Kommentare (old-style vs. new-style, am besten an jedem Funktionskopf strukturiert und an kritischen Stellen in der Funktion, Embedded Documentation, Synchronisation mit Code)
  • Factoring (Funktionen i.d.R. kürzer als 20 Zeilen, sinnvolle Aufspaltung des Quelltexts in Module, Information Hiding)


Markus Demleitner

Copyright Notice