DevDisasters

Pink Slip for the Developer Who Slipped In

If you think Bert is all talk when it comes to his decade of C# experience, you're wrong. He delivers…15 times.

Brian wasn't sure how it happened or what had changed.

When he was hired on five years ago, the process ahead of his being included into the fold of Initech's (not the company's real name) developers was a bit of a pain, though not an uncommon one. After all, you have to be rigorous in your search for the very best.

You see, before being offered a shot at an on-site interview, Brian first had to prove his mettle by completing an online exam. Then he had to fight his way through a gauntlet of phone screenings with several development leads. Only then was he invited in for a full-day interview process with everybody that he had spoken to and an HR drone to make sure he was mentally and morally fit for the position.

Even after he was hired on, Brian had to earn his "Initech .NET Certification" before being allowed to deploy code into production, and prove that, even as an experienced new hire, he could successfully and correctly work within the corporate source control and release environment.

But somehow, the hiring process was relaxed for Bert.

A self-proclaimed 10-year C# expert, Bert's resume had managed to magically impress Brian's team lead and lead architect, allowing him to be fast-tracked through the interview process. Some say that he must have employed some sort of mind trick by talking non-stop about various patterns and the like, but the consensus was clear -- everybody who interviewed him came back feeling that he had the "it" factor they were looking for. Bert was on-boarded in record time and thrown right into the mix, assigned to projects even before being "certified."

But how good was Bert, really?

15 Times Over
A year into the "Bert Era," Brian finally had a chance to experience Bert's code first-hand after it came time to add a new version of some third-party application to the company's flagship app's supported list. This was functionality added by Bert around a few months before.

Brian did not get very far when the WTFs started racing through his head like a Class 5 hurricane.

Turns out, even with 10 years of C#, Bert didn't seem too fond of arrays:

public const string SUPPORTED_VERSIONS = "7.8|7.9|7.10|7.11|7.12|7.13|7.14|8.0";
public const string SUPPORTED_RELEASES = 
  "(R2009a)|(R2009b)|(R2010a)|(R2010b)|(R2011a)|(R2011b)|(R2012a)|(R2012b)";
private const int MAX_VERSIONS = 15;

So, not only was Bert using a pipe "|" as a string separator, but also, it would appear that the application would only support 15 versions. Ever.

Now comes the horror where, around 50 lines later, Bert decided that arrays might actually be a good thing:

private string [] m_ReleaseArray;
private string [] m_VersionArray;
public VersionconstraintsSettings()
{
  id = "Supportedconstraints";
  m_VersionArray = SUPPORTED_Supported_VERSIONS.Split('|');
  m_ReleaseArray = SUPPORTED_Supported_RELEASES.Split('|');
  if (m_VersionArray.Length != m_ReleaseArray.Length)
  {
    System.Diagnostics.Debug.Fail(
      "Please make sure m_VersionArray and m_ReleaseArray match (size and content)");
  }
  var toolboxarray = GENERAL_TOOLBOXES.Split('|');
  m_SupportedtoolboxCombinations = new SupportedToolboxCombinations(m_VersionArray);
  m_SupportedtoolboxCombinations.AddNewToolBoxes(new List<string>(toolboxarray));
  m_SupportedtoolboxCombinations.Apply();
}

"OK, so, we have an array…could've done that in the first place, but whatever," Brian remarked out loud, "Now we would like to enable/disable certain versions, of course, so let's create a variable for that, and all other 14 possible supported versions":

private UndoRedo<bool> m_EnabledZero = new UndoRedo<bool>(false);
private UndoRedo<bool> m_EnabledOne = new UndoRedo<bool>(false);
private UndoRedo<bool> m_EnabledTwo = new UndoRedo<bool>(false);
...
private UndoRedo<bool> m_EnabledFourteen = new UndoRedo<bool>(false);

"And surely we would need an accessor for every value!":

public bool EnabledZero
{
  get
  {
    return m_EnabledZero.Value;
  }
  set
  {
    if (m_EnabledZero.Value != value)
    {
      object oldValue = m_EnabledZero.Value;
      m_EnabledZero.Value = value;
      if (!value)
      {
        m_SupportedtoolboxCombinations.UnCheckSupportedVersion(0);
      }
      PropertyHasChanged("EnabledZero", oldValue);
    }
  }
}

"Ugh ... repeated 14 more times? And if I want to see if a specific version is enabled ... are you kidding me!?":

public string VersionEnabledZero
{
  get
  {
    return GetEnabledVersion(0);
  }
  set
  {
    // Not needed, just for data binding
  }
}
public string VersionEnabledOne
{
  get
  {
    return GetEnabledVersion(1);
  }
  set
  {
    // Not needed, just for data binding
  }
}

... and so on through to VersionEnabledFourteen.

Brian groaned, "Or, wait, I know -- I guess ignore common sense all together and do something like this...":

private bool GetVersionEnabled(int index)
{
  switch (index)
  {
    case 0:
      return EnabledZero;
    case 1:
      return EnabledOne;
    case 2:
      return EnabledTwo;
    ...
    case 14: 
      return EnabledFourteen;
        ...

...and again. Brian started wondering if the number 15 actually held some kind of cosmic significance for Bert:

private void ResetVersionEnabled(int index, bool val)
{
  switch (index)
  {
    case 0:
      m_EnabledZero.Value = val;
      return;
    case 1:
      m_EnabledOne.Value = val;
      return;
    case 2:
      m_EnabledTwo.Value = val;
      return;
    ...
    case 14:
      m_EnabledFourteen.Value = val;
      return;
    ...

And then there's the mother-of-all-case switches to see if all versions are supported:

public bool AllVersionsHaveBeenEnabled
{
  get
  {
    bool res = (PresentedVersionZero == "") || EnabledZero;
    res = res && ((PresentedVersionOne == "") || EnabledOne);
    res = res && ((PresentedVersionTwo == "") || EnabledTwo);
    etc...
  set
  {
    if (m_Lock_AllVersionsHaveBeenEnabled)
    {
      return;
    }
    if (PresentedVersionZero != "")
    {
      EnabledZero = value;
    }
    if (PresentedVersionOne != "")
    {
      EnabledOne = value;
    }
    if (PresentedVersionTwo != "")
    {
      EnabledTwo = value;
    }
    etc...
  }
}

"And, given our less-than-glorious start, it would be a shame to end on anything less than this!":

private string CreateStringOfSelectedSupportedVersions()
{
  string res = "";
  int i;
  for (i = 0; i < m_VersionArray.Length; i++)
  {
    if (GetVersionEnabled(i))
    {
      if (res != "")
      {
        res += "|";
      }
      res += m_VersionArray[i];
    }
  }
  return res;
}

"Yeah," Brian sighed, "let's put it all back into a single string. That makes it so much easier to work with."

Something had to be done.

We Have a Problem...
Not wanting to perpetuate such a tragedy of code, Brian brought the code to the attention of both the lead architect and supervisor. Soon after digging through a bunch of Bert's other commits, bug reports, and some long-ignored code metrics, they figured that Bert was solely responsible for approximately 55 percent to 60 percent of the found bugs, and around 35 percent of the total added lines of code since he started. Not bad for an 18-man team.

The code that Brian worked against rang in a whopping 1,600-plus lines of code alone, not counting the UI-related code or any support functions that Bert created for this monstrosity.

It appeared that Bert talked the talk, but when it came to walking, he preferred crawling...in reverse...off a cliff.

Two weeks later, Bert was let go.

About the Author

Mark Bowytz is a contributor to the popular Web site The Daily WTF. He has more than a decade of IT experience and is currently a systems analyst for PPG Industries.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube