DevDisasters

Developer Fail: A Few Precious Seconds

Ever since Brendan's department had gained ownership of OPSVUE, an enterprise-level application written in Visual Basic .NET used to manage user access to the various homegrown apps, years of unfulfilled enhancement requests and ignored bug fixes had come pouring in.

An issue reported by one user, Alice, stood out.

A power-user, Alice had gained notoriety for the tickets she filed complaining that some screens were taking one to two seconds longer to load than expected. Eager to make a good impression, Brendan responded to her tickets as best he could and explained that the delays might be the result of her working in a remote office.

No Good Deed...
This scenario repeated a number of times until Brendan was finally called into his manager's office.

"Brendan," his manager began in a stern tone. "Alice from West Coast Operations thinks that you have somehow tampered with her access to OPSVUE in retaliation for her filing so many tickets."

Caught off guard, Brendan almost fell out of his seat.

Brendan's manager nodded and continued: "Believe me, I'm on your side, but this squeaky wheel is going to only get louder unless you can give her those seconds back."

Back at his desk, Brendan wracked his brain -- even though he'd fixed a number of things, he didn't have a good idea of how everything fit together. Determined, he meticulously traced through the functions and eventually found a clue:

If (UserData.UserName.Length > 0) Then
  'Now check if the user exists in the User table...
  Dim myUsers = From user In db.Users _
                Where user.PayrollNumber = _
                  rgxExpGXXX.Replace( _
                  ServiceSecurityContext.Current.WindowsIdentity.Name, "")

  If myUsers.Count = 0 Then
    bNewUser = True
  Else
    For Each rec In myUsers
      If (UserData.UserName = rec.Name) Then
        If (rec.Active = False) Then
          rec.Active = True
          db.SubmitChanges()
        End If
        UserData.UserId = rec.Id
      Else
        rec.Active = False
        db.SubmitChanges()
      End If
    Next
    'If we get to here and the User Id is still zero then...
    If (UserData.UserId = 0) Then
      bNewUser = True
    End If
  End If

  If (bNewUser = True) Then
    Dim newRecord = New CommonDal.User With { _
      .PayrollNumber = Environment.UserName, .Name = _
        UserData.UserName, .Active = True}
    db.Users.InsertOnSubmit(newRecord)
    db.SubmitChanges()
  End If
End If

Zero Logic
Upon inspection, Brendan found that the "Users" table had swelled to 15,000 rows -- most of which were duplicates of Alice's User ID. The reason? Turned out, years ago, Alice assisted the original developers in testing OPSVUE and as a result, they included logic to detect her special User ID: 0.

Because taking out the "zero logic" would be painful and time-consuming, Brendan took the easy approach: He changed her User ID to a non-zero, non-special number. Granted, this revoked Alice's power-user abilities, but her screens loaded up much faster.

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