Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

May 2014

Finding Meaning

by in CodeSOD on

Ray was not just a recent addition to the development team. She was also a recent grad just getting started in her career. As a result, she was eager to glean as much knowledge as she could from any source she could find. She poured over all of the documentation provided to her by her team lead. She read the wiki (because that's the storehouse of communal knowledge for every team), reviewed the code and examined the diagrams of the data models used within the application.

All was going swimmingly...until she came across the following.


Last but not Least

by in CodeSOD on

Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio is the sole developer of software managing hundreds of residents. Missing documentation, he tracks down his predecessors for help.

"Just one left."


The In-House Developer

by in CodeSOD on

Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio is the sole developer of software managing hundreds of residents. Missing documentation, he tracks down his predecessors for help.

Miguel, manager of Casa de Quixote, told Sergio he'd find Luis at a dive in Toledo. "Just follow the empty glasses of beer," he said. Sergio did, and they led to a man: about two hundred pounds overweight, asleep at the bar, wearing a Real Madrid shirt.


Accepted Values for Days of the Month

by in CodeSOD on

Ryan recently received some thorough documentation from a client regarding a third-party API he had been tasked with integrating.

He found it quite helpful that the documentation included an Excel spreadsheet that listed the accepted values for each input field. Particularly helpful was the page on acceptable values for the "dob_dd" (Date of birth -day) field, which lists the "title" of each day and its corresponding "value".


Making Off With Your Inheritance

by in CodeSOD on

There are abuses of the class system, and then there are those beautiful, snowflake- like cases of abuse, those moments where you see the code, you understand the code, and you wish that, somehow, you could throttle the invisible person responsible for that code. Alex found this example:

public class Record_Base
{
	public DateTime RecordDateTime
	{
		get { return _recordDateTime; }
		set 
		{ 
			if (this.GetType().Name == "Record_PartRegister")
				_recordDateTime = value;
			else
				throw new Exception("Cannot call set on RecordDateTime for table " + this.GetType().Name);
		}
	}
}

The Professionals

by in CodeSOD on

Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio begins his new job as the sole developer of software managing hundreds of residents.

"Here is your office," said Miguel, the community manager of Casa de Quixote. He showed Sergio inside. The office was as barren as a prison cell: there was nothing in the room save a desk, a computer, and a wooden chair.


Giving Excel the Run-a-Round

by in CodeSOD on

There are entire books — entire bookstores — dedicated to the truisms of business. One truism that doesn't get written about very often is this: before it gets big enough to have IT resources, every enterprise will run on a clutter of VBA-ridden Excel spreadsheets masquerading as line-of-business software. And, as surely as the sun rises in the East, such a company's first few developers will spend most of their time maintaining these. Sometimes those first few developers, with no one on the hiring squad able to vet their capabilities, will even create a few tabular terrors of their own. Dash found himself opening one of these, an Excel workbook created by a long-gone predecessor whose resume had claimed "extreme familiarity with Microsofts XL", to be faced with this:


Private Sub Worksheet_Calculate() 
 
'...snip... 
 
 If Not Intersect(wsTS.Range("Q11:Q35"), wsTS.Range("Q11:Q35")) Is Nothing Then 
   For r = 11 To 35 
     If wsTS.Cells(r, "N") <> "" Then 
       If wsTS.Cells(r, "Q") < 1 And wsTS.Cells(r, "E") <> "std" Then 
        wsTS.Cells(r, "Q").NumberFormat = "0.00" 
       ElseIf wsTS.Cells(r, "Q") < 10 And wsTS.Cells(r, "Q") >= 1 And wsTS.Cells(r, "E") <> "std" Then 
        wsTS.Cells(r, "Q").NumberFormat = "0.0" 
       ElseIf wsTS.Cells(r, "Q") >= 10 And wsTS.Cells(r, "E") <> "std" Then 
        wsTS.Cells(r, "Q").NumberFormat = "0" 
       ElseIf wsTS.Cells(r, "E") = "std" Then 
        wsTS.Cells(r, "Q").NumberFormat = "0.0" 
       End If 
     End If 
   Next r 
 End If 
 
 If wsTS.Range("D42") < 1 Then 
   wsTS.Range("D42").NumberFormat = "0.00" 
 ElseIf wsTS.Range("D42") < 10 And wsTS.Range("D42") >= 1 Then 
   wsTS.Range("D42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("D42") >= 10 Then 
   wsTS.Range("D42").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("G42") < 1 Then 
  wsTS.Range("G42").NumberFormat = "0.00" 
 ElseIf wsTS.Range("G42") < 10 And wsTS.Range("G42") >= 1 Then 
  wsTS.Range("G42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("G42") >= 10 Then 
  wsTS.Range("G42").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("J42") < 1 Then 
  wsTS.Range("J42").NumberFormat = "0.00" 
 ElseIf wsTS.Range("J42") < 10 And wsTS.Range("J42") >= 1 Then 
  wsTS.Range("J42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("J42") >= 10 Then 2
  wsTS.Range("J42").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("O42") < 1 Then 
  wsTS.Range("O42").NumberFormat = "0.00" 
 ElseIf wsTS.Range("O42") < 10 And wsTS.Range("O42") >= 1 Then 
  wsTS.Range("O42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("O42") >= 10 Then 
  wsTS.Range("O42").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("Q42") < 1 Then 
  wsTS.Range("Q42").NumberFormat = "0.00" 
 ElseIf wsTS.Range("Q42") < 10 And wsTS.Range("Q42") >= 1 Then 
  wsTS.Range("Q42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("Q42") >= 10 Then 
  wsTS.Range("Q42").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("D44") < 1 Then 
  wsTS.Range("D44").NumberFormat = "0.00" 
 ElseIf wsTS.Range("D44") < 10 And wsTS.Range("D44") >= 1 Then 
  wsTS.Range("D42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("D44") >= 10 Then 
  wsTS.Range("D44").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("G44") < 1 Then 
  wsTS.Range("G44").NumberFormat = "0.00" 
 ElseIf wsTS.Range("G44") < 10 And wsTS.Range("G44") >= 1 Then 
  wsTS.Range("G42").NumberFormat = "0.0" 
 ElseIf wsTS.Range("G44") >= 10 Then 
  wsTS.Range("G44").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("J44") < 1 Then 
  wsTS.Range("J44").NumberFormat = "0.00" 
 ElseIf wsTS.Range("J44") < 10 And wsTS.Range("J44") >= 1 Then 
  wsTS.Range("J44").NumberFormat = "0.0" 
 ElseIf wsTS.Range("J44") >= 10 Then 
  wsTS.Range("J44").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("O44") < 1 Then 
  wsTS.Range("O44").NumberFormat = "0.00" 
 ElseIf wsTS.Range("O44") < 10 And wsTS.Range("O44") >= 1 Then 
  wsTS.Range("O44").NumberFormat = "0.0" 
 ElseIf wsTS.Range("O44") >= 10 Then 
  wsTS.Range("O44").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("Q44") < 1 Then 3
  wsTS.Range("Q44").NumberFormat = "0.00" 
 ElseIf wsTS.Range("Q44") < 10 And wsTS.Range("Q44") >= 1 Then 
  wsTS.Range("Q44").NumberFormat = "0.0" 
 ElseIf wsTS.Range("Q44") >= 10 Then 
  wsTS.Range("Q44").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("D46") < 1 Then 
  wsTS.Range("D46").NumberFormat = "0.00" 
 ElseIf wsTS.Range("D46") < 10 And wsTS.Range("D46") >= 1 Then 
  wsTS.Range("D46").NumberFormat = "0.0" 
 ElseIf wsTS.Range("D46") >= 10 Then 
  wsTS.Range("D46").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("G46") < 1 Then 
  wsTS.Range("G46").NumberFormat = "0.00" 
 ElseIf wsTS.Range("G46") < 10 And wsTS.Range("G46") >= 1 Then 
  wsTS.Range("G46").NumberFormat = "0.0" 
 ElseIf wsTS.Range("G46") >= 10 Then 
  wsTS.Range("G46").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("J46") < 1 Then 
  wsTS.Range("J46").NumberFormat = "0.00" 
 ElseIf wsTS.Range("J46") < 10 And wsTS.Range("J46") >= 1 Then 
  wsTS.Range("J46").NumberFormat = "0.0" 
 ElseIf wsTS.Range("J46") >= 10 Then 
  wsTS.Range("J46").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("O46") < 1 Then 
  wsTS.Range("O46").NumberFormat = "0.00" 
 ElseIf wsTS.Range("O46") < 10 And wsTS.Range("O46") >= 1 Then 
  wsTS.Range("O46").NumberFormat = "0.0" 
 ElseIf wsTS.Range("O46") >= 10 Then 
  wsTS.Range("O46").NumberFormat = "0" 
 End If 
 
 If wsTS.Range("Q46") < 1 Then 
  wsTS.Range("Q46").NumberFormat = "0.00" 
 ElseIf wsTS.Range("Q46") < 10 And wsTS.Range("Q46") >= 1 Then 
  wsTS.Range("Q46").NumberFormat = "0.0" 
 ElseIf wsTS.Range("Q46") >= 10 Then 
  wsTS.Range("Q46").NumberFormat = "0" 
 End If

Modern Memory Management

by in CodeSOD on

Evan was in charge of overseeing the integration of Hydra Hosting's seventh and newest acquisition, Calamari. Evan had overseen the last six mergers, and he knew that whether you were integrating with a distant datacenter or moving physical servers into your growing facility, things never went smoothly.

But when Hydra's main datacenter linked up Calamari's, it wasn't just bad. It was catastrophic.