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

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

    +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
    there is a reason why opencart is the no.1 most used ecommerce solution in places like china and india, its the easiest code base to understand!
    
    --
    
    many apps servers! what does that mean? you mean different applications running from the same framework?
    you build each application starting from the index.php file and include what ever library classes you require.
    
    --
    
    "I agree with you that it's harder to write simple code, because REPEATING CODE IS HARD TO DEBUG HARD TO READ AND TO CORRECT. so it makes you waste a lot of time."
    
    this is what search and replace is for!

    Создатель опенкарта (Daniel Kerr) исходит на говно, много мякотки
    http://www.techchattr.com/never-use-opencart#comment-1151857248

    Fike, 22 Февраля 2015

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

    +51

    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
    //Sets the color(background and foreground)
    void Console::SetColor(){
        #ifdef _WIN32
            SetConsoleTextAttribute(hConsole, FGColor | BGColor);
        #else
            string clr = "\033[";
            clr += BGColor;
            clr += ";";
            clr += FGColor;
            clr += "m";
            cout << clr;
        #endif
    }

    Изменение цвета текста и фона консоли

    govnokod3r, 17 Февраля 2015

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

    +145

    1. 1
    2. 2
    char bStr[1000];
    strncpy(bStr, "  [\0", strlen("  [\0"));

    Потому что в man:
    Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null terminated.

    Yeiradohr, 13 Февраля 2015

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

    +98

    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
    switch (_viewerPanel.Modified)
    {
         case true:
             _viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
             _filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
             _fileChangeDictionary[_listOfRecords[index].FullName] = true;
             break;
         case false:
             _viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
             _filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
             _fileChangeDictionary[_listOfRecords[index].FullName] = false;
             break;
    }

    Удивительно, но это писал не индус...

    dvgarays, 09 Февраля 2015

    Комментарии (10)
  6. Assembler / Говнокод #17539

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    add ax,1 ; Добавляем в ax 1 (не знаю, почему он так сделал, МЕДЛЕННО И 3 БАЙТА), можно было же inc ax
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    add ax,1
    mov ax,9 ; А теперь я понял тщетность бытия и те потраченные байты выше.

    Самый лучший говнокод новичка, который я видел.

    Mihip, 28 Января 2015

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

    +95

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class ColorExtension
    	{
    		public static bool IsDarkColor(this Color color)
    		{
    			return (color.R & 255) + (color.G & 255) + (color.B & 255) < 3*256/2;
    		}
    	}

    x & 255 = ?, где x типа byte

    schecterXA, 22 Января 2015

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

    +152

    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
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    <?
    require_once('ittable.class.php');
    
    class ITForm extends ITTable
    {
    public function __construct($tbl)
    {
    parent::__construct($tbl);
    
    //путь с скрипту который удаляет файлы по tblname record_id filename
    $this->path2deletephp='/itcms4/ckeditor/delete.php';
    }
    
    
    public function generateFormData($i, $action, $head, $submitvalue='', $captcha=0)
    {
    global $itcmscfg;
    $form->submitvalue=htmlentities($submitvalue?$submitvalue:$head, ENT_NOQUOTES, 'UTF-8');
    $form->tbl = $this->tbl;
    if($this->files) $enctype='enctype="multipart/form-data"';
    $form->head = htmlentities($head, ENT_NOQUOTES, 'UTF-8');
    $form->begin = "<form  name='$this->tbl$i->id' id='$this->tbl$i->id' action='$action' method='post' $enctype>";
    $form->inputhidden .= "<input type='hidden' name='id' value='$i->id'><input type='hidden' name='referer' value='" . ($_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:'./') . "'>\n";
    
    if($action=='delete.php') {$form->disabled = 'disabled'; $OPERATION = UPDATABLE;}
    elseif($action=='insert.php') $OPERATION = INSERTABLE;
    elseif($action=='update.php') $OPERATION = UPDATABLE;
    else $OPERATION = UPDATABLE; 
    
      foreach($this->columns as $field=>$ftype)
      {
       $itforms = " $form->disabled name='$field' id='input-$field'" . $this->getITFormsAttr($field);
       $value = isset($i->$field) ? $i->$field : ($_GET[$field] ? $_GET[$field]: $ftype->Default);
       if(!$ftype->htmlcode) $value = htmlentities($value, ENT_QUOTES, 'UTF-8');
       $itcmscfg->cfgfile = intval($itcmscfg->cfgfile);
       if($ftype->Key=='UNI') $itforms .= " data-async='false' data-unique='{cfgfile:$itcmscfg->cfgfile, tblname:\"$this->tbl\", record_id:\"$i->id\"}'";
       
       if($ftype->visibility & HIDDEN){$form->inputhidden .= "<input type='hidden' $itforms value='$value'>"; continue;}
        
        //если поле не RADONLY, то проверить задан ли regexp и разрешена ли операция
       if( !($ftype->visibility & READONLY) )
        if(!$ftype->pattern || !($ftype->visibility & $OPERATION))
         continue;
       
       $form->inputs[$field]->name = "<label for='input-$field' id='label-$field'>$ftype->outputname</label>"; 
       
       //выводим элементы
       if($ftype->options)
       {
        $form->inputs[$field]->input = $ftype->options->html($field, " $form->disabled " . $this->getITFormsAttr($field), $value);
        if($ftype->options->type==OT_BINARY_CHECKBOX)
         $form->js .= "itform.setCheckboxProperty('$field', 'sum', '$ftype->minselected', '$ftype->maxselected');\n";
       }
       elseif($ftype->inputtype=='wysiwyg')
         $form->inputs[$field]->input = "<script src=/include/ckeditor/ckeditor.js></script>
                                         <textarea class='ckeditor' name='$field'>$value</textarea>";
       elseif($ftype->Type=='text')
        $form->inputs[$field]->input = "<textarea rows='10' cols='80' $itforms " . ($form->disabled?' readonly':'') . ">$value</textarea>";
       elseif($ftype->inputtype)
         $form->inputs[$field]->input = "<input type='$ftype->inputtype' value='$value' $itforms>";
       else
        $form->inputs[$field]->input =  "<input type='text' value='$value' $itforms>";  
    
       $f1 = $ftype->func;
       if(isset($f1))
        $form->inputs[$field]->input .=  (' ' . $f1($value));
    
     }//foreach
    
    
    if($this->files)
    {
     foreach($this->files as $k=>$o)
     {
      $itforms = "";
      //это только для action==insert.php можно, при редактирвоании не обязательно файл заливать
      $itforms .= ($o->required && $action=='insert.php') ? " data-min-length='1'" : '';
      $itforms .= $o->validExtentions ? " data-regexp='$o->validExtentions'" : '';
      if($o->help) $itforms .= " data-help='$o->help'";
      if($o->multiple)
       {
        $itforms .= ' multiple';
        $multiple = '[]';
       }
       else
        $multiple='';
     
      $outputname = htmlentities($o->outputname, ENT_NOQUOTES, 'UTF-8');  
      $form->inputs[$k]->name = "<label for='input-$k'>$outputname</label>";
      $form->inputs[$k]->input = "<input type='file' name='$k$multiple' id='input-$k' $itforms>";
     }//foreach
    
     if(intval($i->id))
      $form->files = $itcmscfg->fs->getFiles4TblRecord($this->tbl, $i->id);
    }//if
    
    return $form;
    }//fun

    itgovnokod, 19 Января 2015

    Комментарии (10)
  9. JavaScript / Говнокод #17397

    +158

    1. 1
    Function.prototype.apply.call(window.alert, window, ['alert'])

    А я чё? Я ничё...

    AjiTae, 01 Января 2015

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

    +156

    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
    foreach ($mass AS $productId => $colorsList)
            {
                foreach ($colorsList AS $colorId => $sizesList)
                {
                    foreach ($sizesList AS $sizeId => $options)
                    {
                        $this->setTable('shop_products')
                             ->update(array(
                                    'price' => $options['price']
                                ),
                                $this->getAdapter()->quoteInto('id = ?', $productId)
                             );
                        break;
                    }
                }
            }

    Автор пытается взять первый элемент многомерного массива вот такой конструкцией

    p0p, 26 Декабря 2014

    Комментарии (10)
  11. Python / Говнокод #17333

    −111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def parse(file):
        if 1==1: #вырвано из другого места, лень пробелы удалять
            if file:
                try:
                    doc = ET.parse(file)
                except IOError:
                    return HttpResponse(u'nofile')

    лол

    alexscrat, 18 Декабря 2014

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