- Designing CSS Buttons: Techniques and Resources
Schaltflächen nach Art des Hauses - Fedora 12: Installation von Software ohne Admin-Rechte möglich!
Oh mein Gott - SQL âGROUP BYâ? issue
Wie mache ich das mit der Preise Tabelle…
Schlagwort: Coding
Random Links #76
Eigentlich auf der w-jax, aber die Grippe hat mir einen Strich durch die Rechnung gemacht. Schweinerei!
- What I miss in Java
Closures, Type inference, Checked Exceptions - Can Java Be Saved?
Noch so ein Artikel. Auch nicht schlecht. - Why version control is important for solo developers
Klare Sache
Random Links #72
Sie sind zwar noch nicht zu sehen, aber ich glaube sie kommen bald. Zähne.
- Stop Commenting Your Code – You’re Just Confusing Things!
Starke Ansage, aber Kernaussage stimmt. - NoSQL-Konferenz in Berlin
Übersicht über aktuellen Status der nicht relationalen Datenbanken. - Mu
Eine JavaScript Library für Facebook.
Random Links #70
- Vim Recipes
Die Suchseite für alle Fragen zu Vi(m) - Eloquent JavaScript
Interaktives JavaScript Tutorial - How to Read Other People’s Code — and Why
Brillant!
Random Links #68
- 31 Days of Refactoring eBook
Die Blogserie jetzt als eBook. - The effect of adding new people to project teams
Hat schon Recht der Herr, aber wenn zu spät neues Personal hinzu kommt, bringt das nix. - Should languages be multi-lingual?
NEIN! Bitte nicht. Mich macht schon das “WENN()” im Excel immer total fertig. - Patch (Unix)
Unix Tools sind Spitzenklasse. Gibt’s da Überhaupt ein Windows Pendant?
Random Links #66
Jetzt ist doch tatsächlich aus dem schlanken, flinken Firefox ein langsames, speicherfressendes Ungetüm geworden. Aber es gibt ja Alternativen.
- Is commenting your code useless?
To comment or not to comment. Bin nicht ganz der Meinung des Autors, eher der des ersten Feedbacks. - Useful websites web developer should make use of
Teilweise gar nicht so schlechte Links. - Java Puzzlers on local variable initialization
Hmm. Interessant. Aber dann doch klar.
Random Links #64
- 10 Puzzle Websites to Sharpen Your Programming Skills
Schon wieder ein Link zu einem Artikel auf Six Revisions. Schon wieder klasse. - Sneaky Microsoft plug-in puts Firefox users at risk
Das ist eigentlich eh ein alter Hut, jetzt aber wieder aktuell. - Goodbye Shared Hosting, Welcome to the Cloud
Für mich momentan noch zu teuer …
Random Links #61
- Plan to write big software – and you have already lost
“Optimizing for your software project becoming big is the same as optimizing a car to hit a rock wall – you are optimizing for failure” – Schöner Satz - The problem with Gentoo
Ich würde “zuviel Aufwand” hinzufügen. - I Don’t Code in my Free Time
Mir sind ein paar Schmunzler ausgekommen …. - Mozilla Join Microsoft in Slamming Google Chrome Frame
Ich bin hin und her gerissen. Mal schauen wie sich Chrome Frame weiter entwickelt
Die verflixte Namensgebung
Den richtigen Namen zu finden ist wohl eine der schwierigsten Aufgaben überhaupt.
Doch das ist nicht wirklich was Neues, Steve McConnell hat schon 1993 in Code Complete geschrieben:
You can’t give a variable a name the way you give a dog a name – because it’s cute or it has a good sound. Unlike the dog and its name, which are different entities, a variable and a variable’s name are essentially the same thing.
..
The most important consideration in naming a variable is that the name fully and accurately describe the entity the variable represents.
Heute kam mir dann diese Frage in die Quere: how do you call this anti-pattern?
Und sofort ist mir ein Gestank (Neudeutsch: Code Smell) aufgefallen:
NotActive = !mytable.active;
Yups. Ein Bool der mit Not anfängt. Sicher, ist noch immer besser als würde die Variable “X” getauft worden sein, aber besser als ganz schlecht ist noch lang nicht gut.
Und warum stinkt das jetzt?
Man muss um die Ecke denken. Wenn ich die Variable auf true setze, meine ich false. Wenn ich wissen will ob das Ding aktiv ist muss ich auf false prüfen.
Da kann dann solcher Code rauskommen:
if (!NotActive) DoSomething();
oder
if (NotActive == false) DoSomething();
oder ganz kreativ (alles schon gesehen)
if (NotActive) else DoSomething();
Kern des Problems ist das Not als Prefix im Variablennamen. Besser wär hier als Name z.B.: IsInactive.
if (!IsInActive) DoSomething();
Trotzdem ist auch das nicht optimal. Erstens weil trotzdem noch eine Verneinung drinnen ist und ich außerdem aus der Variable nicht erkennen kann was jetzt eigentlich (in)aktiv sein soll. Zweiteres hängt natürlich vom Kontext ab.
Viel leserlicher ist schon:
if (MenuItemIsActive) DoSomething();
Beim zweiten Codebrocken in der Frage wirds dann auch nicht besser:
control.enabled = !mytable.Enable_yes_no
Das _yes_no ist natürlich total überflüssig, ein reines “Enabled” liest sich eindeutig besser.
Darum sollte man bei Booleschen Variablen keinesfalls negative Namen verwenden, damit wird der Code unleserlich und vor allem unnötig kompliziert.
Random Links #54
- The Duct Tape Programmer
Uncle Bob’s Antwort auf Spolsky’s The Duct Tape Programmer - A Stick Figure Guide to the Advanced Encryption Standard (AES)
Comics sind super! Noch dazu wenn man was lernt. - Rails JSR286 portlets
Rails Apps in einem Java Portal. Gute Idee.