appropriate method name

Company.Project.Tests.Listeningtool.IntegrationTest.ListeningToolBrandCategoryAndMentionsReportTest.Should_Add_a_Valid_File_And_The_MentionsByBrandAndCategoryReport_Should_Have_Any_Sentiment_Equal_To_Positive()

Or, if you prefer,

Company
 .Project
  .Tests
   .Listeningtool
    .IntegrationTest
     .ListeningToolBrandCategoryAndMentionsReportTest
      .Should_Add_a_Valid_File_And_The
       _MentionsByBrandAndCategoryReport_Should_Have
        _Any_Sentiment_Equal_To_Positive()

How to use Exceptions

   $error = false;
   try
   {
    $response = $comm->sendRequestToPaymentGate($this);
   }
   catch(Exception $e)
   {
    $error = $e;
    $response = null;
   }
   // Save the response's values
   $this->loadEnrollmentResponse($response);
  }
 
  // Save the progress so transaction process can be continued in the future
  $this->save();
 
  if($error !== false)
  {
   Mage::throwException($error->getMessage());
  }

As much as I love WordPress…

Seems that some WP developers are fans of refuctoring.

if ( ($fQ=strpos($Fid,'"'))!==false )
    $Fname = sanitize_title_with_dashes(substr( $Fid, $fQ+1, strpos($Fid,'"',$fQ+1)-$fQ-1 ));
### wrapped in <p> ?
   $p_offset = ($p_close < $p_open) ? $a-(strlen($part_content)-$p_open) : $a;

Argh. Guys, seriously, how about some objects? How about some readable variables? How about instead of nesting function calls and using ugly ternary operators… ugh. Nevermind.

Who likes ugly hacks?

According to my search, a lot of people do.

#ugly hack
self.log.info("Running script")
dict={ 'self' : self.model,
'model' : self.model,
'interpreter': self }
exec(self.script,dict)
// Ugly hack
Class.forName("tristero.util.Conduit");
Class.forName("tristero.util.Lock");
Class.forName("tristero.util.PumpListener");
Class.forName("tristero.util.StringUtils");
_label.Show();
_label.Hide(); // Ugly hack!
base.Show();
 /*
UGLY UGLY UGLY HACK !!!
*/
QFile inFile(uisFile);
if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
 
QFile outFile("/tmp/temp.ini");
if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream in(&inFile);
QTextStream out(&outFile);
 
while (!in.atEnd())
{
QString line = in.readLine();
line.replace("\\","\\\\");
out << line << endl;
}
inFile.close();
outFile.close();
/*
END OF UGLY UGLY UGLY HACK
*/
 // ugly, ugly hack
if(adapterUse.getAdapterIfKnown()== SwaRefAdapter.class) {
programElement.annotate(XmlAttachmentRef.class);
} else {
// [RESULT]
// @XmlJavaTypeAdapter( Foo.class )
programElement.annotate2(XmlJavaTypeAdapterWriter.class).value(
adapterUse.adapterType.toType(outline,EXPOSED));
}

Of course, these doesn’t provide fun nor educational value. But one thing is obvious: ugly code is here to stay. Hopefully I’ll be able to find some more entertaining pieces next time.