IT: l’analisi indipendente

To err is human, but to really foul things up you need a computer.

– Paul Ehrlich

Come ci ha insegnato Steve McConnell sul suo Code Complete, le attività di costruzione di un progetto software dovrebbero essere condotte ordinatamente ed in modo completo per evitare gli ormai classici e famosi disastri, o anche quelli più vicini a casa nostra.

Con particolare riferimento alle prime fasi di un progetto informatico, si nota [Boehm – Papaccio – Understanding Software Costs] che maggiore è la distanza tra la fase progettuale in cui un difetto viene rilevato/identificato e la fase in cui viene determinato, cioè l’errore che c’è a monte e che ha prodotto il difetto, è esponenzialmente proporzionale al costo della risoluzione del difetto.

Quindi si deduce che le attività di studio di fattibilità ed analisi dei requisiti, sono le fasi le cui carenze pesano maggiormente sui costi finali dei progetti, anche informatici.

Oggi nessuno potrebbe pensare di affrontare la costruzione di un edificio che sia più complesso di un’aia per galline, senza un’opportuna fase di studio ed analisi. Eppure nel campo dell’informatica persiste ancora questa deprecabile abitudine.

Un modo che trovo possa essere efficace per rimuovere questo ostacolo è quello di autoregolamentarsi per eliminare il conflitto di interessi che oggi c’è tra analista e sviluppatore.

Oggi il tipico provider di soluzioni informatiche, piccolo o grande, offre lo studio di fattibilità, l’analsi, lo sviluppo e il collaudo della soluzione informatica; c’è un discreto conflitto di interessi nelle attività elencate, infatti:

  • quasi sempre lo studio di fattibilità indicherà che il progetto è fattibile e che proprio questo solution provider ha la soluzione
  • l’analisi mostrerà che la soluzione appropriata è quella che il solution provider ha già fornito anche ad altri clienti

Ovviamente non è affatto detto che le due affermazioni sopra siano sempre false né che siano sempre vere. Ciò che è vero è che spesso anche se il progetto fallisce, il solution provider è comunque e giustamente da pagare per il lavoro svolto.

Lo studio di fattibilità, l’analisi e specifica dei requisiti, così come la direzione dei lavori e il collaudo finale dell’applicazione informatica dovrebbero essere sempre condotti con un “capitolo di spesa” diverso da quello utilizzato per la produzione vera e propria della soluzione informatica.

Quindi un’organizzazione che ha a cuore l’efficacia dei suoi investimenti dovrebbe autoregolamentarsi in tal senso adottando un processo di acquisizione dei beni IT che comprenda:

  • lo studio di fattibilità
  • l’analisi dei requisiti e la loro specifica
  • la redazione di un capitolato di gara per l’assegnazione dei lavori e l’identificazione di un produttore di software adeguato sia sotto il profilo economico che qualitativo
  • la nomina di un responsabile per la direzione dei lavori e per il collaudo finale

Oggi quante organizzazioni hanno un processo di acquisizione di beni IT di questo tipo? E quante di quelle che spendono soldi pubblici possono dire di averci anche solo pensato alla formalizzazione di un processo strutturato di acquisizione? Purtroppo poche…

HOWTO: stream response with struts 2 that works in IE6

Web browser
Image via Wikipedia

Sometimes I had to display a dinamically generated file to the browser without save it locally on the server where I produce it.

HTTP allows you all of this, but browsers implemented the feature in different ways, so here I will report a method for sending a stream of binary data to a browser that works for every browser, in particular IE6.

The environment I use for this example is:

The struts.xml fragment for the action that rertieves the bytes and send them to the browser is as follows:

<action name="getFile" class="my.app.ExportFileAction" method="getFile">
    <result type="stream" name="success">
        <param name="contentType">${mimeType}</param>
        <param name="inputName">exportStream</param>
        <param name="contentDisposition">attachment; filename=${fileName}</param>
    </result>
</action>

The getFile() method of the my.app.ExportFileAction class is as follows:

public String getFile() {
  try {
    exportStream = new ByteArrayInputStream(getFileContent());
    mimeType = "application/pdf"; // in this example I use PDF mime
    fileName = "ExportedFile.pdf"; // the name we want to be proposed in the Save as... dialog
  } catch (Exception e) {
    return ERROR;
  }
  return SUCCESS;
}

exportStream, mimeType and fileName are members of my JavaBean Action class, each of which must have its getter and setter:

 protected String mimeType;
 protected String fileName;
 protected InputStream exportStream;

getFileContent() will be the method that retrieves the bytes of your file to send to the browser; here I will report only the method signature:

 private byte[] getFileContent() {}

HOWTO: JS triggered link showing a DIV with LightBox

 Questo articolo è disponibile anche in italiano.

To use Lightbox to display the content of a DIV instead of an image can be not so straightforward.
In my example, to obtain the desired effect, I used the scsLightbox  jQuery plug-in. This makes easier to interact with page elements.
Here are brief instruction on how to do it:

  1. Download jQuery and the scsLightbox plug-in
  2. Link in your page the jQuery script of the desired version (I tested for this example the 1.4.2 and 1.5.2 releases), the plugin script, and the CSS bundled with the plug-in:
<script type="text/javascript"
     src="MyScripts/jquery/jquery-x.y.z.min.js"></script>
<script type="text/javascript"
     src="MyScripts/scsLightbox/jquery.scslightbox.js"></script>
<link rel="stylesheet" type="text/css" 
     href="MyStyles/scsLightbox/jquery.scslightbox.css">
  1. We want to activate the lightbox clicking a link, so we need the link, and the DIV with the content we want to disply in the LightBox; the link will not have a content because it will only be an anchor that we will activate it from JS:
<a id="link-content-div" href="#content-div"></a>
  <div id="content-div" style="display: none;">
    Il contenuto del nostro div.
  </div>
</div>
DIV is initially hidden. Note that the href link’s attribute point to the DIV’s selector: this is the same selector we would use in CSS to style the DIV.
  1. Now, we want to display the content-div in the LightBox and define the JS function we can call to activate the LighBox. To find DOM elements and activate the link we use jQuery:
<script type="text/javascript">
  $(function() {
    $('#link-content-div').scsLightbox();
  });
  function ShowContentDiv() {
    $('#link-content-div').trigger('click');
  }
</script>

This trick is quite simple and useful, because it allows you to display whatever HTML you want in a LightBox.

As an alternative you can try to use FancyBox to do the same work.

HOWTO: get a recordset result from a PL/SQL Function

 Questo articolo è disponibile anche in italiano.

How to get a recordset result from a parametric query in PL/SQL in one command?

At first, I thought:

  • It should be useful to use a view but…. We can’t “pass” parameters to a view; a view could read some information from the SYS_CONTEXT or from a table where to store the parameter, but in this way the commands used would be complicated ad we should involve a transaction, isolation of the parameter etc.
  • I may use a procedure but… A procedure can’t return a recordset; it can return a cursor, that cannot be directly “viewed” but rather used by another procedure or PL/SQL code that loops thorugh it.
So, here comes the solution. We may use OBJECT TYPES and PIPELINED FUNCTIONS.
A pipelined function, can return a collection of objects, each of which will be rendered as a record of a table in the resulting recordset; so we have to define this object and the relative collection object in PL/SQL:
    CREATE OR REPLACE
    TYPE O_MY_OBJECT AS OBJECT (
      MY_DATE                       DATE
    , MY_NUMBER                     NUMBER
    , MY_VARCHAR                    VARCHAR2(20)
    );

    CREATE OR REPLACE
    TYPE T_MY_OBJECT AS TABLE OF O_MY_OBJECT;
Then, we can declare a function as PIPELINED and say it will return the previously defined collection type and, in the function body, create the objects (the record) and send them to the output with PIPE ROW():
    FUNCTION MY_FUNCTION(V_MY_PARAM IN VARCHAR2)
      RETURN  T_MY_OBJECT
      PIPELINED
    AS
    V_MY_OBJ_VAR O_MY_OBJECT := O_MY_OBJECT(null, null, null);
    BEGIN
          SELECT
                SYSDATE
              , 10
              , 'CIAO MONDO! -> ' || V_MY_PARAM
          INTO
              V_MY_OBJ_VAR.MY_DATE
            , V_MY_OBJ_VAR.MY_NUMBER
            , V_MY_OBJ_VAR.MY_VARCHAR
          FROM
              DUAL;

          PIPE ROW(V_MY_OBJ_VAR);

      RETURN;
    END MY_FUNCTION;
Let’s go deep in some detail:
  • V_MY_OBJ_VAR O_MY_OBJECT := O_MY_OBJECT(null, null, null); => I define a variable and init it with the object’s default constructor
  • INTO clause => set the desired values (in this case some constant value) in my object’s properties
  • PIPE ROW(V_MY_OBJ_VAR) => send the object to output
If we have to work with rows returned by a parametric query that we want to execute inside the pipelined function, we can declare and LOOP through a cursor and, at every loop cycle, build a new object instance and send it to the output with PIPE ROW.
In the end, to call this function and get the final result, we must use the PL/SQL TABLE function:
     SELECT * FROM TABLE(MY_FUNCTION('SAMPLE VALUE'));
The result, will be a grid of results usable as a table or a view.

Check SW development dept health: personal considerations on “The Joel Test”

SVG version of Bug silk.png by Avatar
Image via Wikipedia

I find The Joel Test useful and quite easy to apply when I have to figure out what’s wrong in the SW development departments I encounter in my job. When I talk about SW depts I met, I talk about little or mid-sized SW houses (from some working units to many tens of working units), from start-ups to mature IT players, from Industry’s internal ITs to dev teams working for IT consulting companies. I have very little experience of product companies that maintains a SW product with a notable market share.

Here are some considerations coming from my experience; with this article I hope to help you beginning to approach this problem seriously.

The Joel Test

1. Do you use source control?

About 15 years ago, my SW Engineering teacher at the college, asked a question: “What’s the very first thing a SW dept got to do to write good code?”. He expected this to be a very easy and obvious question. No one answered that day… The answer was this first check test of Joel’s list. Today I’m not very surprised in finding only half-half SW depts meeting this check.

2. Can you make a build in one step?

This doesn’t mean to click “Build Entire Solution” on your MS Visual Studio Environment; in that meaning it should not be a SW dept process capability, but an IDE feature.
On my PC, for the projects I manage, I can make build in one step with Jenkins either for C# projects or Java projects I work with; conversely, nearly 0% of SW depts I met can say “Yes” to this.

3. Do you make daily builds?

Normally I work by contract, so for a project I can be out of contract for months; so daily builds should be obviously intended for daily running projects. Using Jenkins, I configure it to build every commint to the source control. In this case too, nearly 0% of SW depts I met can say yes.

4. Do you have a bug database?

I have a personal account on FogBugz even for my very personal ultra thin projects. I tried to introduce an issue tracker (such as RedMine) in every SW dept I worked with that didn’t have one; for the SW house I work with almost every day it’s used only on personal or customer attitude basis; it’s not a SW dev process rule. Here I can find more presence of something structured for bugs and requests management.

5. Do you fix bugs before writing new code?

It’s not a strict process rule in SW depts I know, but instinctively it’s at least partially followed.

6. Do you have an up-to-date schedule?

Normally sales depts aren’t able to sell this effort because it’s difficult to make customers understand this value, so contract managers tell PMs to don’t waste time in non-coding operations because they are not paid.

7. Do you have a spec?

Same as number 6, but it’s more frequent to have a spec that an up-to-date schedule. To put me in my expreience exactly in the case six I can ask “Do you have an up-to date spec?”.

8. Do programmers have quiet working conditions?

In my experience I can say definitely No. In the team I haunt overtime it’s considered “normal time” since at least three years. Those who can sometimes go home after their contracted hours are watched as scroungers… These, among other issues such as high bureaucracy levels, are not quiet working conditions.

9. Do you use the best tools money can buy?

Not always. Tools that cost money erode profit in short-term. Almost every contract is short-term so, often, there is not much money in a single contract to buy tools. FLOSS is evil when sales dept talks with customers and is heaven when it’s time to spend money for internal use.

10. Do you have testers?

Sadly I must say no for almost every SW dept I know… Every one is free to test or not his own code. Often, our customers, have dedicated test units to accept SW from suppliers. I write unit tests for my software and let Jenkins report test failures, but it’s so obvious refer again to checks number six and seven…

11. Do new candidates write code during their interview?

Sometimes I have to talk with candidates to join the team I’m working with. New candidates don’t write code during the interview, but they must pass through a “trial period” with objectives adequate to their resume and their future tasks. In this trial period it’s often asked to pass an official certification exam. I think this is a good practice.

12. Do you do hallway usability testing?

This is an interesting method to quickly test software, but I never have the chance to experience it. I wish to!