lunedì, febbraio 19, 2007

Code Gallery: defensive coding!

Nothing frights more a developer than a NPE! A C# reporting app, period: year 2007:
public AReport generateReport(...)
{
    //do somethig
    AReport report= new AReport(...);
    if ( report != null )
    {
      return report;
    }
    else
    {
      return null; //!!!!
    }
}
Comment: how to smartly avoid a (brrr!) feared NPE! Here's the clever algorithm, stated after long mumble numble the author:
1- instantiate an object with a new Something()
2- don't rely on "new"! what if it doesn't work? (what if the moon crashes on hearth, I'd reply...)
3- test the newly instantiated object: is it null?
4- if yes... That's the unexpected case, I think! our man had to be in real trouble: what to do NOW? Here comes the artist touch and sensibility, if it is null... well... simply... return null!

A great little cameo: how to look busy and fill of dust a 3 lines method.

mercoledì, febbraio 14, 2007

Fisica dello stato solido al Politecnico

Io mi sono laureato al Politecnico di Torino nel 1999. Oggi, dopo ben 8 anni, mi è capitato di entrarci di nuovo, da un ingresso un po' laterale, di quello che pochi usano. E' ho scoperto che il cartello misterioso, che tante domande ha sollevato è ancora lì. Qualcuno sa dare qualche significato?

Jug Torino Meeting 21 - febb - 2007

La prossima settimana tengo un seminario al meeting mensile del JugTorino!
Tutti dettagli qui e qui sotto il programma:


JugTorino Meeting
21 - febbraio - 2007


Presso CSP SpA Corso Svizzera 185, 10149, Torino
Fabbricato 1, Scala H, 2° Piano


PROGRAMMA:

h18:30 Check-In

h18:45 JugTO Quickie:UML for Dummies
Impara a leggere e scrivere class e sequence diagram in pochi minuti!
Bruno Bossola, JUGTorino

h19:00 JugTO Hands-On: Design Patterns by Examples: il Decorator
Come aggiungere comportamenti e responsabilità alle classi esistenti senza modificarle. Entriamo nel JugTO Lounge Bar per fare pratica!
Domenico Ventura, JUGTorino

h20:00 JugTO Pizzata!

INFO:
http://www.jugtorino.it/vqwiki/jsp/Wiki?MeetingFebbraio2007
meetingfebbraio@jugtorino.it

lunedì, febbraio 12, 2007

lunedì, febbraio 05, 2007

Code Gallery: create and destroy

Known as "stable" code, a so called J2EE web application, period: year 2005:

//used in the creation of some kind report
public void shiftColumn(...)
{
    //do somethig
    if ( isBlankCell(table, row, srcCol) )
    {
      cell = row.createCell((short) destCol);
      row.removeCell(cell);
    }
    //do somethig else
}


Comment: a great example of coding for obfuscation, which states: "never ever will you clearly express your intention through code".
Why creating a new cell and destroying it the line after? And why that subtle test, which checks for srcCol, but creates a new cell at destCol? The artist leaves us slightly dazed and confused, while thinking of his wisdom.

giovedì, febbraio 01, 2007

Code Gallery: error messages

Production code, unknown artist, VB school, period: beginning of 2000th:

Public Function getGridURL(...,ByVal values As xxx,...) As String
    Dim url As String
    -- Do some stuff
    If values Is Nothing Then

        url = "ERRORE PIRLA" -- italian for "FUCKING ERROR"
    Else
        --Do other stuff
    End If
    Return url
End Function

Comment: a little masterpiece for its conciseness, the clean stroke and the ability to crash the whole application.

Il Cardinale Poletto

Ecco uno splendido campionario delle posizioni della chiesa cattolica. Difficile capire in quale mondo vivono (non su questo sicuramente):
Articolo [La Stampa]