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

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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    mainDays = 0;
    
    for (var d = emplDoc.EventDate.AddMonths(1).AddDays(-1).Date; d <= emplDoc.DateEndWork.Date; d = d.AddMonths(1)) {
          mainDays += 2;
    }

    Guid, 11 Мая 2011

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

    +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
    var
        s1:string;
        i:integer;
    const
        m=50;
    begin
        write ('Введите строку: ');
        for i:=1 to m do
            begin
                 write ('s1[',i,']');
                 readln (s1[i]);
            end;
        writeln ('Длина строки: ', length(s1));
    end.

    Это Pascal. Вот так студенты физмата вводят строку, а потом считают ее длину.

    nanovsky, 28 Апреля 2011

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

    +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
    public struct RowForReportBookRecordIssue
    	{
    		public string Column1 { get; set; }
    		public string Column2 { get; set; }
    		public string Column3 { get; set; }
    		public string Column4 { get; set; }
    		public string Column5 { get; set; }
    		public string Column6 { get; set; }
    		public string Column7 { get; set; }
    		public string Column8 { get; set; }
    		public string Column9 { get; set; }
    		public string Column10 { get; set; }
    	}

    Использование соответствующее:
    RowForReportBookRecordIssue.Column1 = ...; RowForReportBookRecordIssue.Column2 = ...;
    Даже страшно, если что-то придется править... :(

    fr0mrus, 12 Апреля 2011

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

    +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
    // Установка обработкчиков событий
                tbTitle.TextChanged += (x, y) => _target.Title = tbTitle.Text;
                cbContractorType.SelectedIndexChanged += (x, y) => _target.ContractorType = cbContractorType.SelectedIndex;
                tbFullTitle.TextChanged += (x, y) => _target.Title = tbFullTitle.Text;
                tbINN.TextChanged += (x, y) => _target.INN = tbINN.Text;
                // Для физ. лица
                dtpBirthDate.ValueChanged += (x, y) => _target.birthDate = dtpBirthDate.Value;
                tbPassportSeria.TextChanged += (x, y) => _target.PassportSeria = tbPassportSeria.Text;
                tbPassportNumber.TextChanged += (x, y) => _target.PassportNumber = tbPassportNumber.Text;
                dtpPassportDateRegistred.ValueChanged += (x, y) => _target.PassportDateRegistred = dtpPassportDateRegistred.Value;
                tbPassportOrganizationRegistred.TextChanged += (x, y) => _target.PassportOrganizationRegistred = tbPassportOrganizationRegistred.Text;
                tbRegistredPassportAddress.TextChanged += (x, y) => _target.RegistredPassportAddress = tbRegistredPassportAddress.Text;
                // Для юр лица
                tbOgranizationJuridicalAddress.TextChanged += (x ,y) => _target.OgranizationJuridicalAddress = tbRegistredPassportAddress.Text;
                tbOrganizationMainBankAcouuntNumber.TextChanged += (x, y) => _target.OrganizationMainBankAcouuntNumber = tbOrganizationMainBankAcouuntNumber.Text;
                tbOrganizationKPP.TextChanged += (x, y) => _target.OrganizationKPP = tbOrganizationKPP.Text;
                tbOrganizationOGRNIP.TextChanged += (x, y) => _target.OrganizationOGRNIP = tbOrganizationOGRNIP.Text;
                tbOrganizationIFNS.TextChanged += (x, y) => _target.OrganizationIFNS = tbOrganizationIFNS.Text;
                tbOrganizationOKATO.TextChanged += (x, y) => _target.OrganizationOKATO = tbOrganizationOKATO.Text;
                tbOrganizationOKPO.TextChanged += (x, y) => _target.OrganizationOKPO = tbOrganizationOKPO.Text;

    У меня денюха поэтому решил отмаппить форму по новому

    glilya, 10 Апреля 2011

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

    +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
    /// <summary> 
    /// Сохраняет элементы справочника
    /// </summary>
    public IEnumerable SaveBookElements(IList elements) {
    	IList result = null;
    
    	try {
    		if (elements != null && elements.Count > 0) {
    			if (elements.GetType().GetGenericArguments().Length == 1 && elements[0].GetType() != elements.GetType().GetGenericArguments()[0]) {
    				var mi = typeof(BooksWorker).GetMethod("SaveTypedBookElements", BindingFlags.NonPublic | BindingFlags.Instance)
    					.MakeGenericMethod(new[] { elements[0].GetType() });
    
    				var casted = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(new[] { elements[0].GetType() }));
    
    				foreach (var t in elements) {
    					casted.Add(t);
    				}
    
    				result = mi.Invoke(this, new object[] { casted }) as IList;
    			}
    		}
    	}
    	catch (Exception ex) {
    		throw new ApplicationException("Ошибка!", ex);
    	}
    
    	return result;
    }

    Автор проникся рефлексией :-!

    Guid, 31 Марта 2011

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

    +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
    // Method that returns anonymous type as object
    object ReturnAnonymous() {
      return new { City="Prague", Name="Tomas" };
    }
    
    void Main() {
      // Get instance of anonymous type with 'City' and 'Name' properties
      object o = ReturnAnonymous();
    
      // This call to 'Cast' method converts first parameter (object) to the
      // same type as the type of second parameter - which is in this case 
      // anonymous type with 'City' and 'Name' properties
      var typed = Cast(o, new { City="", Name="" });
      Console.WriteLine("{0}, {1}", typed.City, typed.Name)
    }
    
    // Cast method - thanks to type inference when calling methods it 
    // is possible to cast object to type without knowing the type name
    T Cast<T>(object obj, T type) {
      return (T)obj;
    }

    via http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/c1c179bb-ea88-4633-970a-947f0dd1e71f/

    Jopa123, 18 Марта 2011

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

    +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
    if (rbNewPackage.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id_user == ent.id
                                             select recb.date).Max() && r.id_status == 1
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbCancelled.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id_user == ent.id
                                             select recb.date).Max() && r.id_status == 5
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbConditional.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id == rp.id
                                             select recb.date).Max() && r.id_status == 3
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbOfficial.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id == rp.id
                                             select recb.date).Max() && r.id_status == 4
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }

    говногод моего бывшего коллеги по работе))

    slavenin, 02 Марта 2011

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

    +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
    public static class ControlManager
        {
            public static UIElement GetControlByName(UIElement control, string name)
            {
                if (EntityType.GetValue(control, "Name").Equals(name))
                    return control;
                if (EntityType.IsProperty(control, "Children"))
                {
                    foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
                    {
                        if (EntityType.GetValue(element, "Name").Equals(name))
                            return element;
                        var temp = GetControlByName(element, name);
                        if (temp != null)
                            return temp;
                    }
                }
                if (EntityType.IsProperty(control, "Child"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "Child");
                    if (EntityType.GetValue(element, "Name").Equals(name))
                        return element;
                    var temp = GetControlByName(element, name);
                    if (temp != null)
                        return temp;
                }
                if (EntityType.IsProperty(control, "SelectionElement"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
                    if (EntityType.GetValue(element, "Name").Equals(name))
                        return element;
                    var temp = GetControlByName(element, name);
                    if (temp != null)
                        return temp;
                }
                return null;
            }
    
            public static UIElement GetControlByType(UIElement control, Type type)
            {
                if (control.GetType() == type)
                    return control; 
                if (EntityType.IsProperty(control, "Children"))
                {
                    foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
                    {
                        if (element.GetType() == type)
                            return element;
                        var temp = GetControlByType(element, type);
                        if (temp != null)
                            return temp;
                    }
                }
                if (EntityType.IsProperty(control, "Child"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "Child");
                    if (element.GetType() == type)
                        return element;
                    var temp = GetControlByType(element, type);
                    if (temp != null)
                        return temp;
                }
                if (EntityType.IsProperty(control, "SelectionElement"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
                    if (element.GetType() == type)
                        return element;
                    var temp = GetControlByType(element, type);
                    if (temp != null)
                        return temp;
                }
                return null;
            }
        }

    Автор тот же.
    Этот код пошатнул мою психику. А может так и надо. а?
    всё-таки stringly-static programming....

    tubus, 15 Февраля 2011

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

    +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
    namespace Containers
    {
        public class TBinaryWaitingQueue<TItem> where TItem : struct
        {
            private readonly TBinaryQueue<TItem> _queue;
            TBinaryWaitingQueue(int amountOfitem)
            {
                _queue = new TBinaryQueue<TItem>(amountOfitem);
            }
    
            public void Enqueue(TItem[] items)
            {
                throw new NotImplementedException();
            }
    
            public void Enqueue(TItem[] items, int beginItem, int amountOfItem)
            {
                throw new NotImplementedException();
            }
    
            public void Dequeue(TItem[] items, int beginItem, int amountOfItem)
            {
                throw new NotImplementedException();
            }
    
            public TItem[] Dequeue(int amountOfItem)
            {
                throw new NotImplementedException();
            }
        }
    }

    Досталось в наследство от предков. Этому коду уже года 4.

    Говногость, 03 Февраля 2011

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

    +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
    public class TObjects
    	{
    		public delegate T DeferredConstruction<out T>();
    
    		public static void Dispose<T>(ref T objectForDispose)
    		{
    			var typeOfObjectForDispose = typeof(T);
    			if (!typeOfObjectForDispose.IsClass)
    				DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
    			else
    				if (!Equals(objectForDispose, null))
    					DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
    			objectForDispose = default(T);
    			//objectForDispose = (T)(object)(null);
    		}
    
    		public static void Create<T>(ref T objectForCreate, DeferredConstruction<T> newObject)
    		{
    			Dispose(ref objectForCreate);
    			objectForCreate = newObject();
    		}
      private static void DisposeIfIDisposable<T>(ref T objectForDispose, Type typeOfObjectForDispose)
            {
                bool canDisposable = (objectForDispose as IDisposable) != null;
                if (canDisposable)
                {
                    var dispose = typeOfObjectForDispose.GetMethod("Dispose");
                    dispose.Invoke(objectForDispose, new object[] { });
                }
            }
    }

    Говногость, 03 Февраля 2011

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