DevDisasters

Fixing Bad Code from a Contractor

DevDisasters

Brandon hired a software development contractor to create a Web portal using ASP.NET to complete a custom software solution for one of his company's Software as a Service customers. As the project manager, Brandon had budgeted this portal for no more than four weeks of work. If the project were done in-house, utilizing the company's custom app framework, it would've taken no more than two weeks for the internal team's slowest developers. The dev group simply didn't have the resources to assign to the project, so Brandon needed to subcontract.

Brandon trained the independent contractor Mark on how to use the app framework. The dev team would code any server code, so Mark was only responsible for the ASP.NET portion of the project.

After about six weeks, Brandon started to realize that things demonstrated to the team as "Complete" weren't working properly once the developers got their hands on them and were close to UAT deployment. Features were semi-functional -- meaning highly unstable -- and it was clear that Mark's nine-year resume and reputation touted by the placement agency were completely farcical.

Good Cop, Bad Cop
Regardless, as the project manager, Brandon got more involved with Mark's code, and so did the company's CTO. The CTO and Brandon decided to do a "good cop, bad cop" routine on him. The CTO, the bad cop, pressured Mark into delivering as he promised or the company wouldn't be able to afford his services.

Brandon got a phone call around 8 p.m. on a Sunday night. The team was supposed to demo the portal for the client the next morning. Mark wanted Brandon to look at his code because he had an "issue."

Mark explained that the data coming from the server wasn't matching the data on the front-end. He stated that the data from the server was correct. (And of course it was -- Brandon's team wrote that code for him.) Brandon asked Mark how he was merging the data together and he said that he was using the "merge" function. Brandon logged on and looked at his code and was completely shocked at what he saw!

Simple Task
Mark actually wrote more than 240 lines of code to manually merge data from two datasets. Brandon had to mute his microphone to call his wife over to see how pathetic this guy's code was:

btnSave_Click Method was 42 lines; Brandon changed it to four lines.

The method SetCaseRow was 205 lines of completely useless code. Brandon deleted it and replaced the call to SetCaseRow with the DataSet.Merge function:

  // Merge with the edited data
  casedata.Data.Merge(
    RefreshCasedatafromInputScreen(
    (CASEDATA)Session["UpdatedCaseData"]
    ).Data);

RefreshCasedataFromInputScreen was 120 lines of code; Brandon called an already existing function, saving another 120 lines.

All in all, he shrunk 363 lines of code (including the more than 240 lines of merge code) into three lines in about 45 seconds. Brandon shook his head as he explained to his wife that Mark had probably spent two or three days writing code -- which didn't even work properly -- when there's a built-in function included by Microsoft. The worst part: Brandon's team had shown Mark some examples of how to merge the data from their server into his UI.

Tell Us Your Tale

Have you experienced the darker side of development? We want to publish your story. E-mail your tale to Executive Editor Kathleen Richards at [email protected] and put "DevDisasters" as the subject line.

Merge Disfunction
Brandon tried not to imagine what would have happened if Mark had tried to implement this type of craziness with all of the schemas and datasets they used in the project. The built-in DataSet.Merge function works with any dataset, while Mark's function worked only with the specific type of dataset for which he had coded. He could have spent weeks or months warping his brain to write merge code -- hundreds of lines for each different type of dataset. Had he only known about the merge function!

Mark finished by telling Brandon that he was so thankful Brandon could help him clean the code up because he was afraid the CTO would see it and tell him there was a better way. Brandon had to tactfully tell Mark that his code was the worst code -- and dumbest thing -- he'd seen in years. Mark was let go that week and Brandon's team had to build the portal in-house.

About the Author

Kathleen Richards is the editor of RedDevNews.com and executive editor of Visual Studio Magazine.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube