1. C++ / Говнокод #19724

    +8

    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
    template <size_t capacity, bool is_signed>
    class fixed_int
    {	
        // Описание ошибки компиляции в случае использования не поддерживаемой размерности 
        template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
        template <> struct unsupported_capacity<1> {};
        template <> struct unsupported_capacity<2> {};
        template <> struct unsupported_capacity<4> {};
        template <> struct unsupported_capacity<8> {};
    
        // Свойства базовых типов, необходимые для перебора
        template<typename type> struct type_traits;
        template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
        template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
        template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
        template<> struct type_traits <unsigned long> {	typedef unsigned long current_type; typedef unsigned long long next_type; };
        template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type;  typedef unsupported_capacity<capacity> next_type; };
        template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
        template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
        template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
        template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
        template<> struct type_traits <long long int> { typedef long long int current_type;  typedef unsupported_capacity<capacity> next_type;};
    
        // Алгоритм выбора типа
        template<typename type, bool> 
        struct type_choice 
        { 
            typedef typename type_traits<type>::current_type std_type; 
        };
        template<typename type> 
        struct type_choice<type, false> 
        { 
            typedef typename type_traits<type>::next_type next_type; 
            typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type; 
        };
    
        // Базовый тип для начала подбора
        template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
        template <> struct base_type_selector<false> { typedef unsigned char base_type; };
    
    public:
    
        typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
    
    };

    "Зачем мне нужен stdint.h?
    У меня нет времени, чтобы ебаться с ним!
    Лучше я высру ещё десяток-другой шаблонов!"
    https://habrahabr.ru/post/280542/

    PS,
    Пятая строка - вообще угар.

    gost, 31 Марта 2016

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

    +1

    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
    private int GetSroOper(MiscTransactionParams param)
    		{
    			if (param.ExpenseItem != null)
    			{
    				switch (param.ContractType)
    				{
    					case Entities.AT.ContractType.Undefined:
    					case Entities.AT.ContractType.TimeAndMaterials:
    					case Entities.AT.ContractType.Retainer:
    						switch ((int)param.ExpenseItem.ExpenseCategory)
    						{
    							case 2:
    							case 3:
    							case 29684252:
    							case 29684285:
    							case 29684805:
    								return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
    							default:
    								throw new InvalidOperationException("Unsupported Expense Category value");
    						}
    					case Entities.AT.ContractType.RecurringService:
    						switch ((int)param.ExpenseItem.ExpenseCategory)
    						{
    							case 2:
    							case 3:
    							case 29684252:
    							case 29684285:
    							case 29684805:
    								return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
    							default:
    								throw new InvalidOperationException("Unsupported Expense Category value");
    						}
    					case Entities.AT.ContractType.FixedPrice:
    						switch ((int)param.ExpenseItem.ExpenseCategory)
    						{
    							case 2:
    							case 3:
    							case 29684252:
    							case 29684285:
    							case 29684805:
    								return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation500 : Helper.SLServiceOrderOperation950;
    							default:
    								throw new InvalidOperationException("Unsupported Expense Category value");
    						}
    					case Entities.AT.ContractType.Incident:
    						switch ((int)param.ExpenseItem.ExpenseCategory)
    						{
    							case 2:
    							case 3:
    							case 29684252:
    							case 29684285:
    							case 29684805:
    								return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation950;
    							default:
    								throw new InvalidOperationException("Unsupported Expense Category value");
    						}
    					default:
    						throw new InvalidOperationException("Unsupported ContractType value");
    				}
    			}
    			else
    			{
    				switch (param.ContractType)
    				{
    					case Entities.AT.ContractType.Undefined:
    					case Entities.AT.ContractType.TimeAndMaterials:
    					case Entities.AT.ContractType.Retainer:
    						return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
    					case Entities.AT.ContractType.RecurringService:
    						return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
    					case Entities.AT.ContractType.FixedPrice:
    					case Entities.AT.ContractType.Incident:
    						int sroOper = (int)param.OrderOperation.EntityRow()[Constants.ServiceOrderOperation.Field.SroOper];
    						switch (sroOper)
    						{
    							case 500:
    							case 600:
    							case 800:
    							case 850:
    							case 950:
    								return sroOper;
    							default:
    								throw new InvalidOperationException("Unsupported Operation value");
    						}
    					default:
    						throw new InvalidOperationException("Unsupported ContractType value");
    				}
    			}
    		}

    Это наш сеньор написал

    kagetoki, 30 Марта 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static bool AddStringIfNoExist(this List<string> strlist, string str)
    {
        if (str == "") return true;
        foreach (string s in strlist) if (s == str) return true;
        strlist.Add(str);
        return false;
    }

    Hashset? А что это такое?

    kerman, 29 Марта 2016

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

    0

    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
    $f = fopen("./.htaccess", "r");
    			while (!feof($f)) {
    			    $tmp = fgets($f);
    			    $tmp = str_replace(REDIRECT_USER."/", $_POST["redir_user"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_SHOP."/", $_POST["redir_shop"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_ADMIN."/", $_POST["redir_admin"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_NEWS."/", $_POST["redir_news"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_CART."/", $_POST["redir_cart"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_PAYMENT."/", $_POST["redir_payment"]."/", $tmp);
    			    $tmp = str_replace(REDIRECT_INFO."/", $_POST["redir_info"]."/", $tmp);
    			    $line[] = $tmp;
    			}
    			fclose($f);

    Настройка редиректов из админки

    drop_database, 29 Марта 2016

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

    +81

    1. 1
    mov podi,vilov

    d_fomenok, 29 Марта 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function extractPublicPlace($item)
    {
        list($a['name'], list($a['lat'], $a['lon'])) = $item;
        return $a;
    }

    просто оставлю

    akanit, 29 Марта 2016

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

    +6

    1. 1
    2. 2
    http://requests.readthedocs.org/en/master/
    Warning: Recreational use of other HTTP libraries may result in dangerous side-effects, including: security vulnerabilities, verbose code, reinventing the wheel, constantly reading documentation, depression, headaches, or even death.

    Не говнокод, даже не говнокоммент. Наоборот, хороший, годный комментарий.

    хуита, 29 Марта 2016

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

    +5

    1. 1
    2. 2
    3. 3
    .dostali {
    font-weight: bold;
    }

    Достали!!!11

    gk228, 29 Марта 2016

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

    +4

    1. 1
    http://cs543107.vk.me/v543107084/f49c/quBsGLPz-lE.jpg

    Программирование по-русски глазами американцев...
    Сериал: "Агенты Щ.И.Т."; Сезон: 3; Эпизод: 13

    LispGovno, 29 Марта 2016

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

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public enum Status : byte
    {
            Disabled = 0,
            Enabled
    }

    Мопед не мой, прислала боевая подруга из Канады, реальный проект за недетские деньги.
    Лаконичности була не хватило, лучше свой енум сделать, чем писать bool IsEnabled.
    KISS.

    kerman, 28 Марта 2016

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