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

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

    −35

    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
    // For the probably_koi8_locales we have to look. the standard says
    // these are 8859-5, but almost all Russian users use KOI8-R and
    // incorrectly set $LANG to ru_RU. We'll check tolower() to see what
    // it thinks ru_RU means.
    // If you read the history, it seems that many Russians blame ISO and
    // Perestroika for the confusion.
    ...
    static QTextCodec * ru_RU_hack(const char * i) {
        QTextCodec * ru_RU_codec = 0;
    
    #if !defined(QT_NO_SETLOCALE)
        QByteArray origlocale(setlocale(LC_CTYPE, i));
    #else
        QByteArray origlocale(i);
    #endif
        // unicode   koi8r   latin5   name
        // 0x044E    0xC0    0xEE     CYRILLIC SMALL LETTER YU
        // 0x042E    0xE0    0xCE     CYRILLIC CAPITAL LETTER YU
        int latin5 = tolower(0xCE);
        int koi8r = tolower(0xE0);
        if (koi8r == 0xC0 && latin5 != 0xEE) {
            ru_RU_codec = QTextCodec::codecForName("KOI8-R");
        } else if (koi8r != 0xC0 && latin5 == 0xEE) {
            ru_RU_codec = QTextCodec::codecForName("ISO 8859-5");
        } else {
            // something else again... let's assume... *throws dice*
            ru_RU_codec = QTextCodec::codecForName("KOI8-R");
            qWarning("QTextCodec: Using KOI8-R, probe failed (%02x %02x %s)",
                      koi8r, latin5, i);
        }
    #if !defined(QT_NO_SETLOCALE)
        setlocale(LC_CTYPE, origlocale);
    #endif
    
        return ru_RU_codec;
    }

    Снова Qt. На этот раз src/corelib/codecs/qtextcodec.cpp и борьба бобра с ослом русских с буржуинскими стандартами ISO.

    bormand, 14 Июня 2012

    Комментарии (7)
  3. C# / Говнокод #10946

    +108

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public sbyte GetSByte(int i)
    {
        IMySqlValue v = GetFieldValue(i, false);
        if (v is MySqlByte)
            return ((MySqlByte)v).Value;
    
        return ((MySqlByte)v).Value;
    }

    Вытащил это "чудо" когда ковырялся в сырцах MySQL .NET Connector-а

    Heisenberg, 13 Июня 2012

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

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    static char[] decToBin(int n)
    {
        byte size = sizeof(int) * 8;
        char[] result = new char[size];
    
        for (int i = 0; i < size; i++) 
        {
            result[size - i - 1] = (((n >> i) & 1).ToString().ToCharArray()[0]);
        }
        return result;
    }

    Плохо пахнущий транслятор непосредственно в дополнительный код.

    vistefan, 12 Июня 2012

    Комментарии (7)
  5. PHP / Говнокод #10915

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function toArray($xml) {
                    $xml = simplexml_load_string($xml);
                    $json = json_encode($xml);
                    return json_decode($json,TRUE);                        
            }

    Но зачем?!

    mr.The, 11 Июня 2012

    Комментарии (7)
  6. JavaScript / Говнокод #10630

    +148

    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
    var isScheduledRadio = $('#ContentPlaceHolder1_FormView1_ctl04_ctl00___IsScheduled_RadioButtonList1_0')[0],
                    isSitnGoRadio = $('#ContentPlaceHolder1_FormView1_ctl04_ctl00___IsScheduled_RadioButtonList1_1')[0],
                    startDateTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl07___StartDate_TextBox1')[0],
                    minPlayersTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl14___MinPlayers_TextBox1')[0],
                    maxPlayersTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_TextBox1')[0],
                    maxPlayersRequiredValidator = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_RequiredFieldValidator1')[0],
                    maxPlayersRow = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_TextBox1')
                        .parent()
                        .parent()[0],
                    endDateTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_TextBox1')[0],
                    endDateRequiredValidator = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_RequiredFieldValidator1')[0],
                    endDateRow = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_TextBox1')
                        .parent()
                        .parent()[0],

    Увидел такой код с сорцах ASP.Net страницы

    krikz, 08 Июня 2012

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function changeFilter(event) {
      if (parseInt(event.newValue) < 1000) {
        api.Msg.showErr("Укажите год!");
      }
    }

    Обработчик onchange поля "Год"

    glprizes, 07 Июня 2012

    Комментарии (7)
  8. PHP / Говнокод #10605

    +70

    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
    function navigationblock() {
    	$lettersarr=array();
    
    function _strtolower($string)
    {
        $small = array('а','б','в','г','д','е','ё','ж','з','и','й',
                       'к','л','м','н','о','п','р','с','т','у','ф',
                       'х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь',
                       'э', 'ю', 'я');
        $large = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й',
                       'К','Л','М','Н','О','П','Р','С','Т','У','Ф',
                       'Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь',
                       'Э', 'Ю', 'Я');
        return str_replace($large, $small, $string); 
    }
     
    function _strtoupper($string)
    {
        $small = array('а','б','в','г','д','е','ё','ж','з','и','й',
                       'к','л','м','н','о','п','р','с','т','у','ф',
                       'х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь',
                       'э', 'ю', 'я');
        $large = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й',
                       'К','Л','М','Н','О','П','Р','С','Т','У','Ф',
                       'Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь',
                       'Э', 'Ю', 'Я');
        return str_replace($small, $large, $string); 
    }
    
    	$rs=mysql_query("SELECT DISTINCT firstletter FROM mr_gazette WHERE firstletter!=' ' AND parent=0 ORDER BY firstletter");
    	while($one=mysql_fetch_array($rs)) $lettersarr[]=$one["firstletter"];
    	?><form name=findform action='index.php' method=get style="margin:10px 20px 20px 0px; text-align:right; ">
    		<font style='font:bold 8pt Tahoma;'><? 
    		for ($i=0; $i<count($lettersarr);$i++) {
    			?><a href="index.php?&letter=<?=$lettersarr[$i]?>" style='font:bold 8pt Tahoma; text-transform:uppercase;'><?=_strtolower($lettersarr[$i])?></a><img src="img/null.gif" width=5><?
    		}
    		?></font>
    		<input type=hidden name="act" value="search">
    		<input type=text name=searchval class=frmtextsub>&nbsp;&nbsp;<input type=submit value='найти' class=mybutton style="width:50px; height:18px;">
    	</form><?
    	return $lettersarr;
    }

    T_T

    форматирование сохранено

    psycho-coder, 07 Июня 2012

    Комментарии (7)
  9. PHP / Говнокод #10520

    +62

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    <?php
    if($res==true){
    $bool_res=true;
    } else {
    $bool_res=false;
    }
    ?>

    Нашёл в одной малоизвестной CMS.

    BiggestFox, 02 Июня 2012

    Комментарии (7)
  10. ActionScript / Говнокод #10347

    −153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var regs:Array;
    				if ( USE_NEW_SYNTAX )
    					regs = line.match( /vc\[([vif][acost]?)(\d*)?(\.[xyzwrgba](\+\d{1,3})?)?\](\.[xyzwrgba]{1,4})?|([vif][acost]?)(\d*)?(\.[xyzwrgba]{1,4})?/gi );
    				else
    					regs = line.match( /vc\[([vof][actps]?)(\d*)?(\.[xyzwrgba](\+\d{1,3})?)?\](\.[xyzwrgba]{1,4})?|([vof][actps]?)(\d*)?(\.[xyzwrgba]{1,4})?/gi );

    игра найди 10 отличий от Adobe :)

    makc3d, 23 Мая 2012

    Комментарии (7)
  11. Куча / Говнокод #10305

    +130

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Вакансия: Программист Java
    Требования:
        ....
        знание компьютерных программ: Java, pl/sql, Eclipse, Oracle Repotrs приветствуется;
        ....

    Не совсем то, но не мог пройти мимо.

    -EZ-, 17 Мая 2012

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