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

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function calculateBaggageFields(selectedNormalOutboundOption, selectedNormalInboundOption,
    				numOriginalNormalBagsOutboundField, numOriginalNormalBagsInboundField,
    				numAdditionalBagsField, numAdditionalBagsOutboundField, numAdditionalBagsInboundField,
    				selectedOutsizeOutboundOption, selectedOutsizeInboundOption,
    				totalForThisPassengerField,
                                    selectedExcessKilosOutboundOption,selectedExcessKilosInboundOption,
                                    numOriginalExcessKilosOutboundField,numOriginalExcessKilosInboundField,
                                    numAdditionalExcessKilos,numAdditionalExcessKilosOutbound,numAdditionalExcessKilosInbound)

    продакшн-говно за работой!

    hrls, 14 Июля 2011

    Комментарии (16)
  3. Java / Говнокод #7244

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(!xmlDate.equals(null))
    {
    ...
    }
    else
    {
            return null;
    }

    Для полноты картинки смотрим метод equals в XMLGregorianCalendar.java. Стажеры такие стажеры...

    Art, 14 Июля 2011

    Комментарии (16)
  4. SQL / Говнокод #7240

    −851

    1. 1
    facepalm.sql

    В таблице платежей несколько полей с цифрами - _amount и _value.
    В связаной таблице есть поле PaymentAmount.
    Угадайте, какому полю платежа оно соответствует 7:

    wiz, 13 Июля 2011

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

    +185

    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
    if ($_GET['code1c_Connected']=='') {
    				if ($_GET['type']!="shop") {
    					if ($_GET['type']!="lk") {
    						if ($_GET['type']!="home") {
    						if ($_GET['type']!="login_reg") {
    							if ($_GET['type']!="reg_quick") {
    								if ($_GET['type']!="order") {
    									if ($_GET['type']!="order_g") {
    								       if ($GET['type']!="payment") {
    										if ($_GET['type']!='contakts') {
    											if ($_GET['type']!='contact_kiev_volinskaya47') {
    												if ($_GET['type']!='contact_kiev_lesi_ukrainki15') {
    													if ($_GET['type']!='contact_kiev_vozduhoflotskiy17') {
    														if ($_GET['type']!='contact_kiev_malinovskogo12') {
    															if ($_GET['type']!='contact_kiev_solomenskaya16') {
    																if ($_GET['type']!='contact_kiev_yakuba2') {
    																	if ($_GET['type']!='contact_odessa_tiraspolskaya35') {
    																		if ($_GET['type']!='contact_odessa') {
    																			if ($_GET['type']!='contact_kharkov') {
    																				if ($_GET['type']!='contact_kharkov_fonvizena18') {
    																					if ($_GET['type']!='contact_dnepropetrovsk') {
    																						if ($_GET['type']!='contact_dnepropetrovsk_suvorova14') {
    																							if ($_GET['type']!='contact_donetsk') {
    																								if ($_GET['type']!='contact_donetsk_shorsa24') {
    																									if ($_GET['type']!='contact_zaporozhye') {
    																										if ($_GET['type']!='contact_zaporozhye_borodinskaya52') {
    																											if ($_GET['type']!='contact_sevastopol') {
    																												if ($_GET['type']!='contact_sevastopol_vosstavshuh4') {

    Сегодня работал с одним проектом, вот на что наткнулся.

    bondar, 05 Июля 2011

    Комментарии (16)
  6. Си / Говнокод #7057

    +137

    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
    int    bufImin[32]={ 4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000,  4000};
    int    bufImax[32]={20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000};
    double bufPmin[32]={    0,     0,     0,     0,     0,     0,     0,     0,     0,   315,     0,     0,     0,     0,     0,     0};
    double bufPmax[32]={    6,    10,     1,    10,    40,    10 ,   10,    10,    10,  -315,     0,     0,   100,   100,    10,  1000};
    
    /*...*/
    bufPmin[9]=(double)CR1_Lb1_4mA*5-500.0;
    bufPmax[9]=(double)CR1_Lb1_20mA*5-500.0;
    Presh[9]=CurrentToPresh(I_9, bufImax[9],bufImin[9],bufPmax[9],bufPmin[9]);
    
    bufPmin[10]=(double)CR1_Lb2_4mA*5-500.0;
    bufPmax[10]=(double)CR1_Lb2_20mA*5-500.0;
    Presh[10]=CurrentToPresh(I_10, bufImax[10],bufImin[10],bufPmax[10],bufPmin[10]);
    
    /*...*/
    
    bufPmax[10]=(double)CR5_Tg_max;
    Presh[15]==CurrentToPresh(I_15, bufImax[15],bufImin[15],bufPmax[15],bufPmin[15]);

    Разгребаю г*вно от предыдущего программиста...
    - зачем массивы на 32 элемента, если их всегда 16.
    - зачем массивы с одинаковыми данными.
    - зачем инициализировать массив числами, которые никогда не используются.
    - массивы используются только для передачи значений в функцию.
    - 17 строка. Это ж надо спутать индекс; как незаметно.
    - 18 строка. :) ==3
    - "Presh" отнюдь не значит "precious", как подумали б американцы. Это Pressure по своей сути.

    MereNonsense, 25 Июня 2011

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

    +160

    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
    public function getList($sort) {
            if ($sort == 'id')
                $select = $this->select()->order('id ASC');            
            if ($sort == 'id2')
                $select = $this->select()->order('id DESC');
            if ($sort == 'username')
                $select = $this->select()->order('username ASC');
            if ($sort == 'username2')
                $select = $this->select()->order('username DESC');
            if ($sort == 'firstname')
                $select = $this->select()->order('firstname ASC');
            if ($sort == 'firstname2')
                $select = $this->select()->order('firstname DESC');
            if ($sort == 'lastname')
                $select = $this->select()->order('lastname ASC');
            if ($sort == 'lastname2')
                $select = $this->select()->order('lastname DESC');
            if ($sort == 'lastdate')
                $select = $this->select()->order('lastdate ASC');
            if ($sort == 'lastdate2')
                $select = $this->select()->order('lastdate DESC');
            if ($sort == 'regdate')
                $select = $this->select()->order('regdate ASC');
            if ($sort == 'regdate2')
                $select = $this->select()->order('regdate DESC');
            if ($sort == 'city')
                $select = $this->select()->order('city ASC');
            if ($sort == 'city2')
                $select = $this->select()->order('city DESC');
            if ($sort == 'vote')
                $select = $this->select()->order('vote ASC');
            if ($sort == 'vote2')
                $select = $this->select()->order('vote DESC');
            $result = $this->fetchAll($select);
            return $result;
        }

    Кусочек кода, написанный в классической манере "if-else" для Zend Framework

    coderov, 20 Июня 2011

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

    +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
    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
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    <?php
    
    class CodeCounter {
        const MULTILINE_COMMENT = 0x01;
    
        private $dir = null;
        private $ext = null;
    
        public function __construct($dir = '.', $ext = '*') {
            $this->dir = $dir;
            if($ext == '*') {
                $this->ext = "/.*/si";
            } else {
                $e = explode('|', $ext);
                foreach($e as &$ext) {
                    $ext = trim($ext);
                    if($ext == '')
                        unset($ext);
                }
                $r = implode('|', $e);
                $this->ext = "/.*\.({$r})$/si";
            }
    
        }
    
        public function calculate() {
            $lines = 0;
            $args = func_get_args();
            if(count($args) == 0)
                $dir = $this->dir;
            else
                $dir = $args[0];
            if(file_exists($dir) && is_dir($dir)) {
                $list = scandir($dir);
                foreach($list as $item) {
                    if($item == '.' || $item == '..')
                        continue;
                    $fullItem = realpath($dir . DIRECTORY_SEPARATOR . $item);
                    if(is_dir($fullItem)) {
                        $lines += $this->calculate($fullItem);
                    } else {
                        if(preg_match($this->ext, $item)) {
                            echo "Calculating lines in {$fullItem}:  ";
                            $_lines = self::count($fullItem);
                            echo "{$_lines}\n";
                            $lines += $_lines;
                        }
                    }
                }
            }
            return $lines;
        }
    
        private static function count($file) {
            $lines = 0;
            $d = null;
            if(file_exists($file) && ($file = file($file))) {
                foreach($file as $line) {
                    $line = trim($line);
                    if($line == '')
                        continue;
                    if( substr($line, 0, 2) == '//' || //single line comment
                        substr($line, 0, 1) == '#'  || //single line comment
                        substr($line, 0, 2) == '<?' || //php open tag
                        substr($line, 0, 2) == '?>'    //php close tags
                    )
                        continue;
                    if(($pos = strpos('/*', $line)) !== false) {
                        if($pos == 0) {
                            if(strpos('*/', $line, $pos) === false) {
                                $d = self::MULTILINE_COMMENT;
                            }
                        } else {
                            $lines++;
                        }
                        continue;
                    }
                    if($d == self::MULTILINE_COMMENT) {
                        if(strpos('*/', $line) !== false) {
                            $d = null;
                        }
                        continue;
                    }
                    $lines++;
                }
            }
            return $lines;
        }
    }
    
    $counter = new CodeCounter('./amapys', 'php|js');
    $lines = $counter->calculate();
    echo "\nTotal: {$lines} lines\n";

    Автор: POPSuL
    Пхп-шники такие пхп-шники.
    ООП во все поля. Им неведом sed и awk.

    cutwater, 13 Июня 2011

    Комментарии (16)
  9. Lua / Говнокод #6809

    −93

    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
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    --загрузка шрифта
    MyFont = pge.font.load("verdana.ttf",12)
    
    --цвета шрифта
    white = pge.gfx.createcolor(255,255,255)
    green = pge.gfx.createcolor(0,255,0)
    
    --загрузка графики
    A01 = pge.texture.load("pics/A-01.png")
    A02 = pge.texture.load("pics/A-02.png")
    A03 = pge.texture.load("pics/A-03.png")
    A04 = pge.texture.load("pics/A-04.png")
    A05 = pge.texture.load("pics/A-05.png")
    A06 = pge.texture.load("pics/A-06.png")
    A07 = pge.texture.load("pics/A-07.png")
    A08 = pge.texture.load("pics/A-08.png")
    A09 = pge.texture.load("pics/A-09.png")
    A10 = pge.texture.load("pics/A-10.png")
    A11 = pge.texture.load("pics/A-11.png")
    A12 = pge.texture.load("pics/A-12.png")
    A13 = pge.texture.load("pics/A-13.png")
    A14 = pge.texture.load("pics/A-14.png")
    A15 = pge.texture.load("pics/A-15.png")
    A16 = pge.texture.load("pics/A-16.png")
    A17 = pge.texture.load("pics/A-17.png")
    A18 = pge.texture.load("pics/A-18.png")
    A19 = pge.texture.load("pics/A-19.png")
    A20 = pge.texture.load("pics/A-20.png")
    A21 = pge.texture.load("pics/A-21.png")
    A22 = pge.texture.load("pics/A-22.png")
    A23 = pge.texture.load("pics/A-23.png")
    A24 = pge.texture.load("pics/A-24.png")
    
    --переменная для счётчика
    index = 1
    
    
    while pge.running() do
    pge.controls.update()
    pge.gfx.startdrawing() -- начало рисования
    pge.gfx.clearscreen() -- очистка экрана
    if pge.controls.pressed(PGE_CTRL_DOWN) then
    index = index+1 -- увеличиваем index на 1
    end
    
    A01:activate()
    A01:draw(30,25) -- отрисовка первой картинки
    -- далее отрисовка последующих картинок в зависимости от значения переменной index
    	if index==2 then
    		pge.gfx.clearscreen()
    		A02:activate()
    		A02:draw(30,25)
    	end
    	if index==3 then
    		pge.gfx.clearscreen()
    		A03:activate()
    		A03:draw(30,25)
    	end
    	if index==4 then
    		pge.gfx.clearscreen()
    		A04:activate()
    		A04:draw(30,25)
    	end
    	if index==5 then
    		pge.gfx.clearscreen()
    		A05:activate()
    		A05:draw(30,25)
    	end
    	if index==6 then
    		pge.gfx.clearscreen()
    		A06:activate()
    		A06:draw(30,25)
    	end
    
    pge.gfx.enddrawing() -- конец отрисовки
    pge.gfx.swapbuffers()
    	if pge.controls.pressed(PGE_CTRL_START) then
    		break
    	end
    end

    Увидел и не смог не запостить
    Lua

    Werdn, 01 Июня 2011

    Комментарии (16)
  10. PHP / Говнокод #6734

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    $cd = strtotime($givendate);
    $newdate = date('Y-m-d H:i:s', mktime(date('H',$cd),
                       date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
                       date('d',$cd)+$day, date('Y',$cd)+$yr));

    kovel, 23 Мая 2011

    Комментарии (16)
  11. Java / Говнокод #6670

    +74

    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
    public boolean setBit(byte _position, boolean _state) {
    		if ( !valid ) {
    			LOG.error("value is INVALID");
    			
    			return false;
    		} else if ( _position<0 ) {
    			LOG.error("NEGATIVE _position");
    			
    			return false;
    		} else if ( _position > capacity ) {
    			LOG.warn("_position("+_position+") > cacity("+capacity+") "+
    					"for value "+this);
    			
    			return false;
    		}
    		
    		value|=( (_state ? 1 : 0) << (_position+1) );
    		
    		return true;
    }

    ога, разбежался

    ilardm, 14 Мая 2011

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