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

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $c = (int)(bool)$_POST['chat'];
    
    // через сто строк
    
    $q = 'UPDATE ....., `chat`='.$c.' WHERE ....';

    интригующе

    jokz, 16 Сентября 2011

    Комментарии (3)
  3. Perl / Говнокод #7793

    −84

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $sth = $dbh->prepare("select *,DATE(DTime),DATE(RDTime),MONTH(DTime),DAY(DTime),HOUR(DTime),MINUTE(DTime),UNIX_TIMESTAMP(DTime) 
    from tt_list where Type!=0  $where order $order");
    ...
    if ($row->{'HOUR(DTime)'}<10) {$row->{'HOUR(DTime)'}="0$row->{'HOUR(DTime)'}"};
    if ($row->{'MINUTE(DTime)'}<10) {$row->{'MINUTE(DTime)'}="0$row->{'MINUTE(DTime)'}"};
    ...
    print "...<td width=60 nowrap><img src=../images/icon_clock.gif width=16 height=16 border=0>
     $row->{'HOUR(DTime)'}:$row->{'MINUTE(DTime)'}</td>...";

    Выводим время...

    Raynor, 07 Сентября 2011

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

    +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
    function addParam(iId)
    {   
        var sData = '';
    
        //Контрольная работа
        if (iId==1) 
            sData = '';
        // Реферат
        else if (iId==2) 
            sData = '';
        // Курсовая
        else if (iId==3) 
            sData = '';
        // Решение задач
        else if (iId==4) 
            sData = '';
        else {
            $('#addParam').hide().html('');
            return false;
        }
        
        $('#addParam').html('').append('<td colspan="2">'+sData+'</td>').show();
    }

    lot's of code, govnocode, govnocode, govnocode...

    kaspvar, 02 Сентября 2011

    Комментарии (3)
  5. Куча / Говнокод #7735

    +138

    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
    error LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class 
    std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class
     std::map<__int64,class k3bufferblock,struct std::less<__int64>,class std::allocator<struct 
    std::pair<__int64 const ,class k3bufferblock> > >,struct std::less<class std::basic_string<char,struct 
    std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class 
    std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class 
    std::map<__int64,class k3bufferblock,struct std::less<__int64>,class std::allocator<struct 
    std::pair<__int64 const ,class k3bufferblock> > > > > >,struct std::less<class 
    std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class 
    std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class 
    std::allocator<char> > const ,class std::map<class std::basic_string<char,struct 
    std::char_traits<char>,class std::allocator<char> >,class std::map<__int64,class k3bufferblock,struct 
    std::less<__int64>,class std::allocator<struct std::pair<__int64 const ,class k3bufferblock> > >,struct 
    std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 
    >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class 
    std::allocator<char> > const ,class std::map<__int64,class k3bufferblock,struct 
    std::less<__int64>,class std::allocator<struct std::pair<__int64 const ,class k3bufferblock> > > > > > 
    > > > k3entity_cache::buffercache" (?buffercache@k3entity_cache@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@V?$basic_string@DU?
    $char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@_JVk3bufferblock@@U?$less@_J@std@@V?$allocator@U?$pair@$$CB_JVk3bufferblock@@@std@@@3@@2@U?$less@V?
    $basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?
    $map@_JVk3bufferblock@@U?$less@_J@std@@V?$allocator@U?$pair@$$CB_JVk3bufferblock@@@std@@@3@@2@@std@@@2@@2@U?$less@V?$basic_string@DU?
    $char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@V?$basic_string@DU?
    $char_traits@D@std@@V?$allocator@D@2@@std@@V?$map@_JVk3bufferblock@@U?$less@_J@std@@V?$allocator@U?$pair@$$CB_JVk3bufferblock@@@std@@@3@@2@U?$less@V?
    $basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?
    $map@_JVk3bufferblock@@U?$less@_J@std@@V?$allocator@U?$pair@$$CB_JVk3bufferblock@@@std@@@3@@2@@std@@@2@@2@@std@@@2@@std@@A)

    CPPGovno, 02 Сентября 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function addNewUpload()
            {
                $('#button_'+i).remove();
                i++;
                $('<div id="field_'+i+'"><input id="file_'+i+'" name="file_'+i+'" type="file"><input type="button" value="+" id="button_'+i+'" onClick="addNewUpload()"></div>').appendTo("#loadmore_files");
                $('#hidden_count').attr('value', i);
            }

    Учись, студент.

    varg242, 23 Августа 2011

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

    −92

    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
    def clean_node(node, debug=False):
        """
            Этот пример скопипащен из книги
            "Как не должен выглядеть код"
        """
        if node['sub']:
            sub = []
            num = 1
            for item in node['sub']:
                i = clean_node(item, debug)
                if i:
                    sub.append(i)
                    num += i['num']
            node['sub'] = sub
            node['num'] = num
        else:
            node['num'] = 1
        if node['deleted']:
            if node['sub']:
                return node
        else:
            return node
    
        return None

    Мне достался в наследство большой проект, в котором порой встречается вот такое. Единственное, что радует это подобные комментарии )

    kvex, 17 Августа 2011

    Комментарии (3)
  8. Python / Говнокод #7541

    −175

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if request.path == '/':
            thread_list = ThreadBlock.objects.all()
        else:
            thread_nomer = re.search( r'/\d*/', request.path ).group()[1:-1]
            thread_list = ThreadBlock.objects.filter(id=int(thread_nomer))

    Бидон, джанга, уеб.

    хуита, 14 Августа 2011

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

    +147

    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
    $offset = intval($_POST['offset']);  
            $sql    = mysql_query("SELECT * FROM `test` ORDER BY id DESC LIMIT $offset, 5");  
            if(mysql_num_rows($sql)>0) { 
            while($post = mysql_fetch_assoc($sql)){  
                foreach($post AS $n=>$m){  
                    $post[$n] = utf8_encode($m); 
                }  
                $json['more'][] = $post; # чтобы было легче до 
            }   
             if(count($json['more']))  { 
                 $json['ok'] = '1';  
             } else {  
                 $json['ok'] = '0'; 
             }      
            } else { 
               $json['ok']='3'; 
            }     
            mysql_close($db);  
        
    echo json_encode($json);

    Индусский метод выборки записей из таблицы.

    fqnm, 11 Августа 2011

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

    +161

    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
    class Session {
    	function sess_write() {
    		/*запись данных сессии в бд ($this->userdata)*/
    	}
    
    	function set_userdata($newdata = array(), $newval = '') {
    		if (count($newdata) > 0) {
    			foreach ($newdata as $key => $val) {
    				$this->userdata[$key] = $val;
    			}
    		}
    		$this->sess_write();
    	}
    
    	function unset_userdata($newdata = array()) {
    		if (count($newdata) > 0) {
    			foreach ($newdata as $key => $val) {
    				unset($this->userdata[$key]);
    			}
    		}
    		$this->sess_write();
    	}
    
    	function userdata($item) {
    		return (!isset($this->userdata[$item])) ? false : $this->userdata[$item];
    	}
    }

    говнокод изысканный.
    ЗЫДН: в таком случае $this->sess_write() правильней делать в деструкторе

    DrFreez, 06 Августа 2011

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

    +125

    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
    for(int i = 0; i<et.Days.Count; i++)
                {
                if (et.Days[i].WorkDay.Day == colno - 1)
                    {
                    EmplTabelDays etd = et.Days[i];
    
                    switch (colno)
                        {
                        case 0:
                            break;
                        case 1:
                            break;
                        default:
                                {
                                //pinc.TypeIncome = (IncomeItem)
                                //((TreeNodeHelper)(income_grid.Rows[e.RowIndex].Cells[e.ColumnIndex]).Value).Value;
    
                                //etd.WorkStatus = (WorkStatus)((DataGridViewCell)(WorkDaysGrid.Rows[recno].Cells[colno]).Value).Value;
    
                                DataGridViewCell cell = WorkDaysGrid.Rows[recno].Cells[colno];
                                if (SpecialButton.Checked == false)
                                    {
                                    etd.TypeWorkHours = 8;
    //еще 100500 строк гавнокода...
    
                                    if (cell.Value == "8")
                                        etd.WorkStatus.Id = 1;
                                    if (cell.Value == "-")
                                        etd.WorkStatus.Id = 2;
                                    if (cell.Value == "О")
                                        etd.WorkStatus.Id = 3;
                                    if (cell.Value == "Б")
                                        etd.WorkStatus.Id = 4;
                                    if (cell.Value == "Р")
                                        etd.WorkStatus.Id = 5;
                                    if (cell.Value == "П")
                                        etd.WorkStatus.Id = 6;
                                    if (cell.Value == "А")
                                        etd.WorkStatus.Id = 7;
                                    if (cell.Value == "Г")
                                        etd.WorkStatus.Id = 8;
                                    if (cell.Value == "С")
                                        etd.WorkStatus.Id = 9;
    
                                    }

    Найдено в коде программы табель для бухгалтерии.
    Заполнение справочника с типами дней на основе ячеек грида.
    KeyboardInheritance в чистом виде.

    etcshadow, 05 Августа 2011

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