An article on Cap&Design, about our filecentral
Look…I’m on the news
January 14th, 2008Unit testing with Javascript
September 28th, 2007I’m a big fan of unit testing. Everybody who has been working with me knows it. Unit testing makes you sleep well at night. If you have not understood the advantage of unit testing your code you should really try to do it!
Lately I’ve been working a lot with Javascript for obvious reasons. Ajax is very hype and if more and more websites require a deep knowledge of the Javascript secrets.
Javascript is not hard but some common mistakes can make your development a pain. Projects get larger and larger and you really need to have good tools to help you not having to pray every time you make a small change.
I will not try to convince you to test your code (maybe I will try in an other article) but I will show you a couple of tricks I use when testing my code.
To run the unit tests I use jsUnit which is a port of the famous jUnit. It is pretty simple to install and if you have used jUnit you basically know how to use it.
Javascript is a dynamic language. It means that you can change the prototype of an object after the object has been defined. That means that if you have an object for which a given method is defined, you can add methods on the fly. And you can do for only one instance or for all instances! Let’s give an example:
That was pretty easy and straightforward if you know the basic of object oriented Javascript.
The cool stuff is that you can use the dynamicity of Javascript to make your testing very simple. Mocking has never been easier!
Let’s make and example and test the following object:
The DiscountCalculator object has basically one method which is useful: discountPrice.
“getPrice” and “getDiscount” are two ajax calls that could be implemented with DWR or any other remoting technique. Since we want to run the test without a remote server providing some real values, we have to mock those calls.
Now, lets write our test. This is the specifiation of the test:
“If an item costs 100 and I get 10% discount I will pay 90”
Can you believe it? What I did is to simulate the two ajax calls by changing the prototype of the “discountCalculator” instance. I replaced the “complex” ajax calls with a simpler implementation that returns values which I can control. Do you remember “If an item costs 100 and I get 10% discount I will pay 90”? I just simulate the “if” part mocking my object.
That is pretty cool! To do that in java or in an other non dynamic language it would have needed a couple of other objects around…
Innebandy at Frescati Hallen (Stockholm)
September 28th, 2007Time is up! The innebandy season for Bandydos is beginning next week. If you are in Sweden and want to play innebandy (aka floorbal) please visit our site on playing innebandy in Stockholm
Teresa De Sio a Rotonda
August 13th, 2007So coold
July 10th, 2007I hade to give my dream of the “Svenska klassiker”. Last sunday I had to give up while swimming the Vansbrosimmning (3 km in open water). I was too slow and after 2 km I was forced to stop.
I really underestimate this race, what a pity.
1000 km
May 31st, 2007Today I reached 1000 km of bike training since 1st march! This was the goal I had in mind before the Vätternrunda, the 300 km race I will run in a couple of weeks.
Unfortunately today the weather was the worst weather I have ever biked in. It was not raining but the air was so humid that it felt like.
Vasaloppet 2007 (Öppet spår)
March 5th, 2007Il 25 febbraio ho partecipato al mio primo “Öppet spår”. L’Öppet spår, insieme alla Vasaloppet é una delle gare di sci da fondo amatoriale organizzate nell’ambito della “Vasaloppsveckan” (settimana della Vasaloppet).
Sia la Vasaloppet che l’Öppet Spår consistono in 90 km di fondo in tecnica classica (cioé é vietato usare il famoso passo pattinato e si procede con gli sci paralleli all’interno dei i binari tracciati per tutta la lunghezza del percorso tranne che, ovviamente, in salita).
L’Öppet spår si differenzia dalla Vasaloppet per la mancanza di professionisti ed é stata creata per venir fronte all’elevatissimo numero di sciatori che vogliono parteciparvi (ca 15.000 iscritti annui alla Vasaloppet, le cui iscrizioni chiudono anche 10 mesi prima della gara stessa, e circa 10.000 partecipanti all’Öppet Spår, ripartiti in due giorni)
Sveglia alle 4. Abbondante colazione a base di crusca e cereali e veloce sul pullman che mi ha portato alla partenza (Sälen). Alle 7.20 ero sugli sci pronto per partire, dopo aver riempito un sacco di plastica, fornito dall’organizzazione, con la giacca pesante e i vestiti che avevo indosso prima di partire per evitare di morire dal freddo.
I 90 km sono spezzettati da 9 posti “di controllo” dove viene servita acqua, bibite energetiche, pane dolce e sopratutto succo di mirtillo caldo, ricco di zuccheri necessari per portare a termine l’impresa. Il tutto con un organizzazione degna di merito.
Dopo 11 ore e 14 minuti arrivavo al traguardo. Prima di me molti altri ma molti anche dopo di me. Era quasi buio quando ero partito ed era ormai buio all’arrivo. Ero stanco ma felice.
Quando raccontavo a mia madre della mia avventura e quando le cercavo di spiegare il perché mi sia cimentato in una sfacchinata tale, mi é venuta in mente la Festa di Sant’Antonio che si celebra a Rotonda, il mio paese natale. Anche lí si passano ore ed ore a camminare in montagna, in nome del santo protettore; anche lí si parte qualche giorno prima e una serie di tavolate imbandite interrompe il pellegrinaggio; anche lí si mangia il pane dolce (u cucceddrato); anche lí si beve tutta una serie di bibite energetiche (u vino paisano)
jfokus 2007
January 30th, 2007Today I attended at jfokus, a conference on java and on its future now that Sun is moving to the open-source world.
I found most of the presentations of pretty low level and some of them of low quality. Maybe they just had to announce what kind of knowledge an attendant was supposed to have. Moreover, the names of the presentation was often misleading in my opinion.
As I suspected, the smoke which has been raised around the Rails/Ruby has also contaminated the java world with the jRuby stuff. But it is all smoke as I said and I can’t wait to see the moment in which the Rails phenomena will provide anything really useful to the business world.
A speech that I found interesting was the presentation of Spring web-services by Arjen Poutsma from Interface21.
Anyway, it was nice to be at the conference and be reminded that there is life out there in the programming World!
Vasaloppet here I come
January 28th, 2007Last week I finally had the opportunity to practise some cross country skiing. The snow has finally come to Stockholm and, altough not a lot, it was enough to let me go on a couple of trips. Check my training schedule on FunBeat
In about a month I will run for “öppet spår”, one of the cross country events part of the vasaloppet’s week.
MVC Expert på svenska!
January 23rd, 2007Infoflex har pubblicerat en ny sajt för att lansera våra MVC konsult-tjänsterna. Genom denna nya sajten kommer vi att erbjuda mentorskap, utveckling och drift av MVC applikationer baserat mest på Spring och Hibernate men också på Rails och andra teknologier.