Ugly Code! https://uglycode.com c0ding is seriose busines!!!!1 Thu, 29 Nov 2012 10:48:51 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.15 actionscript, please https://uglycode.com/2012/11/actionscript-please/ https://uglycode.com/2012/11/actionscript-please/#respond Thu, 29 Nov 2012 10:45:49 +0000 http://uglycode.com/?p=43 /** * This boost the performance 5 times! */ class Float { public var value: Number = .0; }

The post actionscript, please first appeared on Ugly Code!.

]]>
/** * This boost the performance 5 times! */ class Float { public var value: Number = .0; }

The post actionscript, please first appeared on Ugly Code!.

]]>
https://uglycode.com/2012/11/actionscript-please/feed/ 0
appropriate method name https://uglycode.com/2010/07/appropriate-method-name/ https://uglycode.com/2010/07/appropriate-method-name/#respond Wed, 14 Jul 2010 11:48:09 +0000 http://uglycode.com/2010/07/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()

The post appropriate method name first appeared on Ugly Code!.

]]>
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()

The post appropriate method name first appeared on Ugly Code!.

]]>
https://uglycode.com/2010/07/appropriate-method-name/feed/ 0
How to use Exceptions https://uglycode.com/2010/05/how-to-use-exceptions/ https://uglycode.com/2010/05/how-to-use-exceptions/#respond Mon, 03 May 2010 13:55:02 +0000 http://uglycode.com/2010/05/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()); }

The post How to use Exceptions first appeared on Ugly Code!.

]]>
$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()); }

The post How to use Exceptions first appeared on Ugly Code!.

]]>
https://uglycode.com/2010/05/how-to-use-exceptions/feed/ 0
Always, ALWAYS use sub-selects! https://uglycode.com/2009/01/always-always-use-sub-selects/ https://uglycode.com/2009/01/always-always-use-sub-selects/#respond Sat, 24 Jan 2009 12:54:57 +0000 http://uglycode.com/?p=30 SQL with sub-sub-sub-selects: 9 minutes SELECT p.sku AS "Product code", p.annotation AS "Product Description", (SELECT COUNT(orders_products.fk_product_id) AS "count" FROM orders_products INNER JOIN orders ON orders.id = orders_products.fk_order_id AND orders.order_created >= '2008-12-01 00:00:00' AND orders.order_created < = '2008-12-07 24:00:00' INNER JOIN products ON products.id = orders_products.fk_product_id AND products.sku = p.sku WHERE orders_products.fk_order_status_id >= 30) AS "Total … Continue reading Always, ALWAYS use sub-selects!

The post Always, ALWAYS use sub-selects! first appeared on Ugly Code!.

]]>
SQL with sub-sub-sub-selects: 9 minutes

SELECT p.sku AS "Product code",
 p.annotation AS "Product Description",
  (SELECT COUNT(orders_products.fk_product_id) AS "count"
   FROM orders_products
   INNER JOIN orders 
     ON orders.id = orders_products.fk_order_id 
     AND orders.order_created >= '2008-12-01 00:00:00' 
     AND orders.order_created < = '2008-12-07 24:00:00'
   INNER JOIN products 
     ON products.id = orders_products.fk_product_id 
     AND products.sku = p.sku
   WHERE orders_products.fk_order_status_id >= 30) AS "Total number of units sold",
    (
      SELECT SUM((orders_products.price-orders_products.discount)/1.15) AS "sum"
      FROM orders_products
      INNER JOIN orders 
        ON orders.id = orders_products.fk_order_id 
        AND orders.order_created >= '2008-12-01 00:00:00'
        AND orders.order_created < = '2008-12-07 24:00:00'
      INNER JOIN products 
        ON products.id = orders_products.fk_product_id 
        AND products.sku = p.sku
      WHERE orders_products.fk_order_status_id >= 30
     ) AS "Total value"
     FROM products p
      WHERE (
        SELECT COUNT(orders_products.fk_product_id) AS "count"
        FROM orders_products
        INNER JOIN orders 
          ON orders.id = orders_products.fk_order_id 
          AND orders.order_created >= '2008-12-01 00:00:00'
          AND orders.order_created < = '2008-12-07 24:00:00'
        INNER JOIN products 
          ON products.id = orders_products.fk_product_id
          AND products.sku = p.sku
        WHERE orders_products.fk_order_status_id >= 30
      ) > 0

Inner joins for the same thing: 400ms

SELECT products.sku, products.annotation,
  COUNT(orders_products.fk_product_id) AS "count",
  SUM ((orders_products.price-orders_products.discount)/1.15) AS "sum"
  FROM orders_products
  INNER JOIN orders 
    ON orders.id = orders_products.fk_order_id 
    AND orders.order_created >= '2008-12-01 00:00:00' 
    AND orders.order_created < = '2008-12-07 24:00:00'
  INNER JOIN products 
    ON products.id = orders_products.fk_product_id
  WHERE orders_products.fk_order_status_id >= 30
  GROUP BY products.sku, products.annotation

The post Always, ALWAYS use sub-selects! first appeared on Ugly Code!.

]]>
https://uglycode.com/2009/01/always-always-use-sub-selects/feed/ 0
As much as I love WordPress… https://uglycode.com/2009/01/as-much-as-i-love-wordpress/ https://uglycode.com/2009/01/as-much-as-i-love-wordpress/#respond Sat, 24 Jan 2009 12:44:13 +0000 http://uglycode.com/?p=29 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_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 … Continue reading As much as I love WordPress…

The post As much as I love WordPress… first appeared on Ugly Code!.

]]>
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_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.

The post As much as I love WordPress… first appeared on Ugly Code!.

]]>
https://uglycode.com/2009/01/as-much-as-i-love-wordpress/feed/ 0
transactions https://uglycode.com/2008/12/transactions/ https://uglycode.com/2008/12/transactions/#respond Fri, 05 Dec 2008 21:21:53 +0000 http://uglycode.com/?p=22 function run() { ... //DONT TOUCH !!! -> THIS DB TRANS STARTS, BECAUSE XYZ MODUL CONSIST OF DB::Commit() clausule DB::Trans(); return $returnVal; } Hey guys, let’s start a transaction here and expect that no one will ever change the code in any of the other 2000 files. And if they do, I’m sure that while … Continue reading transactions

The post transactions first appeared on Ugly Code!.

]]>
function run() { ... //DONT TOUCH !!! -> THIS DB TRANS STARTS, BECAUSE XYZ MODUL CONSIST OF DB::Commit() clausule DB::Trans(); return $returnVal; }

Hey guys, let’s start a transaction here and expect that no one will ever change the code in any of the other 2000 files. And if they do, I’m sure that while they’ll be editing “modul” XYZ, I’m sure they will know that transaction starts here.

The post transactions first appeared on Ugly Code!.

]]>
https://uglycode.com/2008/12/transactions/feed/ 0
Hardcoding FTW https://uglycode.com/2008/11/hardcoding-ftw/ https://uglycode.com/2008/11/hardcoding-ftw/#respond Sat, 29 Nov 2008 18:19:19 +0000 http://uglycode.com/?p=18 function _getCRServices($data) { if (is_array($data)) { //this is ehmmmm, d*ment requirement from client $not_cr = array(3006, 2416, 1026, 5604, 3501); ... } } Makes one wonder if there was a demented requirement, or just a demented programming technique.

The post Hardcoding FTW first appeared on Ugly Code!.

]]>
function _getCRServices($data) { if (is_array($data)) { //this is ehmmmm, d*ment requirement from client $not_cr = array(3006, 2416, 1026, 5604, 3501); ... } }

Makes one wonder if there was a demented requirement, or just a demented programming technique.

The post Hardcoding FTW first appeared on Ugly Code!.

]]>
https://uglycode.com/2008/11/hardcoding-ftw/feed/ 0
3rd generation MemCached https://uglycode.com/2008/10/3rd-generation-memcached/ https://uglycode.com/2008/10/3rd-generation-memcached/#respond Mon, 27 Oct 2008 08:28:03 +0000 http://uglycode.com/?p=14 $banner->mem->mem->mem->cache_dir = "path/to/cache/dir"; Not confusing at all, no sir!.

The post 3rd generation MemCached first appeared on Ugly Code!.

]]>
$banner->mem->mem->mem->cache_dir = "path/to/cache/dir";

Not confusing at all, no sir!.

The post 3rd generation MemCached first appeared on Ugly Code!.

]]>
https://uglycode.com/2008/10/3rd-generation-memcached/feed/ 0
OCD code? https://uglycode.com/2008/10/ocd-code/ https://uglycode.com/2008/10/ocd-code/#respond Sun, 26 Oct 2008 20:51:09 +0000 http://uglycode.com/?p=10 if (!empty(fetchResult()) and isObject(fetchResult()) and is_a(fetchResult(), "objectType")) { $result = fetchResult(); doSomethingElse(); } elseif (isObject(fetchResult()) { $result = fetchResult(); } I think the guy who wrote it was slightly OCD. And he definitely forgot that fetchResult() fetches results… from the database. After optimizing aforementioned code and singleton-ifying the fetchResult(), number of queries made in one … Continue reading OCD code?

The post OCD code? first appeared on Ugly Code!.

]]>
if (!empty(fetchResult()) and isObject(fetchResult()) and is_a(fetchResult(), "objectType")) { $result = fetchResult(); doSomethingElse(); } elseif (isObject(fetchResult()) { $result = fetchResult(); }

I think the guy who wrote it was slightly OCD. And he definitely forgot that fetchResult() fetches results… from the database.

After optimizing aforementioned code and singleton-ifying the fetchResult(), number of queries made in one pageload went down to 300 from 800. Our code is just awesome.

The post OCD code? first appeared on Ugly Code!.

]]>
https://uglycode.com/2008/10/ocd-code/feed/ 0
Who likes ugly hacks? https://uglycode.com/2008/09/who-likes-ugly-hacks/ https://uglycode.com/2008/09/who-likes-ugly-hacks/#respond Sun, 28 Sep 2008 21:44:41 +0000 http://uglycode.com/?p=3 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 … Continue reading Who likes ugly hacks?

The post Who likes ugly hacks? first appeared on Ugly Code!.

]]>
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.

The post Who likes ugly hacks? first appeared on Ugly Code!.

]]>
https://uglycode.com/2008/09/who-likes-ugly-hacks/feed/ 0