Microsoft’s C# has become an extremely popular language for “enterprise” development, and it’s sobering to think that: yes, this language has been around for 15 years at this point. That’s long enough for the language to have grown from a “sort of Java with reliability, productivity and security deleted.” (James Gosling, one of the creators of Java) to “sort of Java, but with generics and lambdas actually implemented in a useful way, and not completely broken by design”.

15 years is also more than enough time for a project to grow out of control, turning into a sprawling mass of tentacles with mouths on the ends, thrashing about looking for a programmer’s brain to absorb. Virginia N is currently locked in a struggle for sanity against one such project.

Some of the code looks like this:

if (m_ProgEnt!=null)
{
        if (m_ProgEnt.SAFF_SIG==m_PSOC_SIG)
        {
                ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]);
        }
        else
        {
                ChangePosition("P",true,(bool)ar[6], (DateTime)ar[1], (DateTime)ar[5]);
        }
}
else
{

}
ChangePosition("P",true,(bool)ar[6],(DateTime)ar[1],(DateTime)ar[5]);

You’ll note that all three calls to ChangePosition do exactly the same thing. I also don’t know what the array ar holds, but apparently it’s a mixture of booleans and date-time objects.

The code-base is littered with little meaningless conditionals, which makes the meaningful ones so much more dangerous:

if ( demandesDataRowView["SGESDEM_SOC"].ToString().Equals(demandesDataRowView["SGESDEM_SIG"].ToString()) && demandesDataRowView["SGESDEM_SIG"].ToString().Length > 0 )
        sSocieteCour = demandesDataRowView["SGESDEM_SIG"].ToString();
else
        sSocieteCour = demandesDataRowView["SGESDEM_SOC"].ToString();

In another part of the code, they define a ResultsetFields object twice, storing it in the same variable, and never using the first definition for anything:

int iFieldIndex = 0;
ResultsetFields fields = new ResultsetFields(19);
//DemandesDetail fields
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REFLIVR,   iFieldIndex++,          "SGESDEMD_REFLIVR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_SOCLIVR,   iFieldIndex++,          "SGESDEMD_SOCLIVR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTEAUT,    iFieldIndex++,          "SGESDEMD_QTEAUT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_PU,                        iFieldIndex++,          "SGESDEMD_PU");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_TYPE,                      iFieldIndex++,          "SGESDEMD_TYPE");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REMCLIENT, iFieldIndex++,          "SGESDEMD_REMCLIENT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTEASORT,  iFieldIndex++,          "SGESDEMD_QTEASORT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_LBID,                      iFieldIndex++,          "SGESDEMD_LBID");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_LIVRPAR,           iFieldIndex++,          "SGESDEMD_LIVRPAR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_CMDNUM,            iFieldIndex++,          "SGESDEMD_ASORT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REFDEM,            iFieldIndex++,          "SGESDEMD_REFDEM");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_SOCDEM,            iFieldIndex++,          "SGESDEMD_SOCDEM");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTESOR,            iFieldIndex++,          "SGESDEMD_QTESOR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTERECENT,         iFieldIndex++,          "SGESDEMD_QTERECENT");



// Stock fields
fields.DefineField(STOCKFieldIndex.SREF_SOC ,   iFieldIndex++,          "SREF_SOC");
fields.DefineField(STOCKFieldIndex.SREF_COD ,   iFieldIndex++,          "SREF_COD");
fields.DefineField(STOCKFieldIndex.SREF_NSTOCK ,        iFieldIndex++,          "SREF_NSTOCK");
fields.DefineField(STOCKFieldIndex.SREF_QTERES ,        iFieldIndex++,          "SREF_QTERES");
fields.DefineField(STOCKFieldIndex.SREF_QTEASORT ,      iFieldIndex++,          "SREF_QTEASORT");

//SNIP [... 1500 lines without using fields]

iFieldIndex = 0;
fields = new ResultsetFields(29);
//DemandesDetail fields
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REFLIVR,   iFieldIndex++,          "SGESDEMD_REFLIVR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_SOCLIVR,   iFieldIndex++,          "SGESDEMD_SOCLIVR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTEAUT,    iFieldIndex++,          "SGESDEMD_QTEAUT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTELIVR,   iFieldIndex++,          "SGESDEMD_QTELIVR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_PU,                        iFieldIndex++,          "SGESDEMD_PU");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_TYPE,                      iFieldIndex++,          "SGESDEMD_TYPE");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REMCLIENT, iFieldIndex++,          "SGESDEMD_REMCLIENT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTEASORT,  iFieldIndex++,          "SGESDEMD_QTEASORT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_LBID,                      iFieldIndex++,          "SGESDEMD_LBID");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_LIVRPAR,           iFieldIndex++,          "SGESDEMD_LIVRPAR");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_CMDNUM,            iFieldIndex++,          "SGESDEMD_ASORT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_REFDEM,    iFieldIndex++,          "SGESDEMD_REFDEM");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_SOCDEM,    iFieldIndex++,          "SGESDEMD_SOCDEM");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_DOAA_ID,   iFieldIndex++,          "SGESDEMD_DOAA_ID");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_DOALID,    iFieldIndex++,          "SGESDEMD_DOALID");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_DOAA_ANNEE,        iFieldIndex++,          "SGESDEMD_DOAA_ANNEE");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_VALMASSE,  iFieldIndex++,          "SGESDEMD_VALMASSE");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTERECENT, iFieldIndex++,          "SGESDEMD_QTERECENT");
fields.DefineField(DEMANDESDETAILFieldIndex.SGESDEMD_QTESOR,    iFieldIndex++,          "SGESDEMD_QTESOR");


// Stock fields
fields.DefineField(STOCKFieldIndex.SREF_SOC ,   iFieldIndex++,          "SREF_SOC");
fields.DefineField(STOCKFieldIndex.SREF_COD ,   iFieldIndex++,          "SREF_COD");
fields.DefineField(STOCKFieldIndex.SREF_DES ,   iFieldIndex++,          "SREF_DES");
fields.DefineField(STOCKFieldIndex.SREF_NSTOCK ,        iFieldIndex++,          "SREF_NSTOCK");
fields.DefineField(STOCKFieldIndex.SREF_QTERES ,        iFieldIndex++,          "SREF_QTERES");
fields.DefineField(STOCKFieldIndex.SREF_QTEASORT ,      iFieldIndex++,          "SREF_QTEASORT");
fields.DefineField(STOCKFieldIndex.SREF_BIEN ,  iFieldIndex++,          "SREF_BIEN");
fields.DefineField(STOCKPARAMFieldIndex.SREFP_LOT ,     iFieldIndex++,          "SREFP_LOT");
fields.DefineField(STOCKPARAMFieldIndex.SREFP_KIT ,     iFieldIndex++,          "SREFP_KIT");
fields.DefineField(STOCKPARAMFieldIndex.SREFP_EPI ,     iFieldIndex++,          "SREFP_EPI");

These three different samples I’ve used here did not come from various methods throughout the code-base. No, to the contrary, these are all in the same method, lnkPrCompte_LinkClicked. That would be an event-handling method. One event handling method. In a .NET solution which contains over 70 individual DLL and executable projects, with hundreds of classes per DLL, and a whopping 65 million lines of code- roughly one line for each year the dinosaurs have been extinct.

Virginia is trying valiantly to refactor the project into something supportable. She’s tried to bring in tools like ReSharper to speed the effort along, but ReSharper takes one look at the code base, decides the dinosaurs had the right idea, and promptly dies.

A screengrab of Visual Studio 2003, showing the method lnkPrCompte_LinkClicked is over 2,000 lines in a 39,000 line file

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!