"I recently found this while going over some code in a Util library used by my project," Ian writes, "clearly, this method makes sure the job gets done."

public static int EvalToInteger(string statement) {
     string s = EvalToString(statement);
     return int.Parse(s.ToString());
}

 

"I spotted this in the codebase," Boris L wrote," I laughed at first. Then I cried. Then I laughed again."

Private CARROT() As Char = {"^"c}

 

"Many years back, we went through our codebase and replaced the println statements with calls to our grown-up logger," writes N.B., "a few years later, this pattern has returned."

catch (Exception e)
{
  System.out.println(e);

  int j = 0;

  return j;
}

 

"I stumbled upon this curious function," wrote Johannes, "perhaps the coder of this function doesn't know about replace()?"

protected String parseStringData(String str)
{
    String frag[] = str.split("\"");
    String result = "";
    for (int k=0; k<frag.length;k++)
    {
        result += frag[k];
    }
    return result;
}

 

"Like many fellow developers, the codebase I work on each day is terrible and devoid of any structure," writes Daniel, "but at least I get to enjoy comments made by previous programmers."

// THIS SETTING SHOULD NOT BE 'TRUE'. 
// 'gumdrops' is used here because the variable must 
// be set (to anything - call it 'monkey' if you want), 
// but setting it to 'TRUE' will cause unwanted behaviour
$main->set('categoryDropdownSelection', 'gumdrops'); 

 

"I found this in a simple import script," Matt writes, "it quickly became unclear what the link between the 3 numbers is."

# Find the last 200 transactions
logging.debug( "Finding the last 600 transactions" )
ConnMysql.query("select Id from Transactions order by ts desc limit 0,10000 ")

 

"We have a Classic ASP application," writes Matt Spicer, "and it has some 'classic' ASP code."

' DEBUG for kkieller user
If Session("UserID") = 1 then
   ' Phrase = "[" &  Phrase & "]"
end if
' DEBUG for jmacpherson user
If Session("UserID") = 9 then
   'Phrase = "[" &  Phrase & "]"
End If

 

Jeremy shares a few different interesting snippets from his codebase...

BDate.Value = DateTime.Now.ToString("M/d/yyyy").ToUpper();
EDate.Value = DateTime.Now.AddDays(1).ToString("M/d/yyyy").ToUpper();

... 

string sql = "exec spRequestInitechData '" 
   + txtData.Text.ToString().Replace("'", "''") + "'";
 

...

/// <summary>
///
/// </summary>
/// <param name="blnYes"></param>
private void EditTDemensions(bool blnYes) 
{
    //bln is the introvert of blnYes
    bool bln = (blnYes ? false : true);

    //Display or Hide buttons
    btnDemensionsEdit.Visible = bln;
    btnDemensionsSave.Visible =  blnYes;
    btnDemensionsCancel.Visible = blnYes;
}

 

Michał Ochman came across this "clever" way of creating a directory.

$dir = 'test';
if (!file_exists($dir) || !is_dir($dir))
{
    exec('mkdir '.$dir);
}

  Jon Siddle writes "OpenXML has an interesting enumeration for visibility:"

Member name Description
Visible Visible. When the item is serialized out as xml, its value is "visible".
Hidden Hidden. When the item is serialized out as xml, its value is "hidden".
VeryHidden Very Hidden. When the item is serialized out as xml, its value is "veryHidden".
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!