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

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

    +114

    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
    if (FindNumber.Text.Length > 0)
            {
                string Num = FindNumber.Text;
                FindNom FN=new FindNom();
                Num = FN.ReplFindNumer(Num);
                if (Num != null && Num.Length > 0)
                {
                    StringBuilder sb = new StringBuilder(Num.Length);
                    foreach (char c in Num)
                    {
                        if (Char.IsControl(c) == true)
                            continue;
                        sb.Append(c);
                    }
                    Num = sb.ToString();
                }

    я пришел работать в фирму на развитие проекта интернет магазина, в ней уже работает программист, работает 6 лет!
    я открыл его код и увидел ЭТО. причем чувак щеки от важности раздувает

    t13ka, 04 Апреля 2012

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void convert_bglfile(std::string infile, std::string source_charset, std::string target_charset)
    {
        std::string outfile;
        const char *p = infile.c_str();
        const char *p1 = strrchr(p, '.');
        if (p1) {
            outfile.assign(p, p1-p);
        } else {
            outfile = infile;
        }
    ...

    Из опенсорсного словаря StarDict. Товарисч на форуме написал, что не комилируется - не иклюдился cstring. А там такое :o

    myaut, 03 Апреля 2012

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

    +142

    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
    else
                    {
                      if(i == 0)
                      {
                        if(j == 0)
                        {
                          if(cells[i][j+1].label == 1)
                          {
                            cells[i][2].label = 2;
                            cells[i][2].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i+1][j].label == 1)
                          {
                            cells[2][j].label = 2;
                            cells[2][j].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i+1][j+1].label == 1)
                          {
                            cells[2][2].label = 2;
                            cells[2][2].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }
                        }else if(j == 1)
                        {
                          if(cells[i][j-1].label == 1)
                          {
                            cells[i][2].label = 2;
                            cells[i][2].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i+1][j].label == 1)
                          {
                            cells[2][j].label = 2;
                            cells[2][j].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i][j+1].label == 1)
                          {
                            cells[0][0].label = 2;
                            cells[0][0].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }
                        }else
                        {
                          if(cells[i][j-1].label == 1)
                          {
                            cells[i][0].label = 2;
                            cells[i][0].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i+1][j].label == 1)
                          {
                            cells[2][2].label = 2;
                            cells[2][2].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }else if(cells[i+1][j-1].label == 1)
                          {
                            cells[2][0].label = 2;
                            cells[2][0].empty = false;
                            playerIsTurn = true;
                            numTurns++;
                          }
                        }
                      }else if(cells[i-1][j].label == 1)

    часть 3 полный код можно посмотреть на http://www.gamedev.ru/projects/forum/?id=160346&page=2

    dani4, 01 Апреля 2012

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

    +141

    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
    else if(numTurns != 1)
          {
            {
              for(int i = 0; i < 3; i++)
              {
                for(int j = 0; j < 3; j++)
                {
                  if(cells[i][j].label == 1)
                  {
                    if(i == 1 && j == 1)
                    {
                      if(cells[i][j-1].label == 1)
                      {
                        cells[i][j+1].label = 2;
                        cells[i][j+1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i][j+1].label == 1)
                      {
                        cells[i][j-1].label = 2;
                        cells[i][j-1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i-1][j].label == 1)
                      {
                        cells[i+1][j].label = 2;
                        cells[i+1][j].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i+1][j].label == 1)
                      {
                        cells[i-1][j].label = 2;
                        cells[i-1][j].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i-1][j-1].label == 1)
                      {
                        cells[i+1][j+1].label = 2;
                        cells[i+1][j+1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i-1][j+1].label == 1)
                      {
                        cells[i+1][j-1].label = 2;
                        cells[i+1][j-1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i+1][j+1].label == 1)
                      {
                        cells[i-1][j-1].label = 2;
                        cells[i-1][j-1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }else if(cells[i+1][j-1].label == 1)
                      {
                        cells[i-1][j+1].label = 2;
                        cells[i-1][j+1].empty = false;
                        playerIsTurn = true;
                        numTurns++;
                      }
                    }

    часть 2

    dani4, 01 Апреля 2012

    Комментарии (1)
  6. PHP / Говнокод #9778

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    public function session_set_lifetime($time){
      /*NOT USED with cookies, can be used with sessions*/
      return null;
    }

    тотже мастер класа что и тут:
    http://govnokod.ru/9765/
    http://govnokod.ru/9777/

    fafik91, 27 Марта 2012

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

    +114

    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
    99. 99
    private void button8_Click(object sender, EventArgs e)
            {
    
                string fn = "";
                string st = "";
                string value = "";
                string dirfile = "";
                StreamWriter sw;
    
    
                if (textBox1.Text != "")
                {
                    dirfile = textBox1.Text + "\\" + GetFileName(openFileDialog1.FileName) + comboBox1.SelectedValue.ToString() + ".csv";
                    sw = new StreamWriter(dirfile, false, System.Text.Encoding.UTF8);
                }
                else
                {
                    sw = new StreamWriter(openFileDialog1.FileName + comboBox1.SelectedValue.ToString() + ".csv", false, System.Text.Encoding.UTF8);
                }
    
                // Создаем колонки
    
                for (int cl = 0; cl < dt.Columns.Count; cl++)
                {
                    fn = dt.Columns[cl].ColumnName;
    
    
                    if (cl == 0)
                    {
                        st =  fn.Replace("\n", "").Replace(";", "");
                    }
                    else
                    {
                        st += ";" +  fn.Replace("\n", "").Replace(";", "");
                    }
    
    
                }
                sw.WriteLine(st);
    
    
                progressBar1.Minimum = 1;
                progressBar1.Maximum = dt.Rows.Count;
    
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    progressBar1.Value = i + 1;
    
                    Application.DoEvents();
    
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        value = dt.Rows[i][j].ToString();
    
                        if (value == "") { value = " "; }
    
                        try
                        {
                            Convert.ToInt16(value);
                            if (j == 0)
                            {
                                st = value.Replace("\n", "").Replace(";", "");
                            }
                            else
                            {
    
                                st += ";" + value.Replace("\n", "").Replace(";", "");
                            }
                        }
                        catch (System.FormatException exp)
                        {
                            if (j == 0)
                            {
                                st =  value.Replace("\n", "").Replace(";", "");
    
                            }
                            else
                            {
    
                                st += ";" +  value.Replace("\n", "").Replace(";", "") ;
                            }
                        }
                        catch (OverflowException oe)
                        {
                            if (j == 0)
                            {
                                st = value.Replace("\n", "").Replace(";", "");
                            }
                            else
                            {
    
                                st += ";" + value.Replace("\n", "").Replace(";", "");
                            }
                        }
                    }
                    sw.WriteLine(st);
                }
                sw.Close();
                MessageBox.Show("Ok");

    досталось в наследство, сохранение DataTable в CSV :)

    Lokich, 26 Марта 2012

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

    +109

    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
    public static MyResultData SqlReturnDataset(string sql, string connection)
                {
                    MyResultData result = new MyResultData();
                    try
                    {
                        MySql.Data.MySqlClient.MySqlConnection connRC = new MySql.Data.MySqlClient.MySqlConnection(connection);
                        MySql.Data.MySqlClient.MySqlCommand commRC = new MySql.Data.MySqlClient.MySqlCommand(sql, connRC);
                        connRC.Open();
    
                        try
                        {
                            MySql.Data.MySqlClient.MySqlDataAdapter AdapterP = new MySql.Data.MySqlClient.MySqlDataAdapter();
                            AdapterP.SelectCommand = commRC;
                            DataSet ds1 = new DataSet();
                            AdapterP.Fill(ds1);
                            result.ResultData = ds1.Tables[0];
                        }
                        catch (Exception ex)
                        {
                            result.HasError = true;
                            result.ErrorText = ex.Message;
                        }
                        connRC.Close();
                    }
                    catch (Exception ex)//Этот эксепшн на случай отсутствия соединения с сервером.
                    {
                        result.ErrorText = ex.Message;
                        result.HasError = true;
                    }
                
                    return result;
    
                }

    Govnisti_Diavol, 26 Марта 2012

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

    +114

    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
    private int GetInsertion(byte[] firstArr, byte[] secondArr)
            {
                int result = -1;
                int counter = 0;
                if (firstArr.Count() >= secondArr.Count())
                {
                    for (int i = 0; i < firstArr.Count(); i++)
                    {
                        if (firstArr[i] == secondArr[counter])
                        {
                            counter++;
                            if (counter == secondArr.Count())
                            {
                                result = i - counter + 1;
                                break;
                            }
                        }
                        else
                        {
                            counter = 0;
                        }
                    }
                }
                return result;
            }

    находит индекс вхождения одного массива в другой

    razzil, 23 Марта 2012

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

    −124

    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
    if (param.visible == 'cache')
    {
    	while (parseCacheResult.indexOf('$data') != -1) parseCacheResult = parseCacheResult.replace('$data', '_dataCache');
    	while (parseCacheResult.indexOf('$name') != -1) parseCacheResult = parseCacheResult.replace('$name', param.nameParam);
    	while (parseCacheResult.indexOf('$type') != -1) parseCacheResult = parseCacheResult.replace('$type', param.type);
    } else if (param.visible == 'static')
    {
    	while (parseStaticResult.indexOf('$data') != -1) parseStaticResult = parseStaticResult.replace('$data', '_dataStatic');
    	while (parseStaticResult.indexOf('$name') != -1) parseStaticResult = parseStaticResult.replace('$name', param.nameParam);
    	while (parseStaticResult.indexOf('$type') != -1) parseStaticResult = parseStaticResult.replace('$type', param.type);
    }
    else
    {
    	while (parseDynamicResult.indexOf('$data') != -1) parseDynamicResult = parseDynamicResult.replace('$data', '_dataDynamic');
    	while (parseDynamicResult.indexOf('$name') != -1) parseDynamicResult = parseDynamicResult.replace('$name', param.nameParam);
    	while (parseDynamicResult.indexOf('$type') != -1) parseDynamicResult = parseDynamicResult.replace('$type', param.type);
    }
    
    while (setResult.indexOf('$name') != -1) setResult = setResult.replace('$name', param.nameParam);
    while (setResult.indexOf('$type') != -1) setResult = setResult.replace('$type', param.type);
    while (setResult.indexOf('$className') != -1) setResult = setResult.replace('$className', className);
    
    while (getResult.indexOf('$name') != -1) getResult = getResult.replace('$name', param.nameParam);
    while (getResult.indexOf('$type') != -1) getResult = getResult.replace('$type', param.type);
    
    while (varResult.indexOf('$name') != -1) varResult = varResult.replace('$name', param.nameParam);
    while (varResult.indexOf('$type') != -1) varResult = varResult.replace('$type', param.type);
    while (varResult.indexOf('$comment') != -1) varResult = varResult.replace('$comment', param.comment);
    while (varResult.indexOf('$default') != -1) varResult = varResult.replace('$default', param.defaultValue);
    
    }
    
    var result : String = baseTemplate;
    while (result.indexOf('$className') != -1) result = result.replace('$className', className);
    while (result.indexOf('$comment') != -1) result = result.replace('$comment', comment);
    while (result.indexOf('$baseClass') != -1) result = result.replace('$baseClass', baseClass);
    while (result.indexOf('$singleton_1') != -1) result = result.replace('$singleton_1', singl_1);
    while (result.indexOf('$singleton_2') != -1) result = result.replace('$singleton_2', singl_2);
    
    result = result.replace('$var', varResult);
    result = result.replace('$set', setResult);
    result = result.replace('$get', getResult);
    result = result.replace('$parseDynamic', parseDynamicResult);
    result = result.replace('$parseStatic', parseStaticResult);
    result = result.replace('$parseCache', parseCacheResult);
    result = result.replace('$values', valuesList);
    result = result.replace('$dynamic', data.dynamicClass == 1 ? 'dynamic' : '');

    Как то родилось в процессе допилок кодогена )

    kyzi007, 23 Марта 2012

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

    +79

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if ("5".equals(pid)) {
    
    } else {
    	if ("1".equals(pid) || "4".equals(pid)) {
    		type = "fl";
    	} else if ("6".equals(pid)){
    		type = "nw";
    	}else {
    		type = "ul";
    	}
    }

    Из базы формируется дерево элементов для меню. Там же есть какая-то сортировка. Меняем в базе сортировку, а все работает по-старому. Лезем копать и находим.

    akkuch, 23 Марта 2012

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