famo.us
Web Components
Hardware Hacking
Properties are always accessed via method calls on their owning object. For readable properties there will be a getter method to read the property value. For writable properties there will be a setter method to allow the property value to be updated.
Java BeansSpec (08.08.1997)
These three sentences have done something weired to my brain. The somehow completely rewired my brain to believe that every method that starts with get means Getter. And this comes with a price: I usually expect a getter to be an O(1) operation. I expect it to be the same three bytecode sequence that is a simple field access and a return. Nothing more. The same goes for a method that starts with set. I don’t expect them to throw exceptions, I don’t expect them to talk to the filesystem or to the network. Just a simple field access, nothing more.
And I am not alone.
Most of the Java programmers are somehow hardwired to have this JavaBean asumption. So naming a method that does more than a simple get or a simple set to an object field should not be named get or set. If it creates something name it “create”, if it finds something name it “find”, if it stores something name it “store”. You get the idea. As I’m always on the reading side of code, I believe that the these naming conventions are quite good, but they are not only a convention on how to name something, but also a convetion on how to not name things. So if it is not a getter, do not name it get! When looking for alternatives, Stephen Colebourne did a nice collection on common prefixes in the Java world.
So, by now everybody got it: Code is there to be read by people, to be analyzed by people and to be understood by people. The fact that you can put it through a compiler and run it is a nice sideffect, but nothing to focus on. Besides writing readable tests of course.
But when software is growing and many different hands touch the same spots, it somehow gets dirty. So even when you have usually quite high coding standards, it still can happen that I stumble upon something like this:
User user = userService.createNewUser( email, password, false, true, null, 5 );
I like to be able to read a line of code like a line of text. Which means that I at least want to be able to get the “words” without the surrounding context.
So what would you be able to tell about the above snipplet? I would say: it apparently creates a new user, using some service and it requires an email and a password, which might be stored somewhere. And the point that makes me cry: apparently some magic flags, a nullable parameter and a magic number.
So lets see how we can clean this up with some new patterns. I usually make up my own names, if someone has a rather more common name for them feel free to comment, I will be happy to replace them.
Enum as Flag Pattern (aka do not use boolean literals)
enum FailIfExists { YES, NO }; enum NewPasswordChecks { YES, NO } User user = userService.createNewUser( email, password, FailIfExists.NO, NewPasswordChecks.YES, null, 5 );
So, what can you tell about the method call now. The problem of methods that react to flags aside, the readability is better. You at least can deduct now that there might be no error if the user already exists and that it uses the “new” password checks. It is even easier to refactor to use the third password validation algorithm should it ever be changed again.
When setting up a new project you might try to disallow all boolean literals in certain high level classes, I don’t know if it works that well with third party libraries. This might be a cool Checkstyle rule to try.
No nullable Parameters Pattern (aka keep your implementation details internal)
So what is my next problem? Well, the given null parameter value. I believe that the ability to cope with null values is an implementation detail that belongs in the class that defines a method. So the UserService interface should provide us with an overridden version createNewUser that does not have the fifth parameter. Then the implementation could hide the fact that this parameter is really nullable. And it avoids the clutter of methods that have n optional object parameters.
If you use Findbugs in combination with the great JSR 305 annotations, which by the way can be enforced using a Checkstyle plugin, you might try to disallow using the Nullable Annotation in public methods. Maybe even for protected methods. In any case, you should never have to use a null parameter while calling a visible method of another class.
No literals outside constant definitions (aka give names to your magic numbers)
The last thing is a classic, but there are still a couple of people who do not use constants instead of literals. I think the general rule is that you should never use a numeric literal inside a method, but always a class declared constant. Furthermore this might even be extended to be valid for String literals and as told in the first point to boolean literals.
So let’s revisit my short (and bad) example taking the above mentioned points into consideration:
enum FailIfExists { YES, NO }; enum NewPasswordChecks { YES, NO } private static final int INITIAL_NUMBER_OF_INVITES = 5; User user = userService.createNewUser( email, password, FailIfExists.NO, NewPasswordChecks.YES, INITIAL_NUMBER_OF_INVITES );
Given that you might see this lines of code during a review, where you can’t browse the complete source of your project, one might now be able to better understand what this method does: it creates a new user with the given email and passwords, succeeds even when the user already exists, uses some mythical new password check and gives him an initial number invites of five. This can be guessed by just reading code, without a single line of JavaDoc and even without once visiting the declaring class or interface.
So in future, when writing code, try to consider if you would understand your method calls without ever having seen the implementation or even the declaration of the called method.
Inspiriert durch die steigende Nutzung von Fitocracy und den dadurch quasi erreichten Zustand von Dauermuskelkater habe ich mich mal ein wenig zu Muskelkater umgesehen:
Fakt ist wohl das Muskelkater durch die Beschädigung der Muskelfasern durch die Belastung entsteht und nicht durch Milchsäure. Dabei liegen die Schmerzen wohl tatsächlich an entzündlichen Reaktionen auf diese Verletzungen. Dazu gibt es folgende Infos:
Metastudien:
Treatment and prevention of delayed onset muscle soreness
Delayed Onset Muscle Soreness Treatment Strategies and Performance Factors
Various Treatment Techniques on Signs and Symptoms of Delayed Onset Muscle Soreness
Hilft:
Sauerkirschsaft
Sauerkirschsaft ist wohl entzündungshemmend, daher gibt es eine Studie die wohl belegt das man bei regelmäßiger Einnahme vor, während, nach dem Sport weniger Muskelater bekommt: http://bjsm.bmj.com/content/40/8/679.abstract
Ascorbinsäure/ASS/Aspirin/Paracetamol etc.
Widersprüchlich, im Endeffekt schwächt wohl Paracetamol sowohl die schmerzen als auch den Effekt von Training ab, daher wohl eher nicht so zu empfehlen. An die Studie für Aspirin komme ich nicht dran, die ist aber auch von 1988 und das scheint jetzt nicht das silver Bullet gewesen zu sein.
Warmes Wasser
Oh wunder, warmes Wasser, also schön in die heiße Badewanne, hilft wohl: http://www.ncbi.nlm.nih.gov/pubmed/21681159
Hilf nicht:
Vitamin C:
Kann man ja mal ausprobieren, hilft aber nicht: http://www.ncbi.nlm.nih.gov/pubmed/16998453
Massagen und Stretching:
Hat alles keinen großen Einfluss, ist wohl beides wegen der zusätzlichen mechanischen Belastung eher schlecht.
Am Besten ist es übrigens gar keinen Muskelkater zu verursachen, bringt nämlich auch nix: Muscle damage and muscle remodeling: no pain, no gain?
Manchmal komme ich ja auf so Gedanken aus denen dann lustige Projekte entstehen. So ereignete es sich auch Mitte Oktober, als es im Pub um die allgegenwärtigen Hinz&Kunzt Verkäufer ging. Und daraus wird jetzt mein Novemberprojekt.
Im November gilt für mich folgende Regel:
Ich kaufe von jedem Verkäufer eine Hinz&Kunzt den ich an diesem Tag zum ersten mal sehe.
Das heißt: jeder Verkäufer im Supermarkt wird eine Zeitschrift an mich los. Jeder der mir eine anbietet wird auch eine an mich los. Ich bin mal echt gespannt wie viele ich am Ende des Monats habe.
Warum? Naja, zum einen ist das eine bescheuerte Idee, zum anderen geht es aber um Wahrnehmung. Es gibt so viel über das man normalerweise nicht mehr nachdenkt. Meine vegetarischen Monate führen immer dazu das ich mir Gedanken über Essen mache, was ich normalerweise auch nicht tue. Mein Hinz&Kunzt Projekt wird dazu führen das ich die Verkäufer mal wirklich “sehe”. Und vielleicht mache ich ja sogar Fotos und sammele meine Begegnungen. Auf jeden Fall freue ich mich auf das Projekt.
Ich komme ja im Moment immer auf so lustige Ideen, die dafür da sind um meine Grenzen auszutesten und einfach mal mehr Maß und Bewusstsein in das zu integrieren was einem doch manchmal einfach durch die Finger rinnt: den Alltag. Daher habe ich schon Anfang Oktober mal wieder einen “Milchmonat” eingelegt, also keinen Alkohol. Da ich solche Unterbrechungen meines normalen Verhaltens gerne maximiere habe ich dann direkt auch noch einen “Gemüsemonat” daraus gemacht, sprich kein Fleisch, diesmal sogar auch keinen Fisch. Ich bin eh der Meinung das man viel weniger Fleisch essen sollte, aus ethischen Gründen den Tieren gegenüber und seinen Mitmenschen, von denen doch viel zu viele immer noch hungern. Ich finde da sollte man eher schauen das man die Lebensmittelpreise auf ein Niveau bekommt so dass es Weltweit keine Probleme gibt. Dazu gehört auch Futtermittelproduktion zu reduzieren, erst recht sollte man Ackerfläche natürlich auch nicht als Lieferant für Biokraftstoffe nutzen. Aber ich schweife ab. Wie gesagt, wenn ich 2 von 12 Monaten kein Fleisch esse ist das immerhin schon mal ein Anfang.
Naja, auf jeden Fall habe ich mir dann gedacht das man ja auch mal ein richtiges Fasten in die Zeit legen sollte, da ich ja eh im Moment eher Gesund lebe ist das wohl die richtige Zeit. Also habe ich mal eine Woche Fasten eingelegt.
Entlastungstag
Am Samstag war also Entlastungstag angesagt, also quasi mal nichts schweres essen sondern nur Obst. Das war auch nicht so besonders schwer, da ich mir mit meinem ersten 15km Lauf den Appetit doch ziemlich versaut habe. Also gab es tatsächlich nur 3 Bananen, 2 Äpfel und 3 Birnen. Das war schon mal lecker.
1. Fastentag
War jetzt auch nicht so schwierig, war halt noch Sonntag. Zum Frühstück gab es leckeren Sauerkrautsaft (ich mag wirklich Sauerkraut) und dann später noch mal einen Gemüsesaft und etwas Gemüsebrühe. Abends im Rover war dann auch kein Problem, da kann man auch Kamillentee trinken.
2. Fastentag
Ich habe unglaublich schlecht geschlafen in der Nacht auf Montag, was auch ein wenig dazu geführt hat das ich den Tag über eher auf Wolken gegangen bin. Morgens gab es lecker Karottensaft, Mittags Tee und Abends wieder Brühe und Gemüsesaft. Im großen und ganzen fühle ich mich aber wohl, obwohl mein Magen doch auch komische Geräusche macht.
3. Fastentag
War auf jeden Fall der Tag wo das Fasten am wenigsten Spass gemacht hat. Am Montag war ich in der Mittagspause noch bei der Bank und bin freudig etwas rumgelaufen, am Dienstag war das schon eher sehr langweilig und hat auch keinen Spass gemacht. Richtig gut gefühlt habe ich mich auch nicht. Morgens gab es Tomatensaft und Abends Brühe, obwohl ich Abends auch Unterwegs war und mir einen Liter Apfelschorle reingetan habe. Aber wenn ich schon keine Pizza und kein Bier bekomme…
4. Fastentag
Der Mittwoch war dann schon wieder besser, lecker Karottensaft zum Frühstück, Mittags um den Isekanal spaziert, Abends Brühe und dann… schwimmen. Man soll ja seinen normalen Sport machen, also habe ich es tatsächlich auf 40 Kraul Bahnen gebracht. Insgesamt ging es aber an dem Tag auch besser und ich habe mich auch eher normal gefühlt. So richtig Hunger habe ich auch eher selten, es ist nur das ich einfach gerne Essen. Nicht umsonst habe ich mir am Dienstag auch endlich einen Qype Account zugelegt. Ich muss aber auch immer noch sagen das das wohl fürs erste das letzte mal war, soviel Spass macht das jetzt auch nicht. Gewichtsmäßig wirkt es sich übrigens auch kaum aus. Also wenn ich mich nicht am Freitag oder Samstag so gut wie seit Jahren fühle dann würde ich es auch eher als Effektfrei beschreiben.
5. Fastentag
Morgen gibt es einen Apfel, ich glaube das wird der beste Apfel meines Lebens. Und Suppe, das wird auch groß. Der 5. Tag ging eigentlich auch sehr gut, die Nacht ging halt gar nicht, ich habe nur 4 Stunden geschlafen, was aber auch am Schwimmen und dem kleinen Mittagsschlaf davor lag. Im großen und ganzen siegt aber gerade die Erleichterung das ich das durchgezogen habe und ab morgen wird dann langsam wieder aufgebaut. Yay, Fasten bestanden!
1. Aufbautag
Endlich vorbei. Zum Frühstück gab es einen Apfel, der obwohl er hart und sauer war einfach mal die Erlösung mit sich brachte. Mittags dann Suppe und Abends auch. Im großen und ganzen bin ich damit wiede fit und auch der Hunger geht langsam weg. Mein Gewicht ist doch noch etwas gefallen, mal sehen. Das “wie neu geboren” Gefühl hat sich aber jetzt noch nicht wirklich eingestellt. Morgen werden Bäume gefällt und auch wieder normal gegessen, mal sehen was so der nachhaltige Effekt ist.
Ich werde das aber bestimmt nicht so schnell wieder tun, einmal alle 30 Jahre reicht.
Today I found out that use.perl.org is shutting down, or at least it is not accepting any new posts anymore. As I had my first blog on use.perl.org I wanted to preserve the data. This was quite easy as I just had to enhance a little script that I found on perlmonks.org in order to export the text of the use.perl.org entries to create an RSS file which I just imported here. Thus my blog history now starts in September 2003, which is more than 8 years ago.
The code is here:
Heute habe ich es tatsächlich mal geschafft bei der HH.js Vorbeizuschauen, das hatte ich irgendwie das ganze Jahr schon mal vor, ist aber bis jetzt nicht wirklich passiert da ich irgendwie nie Zeit hatte. Heute fand das Ganze in den Räumlichkeiten von Bigpoint statt, die Jungs haben auch ein schönes Büro und klingen auch ganz nett. Der @scheffield war mit und den @heshist haben wir da getroffen.
Erstmal gab es einen HTML 5 Appcache Vortrag von Peter Kröner (@sir_pepe), der war sehr gut und sehr schnell und hatte eine angenehme Informationsdichte. Das einzige was ich mitgenommen habe ist aber das man wohl noch viel tun muss damit das läuft und das ich mir mal jStorage anschauen muss.
Danach ging es mit Meno Abels über lauter kranken kram den man mit JS machen kann wenn man ein Konferenz-WLAN baut, den kram hat er auf seinem Github account (https://github.com/mabels).
Haymo Meran hat kurz was über den Aloha Editor erzählt, der wohl die sane Variante von “contentEditable” ist, indem er die ganzen Dom-Operationen selber macht. Wirkt zumindest besser als alles was ich bis jetzt da draußen gesehen habe.
Dann gab es noch ein Roundup zur jsconf.eu, wo eigentlich alle Vorträge mal zusammengefasst wurde. Folgende Puntke waren für mich interessant:
Habe mein Blog mal aufgeräumt, ich muss ja nächsten Monat mein Projekt irgendwo festhalten. Daher ist das jetzt hier schöner und ohne den Twitter kram und so.
Ende Oktober sollte es dann kompilieren, ich muss noch ein wenig an dem Beispiel arbeiten 😉
public class ProjectCoinFinals { private final static Set primes = { 2, 7, 31, 127, 8191, 131071, 524287 }; private final static Map<String, Integer> wordCounter = new HashMap<>(); private final static Integer oneMillionDollar = 1_000_000; private final static byte aByte = (byte)0b00100001; public static void main( String... args ) { try (BufferedReader br = new BufferedReader(new FileReader(args[0])) { handleLine( br.readLine() ); } } private static void handleLine( final String line ) { switch (line) { case "foo": foo(); break; case "bar": bar(); break; } } private static void foo() { wordCounter["foo"] = wordCounter["foo"] == null ? 1 : wordCounter["foo"] + 1; } private static void bar() { wordCounter["bar"] = wordCounter["bar"] == null ? 1 : wordCounter["bar"] + 1; } }