1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #12935

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    while(true){
        $it = $this->item_by_id($i++);
        if($it != null){
            $nItems[] = $it;
        }
        if(count($nItems) >= 5){
            break;
        }
    }

    mr.The, 25 Апреля 2013

    Комментарии (4)
  3. PHP / Говнокод #12927

    +153

    1. 1
    2. 2
    3. 3
    $d = date("d")-1;
    $h = date("H")-2;
    header("Last-Modified: " . gmdate("D, ".$d." M Y ".$h.":i:s") . " GMT");

    Вчера

    straga_coda, 21 Апреля 2013

    Комментарии (4)
  4. JavaScript / Говнокод #12890

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    genchatmessage: function(text, avatar1, avatar2, time, rtl) {
    		if (typeof rtl == "undefined") var rtl = false;
    		if (typeof avatar == "undefined") var avatar = "images/user_male.png";
    		if (typeof time == "undefined") var time = this.gettime();
    		var tr = document.createElement("tr");
    		var td = [document.createElement("td"), document.createElement("td"), document.createElement("td")];
    		var div = document.createElement("div");
    		var span = document.createElement("span");
    		var pre = document.createElement("pre");
    		span.innerHTML = time;
    		pre.innerHTML = interface.innerText(String(text));
    		if (rtl) {
    			div.className = "chat-message-rtl";
    		} else div.className = "chat-message";
    		if (typeof avatar1 == "string") {
    			var img1 = document.createElement("img");
    			img1.src = avatar1;
    			td[0].appendChild(img1);
    		}
    		if (typeof avatar2 == "string") {
    			var img2 = document.createElement("img");
    			img2.src = avatar2;
    			td[2].appendChild(img2);
    		}

    Govnisti_Diavol, 14 Апреля 2013

    Комментарии (4)
  5. JavaScript / Говнокод #12867

    +151

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    var form = jQuery('#' + formId);
    jQuery(form).attr('action', s.url);
    jQuery(form).attr('method', 'POST');
    jQuery(form).attr('target', frameId);
    if(form.encoding)
        {
            jQuery(form).attr('encoding', 'multipart/form-data');      			
        }
    else
        {	
            jQuery(form).attr('enctype', 'multipart/form-data');			
        }			
    jQuery(form).submit();

    Без комментариев.)

    miraage, 09 Апреля 2013

    Комментарии (4)
  6. Perl / Говнокод #12833

    −116

    1. 1
    sprintf "%d-%02d-%02d", map { $$_[5]+1900, $$_[4]+1, $$_[3]+1 } [localtime];

    Даты. Perl. Классика.

    http://perldoc.perl.org/POSIX.html#strftime

    Elvenfighter, 01 Апреля 2013

    Комментарии (4)
  7. Java / Говнокод #12821

    +67

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    System.out.println(randomString(-229985452) + " " + randomString(-147909649));
    
    Функция randomString() реализуется примерно вот так:
    public static String randomString(int i)
    {
        Random ran = new Random(i);
        StringBuilder sb = new StringBuilder();
        for (int n = 0; ; n++)
        {
            int k = ran.nextInt(27);
            if (k == 0)
                break;
    
            sb.append((char)('`' + k));
        }
    
        return sb.toString();
    }

    Оригинальный hello world на java

    tsovak, 28 Марта 2013

    Комментарии (4)
  8. C++ / Говнокод #12812

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    int main()
    {
    	__asm()
    	{
    	NOP
    	}
    	return 0;
    }

    программа делает ничего, но делает

    tsovak, 28 Марта 2013

    Комментарии (4)
  9. C# / Говнокод #12797

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public event ConnectedHandler OnConnected;
    .......
    lock( OnConnected )
    {
        if( OnConnected != null )
        {
            OnConnected( ... );
        }
    }

    Быдломакронабиратели...

    grobotron, 25 Марта 2013

    Комментарии (4)
  10. C++ / Говнокод #12789

    +13

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    CompoundExpression*
    CompoundExpression::newBinaryExpression(
    	BasicBinaryOperation::Type operation,
    	const Expression *x,
    	const Expression *y
    ) {
    	vector<Expression::const_pointer> params(2);
    	params[0] = x;
    	params[1] = y;
    	
    	// integer power optimization
    	if (operation == BasicBinaryOperation::POWER) {
    		if (y->isNumber()) {
    			Number::const_pointer number_y = dynamic_cast<typeof number_y>(y);
    			if (number_y != NULL && number_y->isIntegerNumber()) {
    				IntegerNumber::const_pointer integer_y = dynamic_cast<typeof integer_y>(number_y);
    				if (integer_y != NULL) {
    					operation = BasicBinaryOperation::INT_POWER;
    					return new CompoundExpression(BinaryOperation::getOperation(operation), params);
    				}
    			}
    		}
    	}
    	
    	// x^(y/n), where 'n' is odd integer
    	// transform to '(x^y)^(1/n)'
    	if (operation == BasicBinaryOperation::POWER) {
    		if (y->isCompoundExpression()) {
    			auto compoundExpressionY = dynamic_cast<CompoundExpression::const_pointer>(y);
    			if (compoundExpressionY != NULL && compoundExpressionY->operation->isBinary()) {
    				auto innerOperation = compoundExpressionY->operation;
    				auto binaryOperation = dynamic_cast<BinaryOperation const *>(innerOperation);
    				if (binaryOperation != NULL && binaryOperation->getType() == BasicBinaryOperation::DIVIDE) {
    					Expression::const_pointer   numerator = compoundExpressionY->params[0];
    					Expression::const_pointer denominator = compoundExpressionY->params[1];
    					if (denominator->isNumber()) {
    						auto numberDenominator = dynamic_cast<Number::const_pointer>(denominator);
    						if (numberDenominator != NULL && numberDenominator->isIntegerNumber()) {
    							auto integerDenominator = dynamic_cast<IntegerNumber::const_pointer>(numberDenominator);
    							if (integerDenominator != NULL && (integerDenominator->intValue() % 2) != 0) {
    								auto base = CompoundExpression::newBinaryExpression(BasicBinaryOperation::POWER, x, numerator);
    								return CompoundExpression::newBinaryExpression(BasicBinaryOperation::NTH_ROOT, integerDenominator, base);
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    
    	return new CompoundExpression(BinaryOperation::getOperation(operation), params);
    }

    Моё. Потребовалось воткнуть оптимизацию арифметического выражения некоторого вида. В результате родился вот такой костыль.

    UncleAli, 24 Марта 2013

    Комментарии (4)
  11. C++ / Говнокод #12664

    +8

    1. 1
    2. 2
    #define I_HATE_MACRO2(BEGIN__, END__) BEGIN__##END__
    #define CONCAT_MACRO(BEGIN__, END__) I_HATE_MACRO2(BEGIN__,END__)

    LispGovno, 28 Февраля 2013

    Комментарии (4)