public function getProduct($product_id) {
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND pr.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		/* ... */

Opencart's Product model

By opencart, 2017-12-12 12:52:34
private HashMap<String, Tuple6<float[], String[], String[], String[], String[], String>> memberNameChangedToProtectTheInnocent = null;
By Anonymous, 2017-12-12 12:13:22

"  ".split(" ");

Very weird code found multiple times in old code base.

By heldt, 2017-12-12 12:03:14
    public static class DecimalHelpers
    {
        /// <summary>
        /// Format a decimal XX.XX to XX,XX%.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToStringPercentageValue(this decimal value)
        {
            return value.ToString().Replace(".", ",").FormatToPercentageValue();
        }
    }
    
    public static class StringHelpers
    {
        /// <summary>
        /// Add % at the end of the string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToPercentageValue(this string value)
        {
            return string.Concat(value, "%");
        }
    }
By Anonymous, 2017-12-12 10:58:38
switch (numberOfQuestionsToAnswer) {
        case 0:
            displayGrid1 = false;
            displayGrid2 = false;
            displayGrid3 = false;
            displayGrid4 = false;
            displayGrid5 = false;
            displayGrid6 = false;
            displayGrid7 = false;
            displayGrid8 = false;
            displayGrid9 = false;
            displayGrid10 = false;
            break;
        case 1:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayGrid1 = true;
            break;
        case 2:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            break;
        case 3:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            break;
        case 4:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            break;
        case 5:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            break;
        case 6:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayAnsInputTextBox6 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            displayGrid6 = true;
            break;
        case 7:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayAnsInputTextBox6 = displayPreselectedAnsBox();
            displayAnsInputTextBox7 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            displayGrid6 = true;
            displayGrid7 = true;
            break;
        case 8:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayAnsInputTextBox6 = displayPreselectedAnsBox();
            displayAnsInputTextBox7 = displayPreselectedAnsBox();
            displayAnsInputTextBox8 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            displayGrid6 = true;
            displayGrid7 = true;
            displayGrid8 = true;
            break;
        case 9:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayAnsInputTextBox6 = displayPreselectedAnsBox();
            displayAnsInputTextBox7 = displayPreselectedAnsBox();
            displayAnsInputTextBox8 = displayPreselectedAnsBox();
            displayAnsInputTextBox9 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            displayGrid6 = true;
            displayGrid7 = true;
            displayGrid8 = true;
            displayGrid9 = true;
            break;
        case 10:
            displayAnsInputTextBox1 = displayPreselectedAnsBox();
            displayAnsInputTextBox2 = displayPreselectedAnsBox();
            displayAnsInputTextBox3 = displayPreselectedAnsBox();
            displayAnsInputTextBox4 = displayPreselectedAnsBox();
            displayAnsInputTextBox5 = displayPreselectedAnsBox();
            displayAnsInputTextBox6 = displayPreselectedAnsBox();
            displayAnsInputTextBox7 = displayPreselectedAnsBox();
            displayAnsInputTextBox8 = displayPreselectedAnsBox();
            displayAnsInputTextBox9 = displayPreselectedAnsBox();
            displayAnsInputTextBox10 = displayPreselectedAnsBox();
            displayGrid1 = true;
            displayGrid2 = true;
            displayGrid3 = true;
            displayGrid4 = true;
            displayGrid5 = true;
            displayGrid6 = true;
            displayGrid7 = true;
            displayGrid8 = true;
            displayGrid9 = true;
            displayGrid10 = true;
            break;
}

This was for a wizard type questionnaire where there could be up to 10 questions.

By Anonymous, 2017-12-12 10:57:52
string month = DateTime.Today.Month.ToString();
if (DateTime.Today.Month < 10)
{
    month = "0" + month;
}
string day = DateTime.Today.Day.ToString();
if (DateTime.Today.Day < 10)
{
    day = "0" + day;
}

string dateCorrect = String.Format("{0}.{1}.{2}", DateTime.Today.Year, month, day);

string dateDue = "";
if (transferFields.DueDate.SelectedDate.HasValue)
{
    var dateDuearr = transferFields.DueDate.Value.Split(' ')[0].Split('.');
    dateDue = dateDuearr[2] + '.' + dateDuearr[1] + '.' + dateDuearr[0];
}
else {
    dateDue = dateCorrect;
}

Real developers don't use built in parsing and formatting methods.

By You will be proud of our code!, 2017-12-12 09:53:08
bool b = connection.isConnected() == true ? true : false;

My first internship presented me with this.

By Anonymous, 2017-12-12 09:39:54
#112 Go -7
if err != nil {
    return err
}
By the intelligentsia of /r/pcj, 2017-12-12 09:37:38
Long timestamp = Instant.now().toEpochMilli(); // fallback
if (oTimestamp instanceof Integer)
    timestamp = (Integer) oTimestamp *1L;
else
    if (oTimestamp instanceof Long)
        timestamp = (Long) oTimestamp * 1L;
By Anonymous, 2017-12-12 08:13:40


public static MyClass {
    private static volatile ProcessManager singleton = null;
    
    public static ProcessManager getInstance() throws Exception {
        if (singleton == null) {
            synchronized (MyClass.class) {
                if (singleton == null) {
                    singleton = new ProcessManager();
                }
            }
        }
        return singleton;
    }
}

The double-checking was invented prior to Java5.

The purpose is if the field isn't null, you don't have to synchronize. But since the java memory model specification was cleaned up and Synchronize/Volatile were given much better specification and semantics it is totally useless boilerplate that you should only write if you have to support Java4. There is a Google Tech Talk that covers this.

By cody, 2017-12-12 08:02:01
try:
    self._update_plan()
except Exception as e:
    raise Exception('{0}'.format(e))

RIP debuggability

By Anonymous, 2017-12-12 05:22:22
Double value = item.getPrice() * loyaltyPointMultiplier;
String[] s = String.split(value.toString(), "\\.");
points = Integer.parseInt(s[0]);
if(Integer.parseInt(s[1]) > 0) {
    points++;
}
    
return points;

Want to round up? Math.ceil() uses too little memory! Use this instead!

By phytyca, 2017-12-12 05:02:48
def absolute_value(value):
    if str(value)[0]=='-':
        value = -1 * value
        return value
    else:
        return value
By Random student of algorithms., 2017-12-12 04:32:36
def open(self, *filename):
	if len(filename) > 1:
		print(("Usage:\nopen() - opens with the initialized "
			"filename\nopen(filename) - opens with given filename"))
		return 1
	if len(filename) == 1:
		self.filename = filename[0]
	if self.filename is None:
		print("No filename given")
		return 1
	self.struct_p = open_struct(self.last_error, self.error_size, \
		self.filename)
	if self.struct_p is None:
		print("Cannot open file: " + self.filename)
		return 1
	self.load_data()
	return 0
By Anonymous, 2017-12-12 03:26:17
int my_array[] = {
#include "data.txt"
};
By Anonymous, 2017-12-12 01:45:55