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

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

    +116

    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
    int min = 32000;
    int max = 0;
    int mind = 0;
    int i;
    int j;
    double t;
    double f;
    int p = 0;
    double[] x = new double[4];
    double[] k = new double[4];          //массив для К
    double[,] s = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[,] a = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[] b = { 120, 280, 240, 360 };
    double[] c = { 10, 14, 12, 0, 0, 0, 0 };
    double[] r = new double[7];
    double[,] s1 = new double[4, 7];
    for ( i = 0; i < 4; i++)
    {
        for (j = 0; j < 7; j++)
            Console.Write(a[i, j] + "\t");
        Console.WriteLine("\n");
     
    }
    for (j = 0; j < 4; j++)
        Console.Write(b[j] + "\t");
    Console.WriteLine();
     
    for (j = 0; j < 7; j++)
        Console.Write(c[j] + "\t");
    Console.WriteLine();
    Console.WriteLine();
      //первая итерация         
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    if (a[i, j] != 0)
        s[i, j] = b[i] / a[i, j];
     
    Console.Write(s[i, j] + "\t");
            }
            Console.WriteLine();
        }
        for (j = 0; j < 7; j++)
        {
            for (i = 0; i < 4; i++)
            {
    if (s[i, j] < min)
        min = Convert.ToInt32(s[i, j]);
     
     
     
            }
            r[j] = min * c[j];
            Console.Write(r[j] + "\t");
     
        }
        Console.WriteLine();
        for (j = 0; j < 7; j++)
        {
            if (r[j] > max)
            {
    max = Convert.ToInt32(r[j]);
    p = j;
     
     
     
            }
     
        }
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    k[i] = a[i, p];
            }
        }
        min = 32000;
     
        for (i = 0; i < 4; i++)
        {
            if (s[i, p] < min)
            {
    min = Convert.ToInt32(s[i, p]);
    mind = i;
     
            }
            Console.WriteLine();
     
     
        }
        t = a[mind, p];
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    s[i, j] = a[i, j];
            }
        }

    Полная версия: http://pastebin.com/p36MWPXR
    Этот код был выложен на одном из форумов с просьбой объяснить "Что делает приложенный код".
    Посмотрев строчек 50 из почти 300, понял, что мои нервы дороже этого говнокода.
    Форматирование практически полностью сохранено.
    Был один интересный пост к этой теме: "могу ошибаться, но по-моему - позорит автора", согласен с мнением автора этого поста.

    FutureCome, 24 Марта 2012

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

    +116

    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
    private void label1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Данная программа вычисляет\nнаибольший общий делитель.");
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (Convert.ToInt32(textBox1.Text) >= Convert.ToInt32(textBox2.Text))
                {
                    for (int i = Convert.ToInt32(textBox1.Text); i > 0; i--)
                    {
                        if (Convert.ToInt32(textBox1.Text) % i == 0)
                        {
                            if (Convert.ToInt32(textBox2.Text) % i == 0)
                            {
                                label2.Text = "НОД = " + Convert.ToString(i);
                                break;
                            }
                        }
                    }
                }
                else
                    for (int i = Convert.ToInt32(textBox2.Text); i > 0; i--)
                    {
                        if (Convert.ToInt32(textBox2.Text) % i == 0)
                        {
                            if (Convert.ToInt32(textBox1.Text) % i == 0)
                            {
                                label2.Text = "НОД = " + Convert.ToString(i);
                                break;
                            }
                        }
                    }
            }

    Программа с одного форума

    P4R4, 12 Марта 2012

    Комментарии (2)
  4. Java / Говнокод #9632

    +116

    1. 1
    return Long.parseLong(content.substring(content.lastIndexOf('/' + 1)));

    Пришлось поразмыслить, почему не работает.

    someone, 09 Марта 2012

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

    +116

    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
    class MyClass
    {
      private List<MyObject> _collection = new List<MyObject>();
      public int SelectedObjectIndex { get; set; }
    	
      private void SelectionChanged( List<MyViewObject> selectedObjects )
      {
        bool bFound = false;
    
        foreach (MyViewObject item in objects)
        {
          if (!bFound)
          {
            for (int i = 0; i < _collection.Count; i++)
            {
              if (item.Tag != null && item.Tag is MyObject)
              {
                if (_collection[i] == item.Tag)
                {
                  this.SelectedObjectIndex = i;
                  bFound = true;
                  break;
                }
              }
            }
          }
          else
          {
            break;
          }
        }
    
        if (!bFound)
        {
          SelectedObjectIndex = -1;
        }
      }
    }

    Просто кладезь какой-то.
    Я переделал исходный код, чтобы было понятнее кто здесь кому и не нужно было разбираться со сложной структурой классов, которая используется в исходнике.
    Все имена классов вымышленные, на них не нужно обращать внимание - все лишь для демонстрации подхода к построению циклов и поиску объектов в коллекциях.

    ICELedyanoj, 17 Февраля 2012

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

    +116

    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
    bool IsAdd = false;
    
    
                if (EditAnalysisTable.Rows.Count == 1)
                {
                    if (EditAnalysisTable.Rows[0][4].ToString() == string.Empty)
                    {
                        drow = EditAnalysisTable.Rows[0];
                    }
                    else
                    {
                        IsAdd = true;
                    }
                }
                else
                {
                    IsAdd = true;
                }
                if (IsAdd)
                {
                    drow = EditAnalysisTable.NewRow();
                    EditAnalysisTable.Rows.Add(drow);
                }

    Indian style: у них свои законы логики

    Nataly, 17 Февраля 2012

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    IGridCell IGridControl.this[int columnIndex, int rowIndex]
            {
                get { return Cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex); }
                set
                {
                    cells.Remove(cells.Single(c => c.OwningRow.Index == rowIndex && c.OwningColumn.Index == columnIndex));
                    cells.Add(value);
                }
            }

    вот такие вот индексаторы

    Ccik, 10 Ноября 2011

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

    +116

    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
    <Grid Grid.Row="2" Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[0]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[1]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[2]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[3]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[4]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[5]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[6]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[7]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[8]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[9]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[10]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[11]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[12]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[13]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[14]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[15]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[16]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[17]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[18]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[19]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[20]}"/>            
            </Grid>

    legat, 22 Октября 2011

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

    +116

    1. 1
    2. 2
    repositoryBugzilla.Open();
    repositoryBugzilla.Close();

    Вот такой код я нашел у себя в проекте.

    abbbbbbbbbb, 23 Августа 2011

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if ( check < 50000 ) {
        primaryAnimation = primaryAnimation;
    } else {
        int ani = (check - 50000) / 100;
        primaryAnimation = _OptionalAnimations["Run"][ani];
     }

    Найдено в недрах загрузчика MD2-моделек для XNA.

    RaZeR, 23 Июня 2011

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

    +116

    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
    IList<Hashtable> records = crit.List<Hashtable>();
    Guid[] personsId = records.Select(item => (Guid)item["PersonID"]).Distinct().ToArray();
    List<EmployeeData> empDatas = new List<EmployeeData>();
    
    foreach(Guid personId in personsId) {
    	IEnumerable<Hashtable> employeeRecords = records.Where(item => (Guid)item["PersonID"] == personId);
    	Hashtable employeeRecord = employeeRecords.FirstOrDefault(item => !(bool)item["IsLoad"] || (DateTime)item["EventDate"] == employeeRecords.Max(unit => (DateTime)unit["EventDate"]));
    
    	Hashtable employeeRecordAddition = new GenericNHibernateDao<BaseDocument>().CreateCriteria()
    		.CreateAlias("Department", "department")
    		.CreateAlias("Employee", "employee")
    		.CreateAlias("WorkDescription.Schedule", "schedule", JoinType.LeftOuterJoin)
    		.CreateAlias("WorkDescription.EmployeeApperance", "employeeApperance", JoinType.LeftOuterJoin)
    		.Add(Restrictions.Eq("EmployeeStamp.TabNo", employeeRecord["TabNo"]))
    		.Add(Restrictions.Eq("IsHalf", false))
    	...
    }

    No comments %)

    Guid, 12 Мая 2011

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