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

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

    −146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    n = 0
    for i in range(n):
        pass
    print i
    
    NameError: name 'i' is not defined

    3_14dar, 25 Июня 2015

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

    +9

    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
    template<...many params...>
    class Foo
    {
      template <typename T>
      class __Bar 
      {
        T t;
      public :
        __Bar(T t) : t(t) {}  
      };
    
    public :
      template <typename T>
      __Bar<T> Bar(T t)
      {
        return __Bar<T>(t); // просто __Bar(t) нельзя, вывод не сработает
      }
    
      template <typename T>
      void Buzz (T t)
      {
      }
    };
    
    ...
    Foo f;
    f.Buzz(Bar(5));

    А как вы выкручиваетесь из неумения определять тип результата по типу параметров конструктора?

    TarasB, 15 Апреля 2014

    Комментарии (87)
  4. Perl / Говнокод #13605

    −139

    1. 1
    2. 2
    >> # HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A')
    >> $content =~ s/(?<!%0D)%0A/%0D%0A/g if defined($content);

    HTTP::Request::Common 6.04, строка 86
    http://cpansearch.perl.org/src/GAAS/HTTP-Message-6.04/lib/HTTP/Request/Common.pm

    Оно просто берёт и изменяет передаваемый контент. Любой. В том числе просто бинарные данные.

    kainwinterheart, 13 Августа 2013

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

    +32

    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
    // *.h
    class MyClass {
    
    public:
    	MyClass ();
    	~MyClass ();
    	// ..etc
    
    };
    
    // *.cpp
    #include "*.h"
    
    MyClass *mycl;
    
    MyClass::MyClass ()
    {
    	mycl=this; // эту строчку не удалять без нее не работает, точнее не всегда работает иногда сбоит
    }
    
    MyClass::~MyClass ()
    {
    }

    Простите меня пожалуйста. Я уныл чуть мене чем полностью, но почему человек которые это написал хороший программист. Это писал не я. Извините пожалуйста за беспокойство :( ..

    neudachnik, 25 Января 2013

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

    +170

    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
    <?
    if (!$_SESSION['signed_id_user'] || $_SESSION['signed_id_group'] != 1) {
    	$pagetitle = 'Необходима авторизация';
    
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<div align=\"center\" style=\"width: 400px;\">\n";
    	$pagecontent .= "<form action=\"login.php\" method=\"post\">\n";
    	$pagecontent .= "<fieldset class=\"bw\">\n";
    	$pagecontent .= "	<legend class=\"bw\">авторизация пользователя</legend>\n";
    	$pagecontent .= "	<p>Поля, помеченные <span class=\"required\">*</span> являются обязательными для заполнения</p>\n";
    	$pagecontent .= "	<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" align=\"center\">\n";
    	$pagecontent .= "	<tr>\n";
    	$pagecontent .= "		<td width=\"160\" align=\"right\">имя пользователя:</td>\n";
    	$pagecontent .= "		<td width=\"120\"><input type=\"text\" size=\"20\" class=\"baseinput\" name=\"username\" id=\"username\" /></td>\n";
    	$pagecontent .= "		<td><div id=\"msgUsername\" class=\"required\">*</div></td>\n";
    	$pagecontent .= "	</tr>\n";
    	$pagecontent .= "	<tr>\n";
    	$pagecontent .= "		<td width=\"160\" align=\"right\">пароль:</td>\n";
    	$pagecontent .= "		<td width=\"120\"><input type=\"password\" size=\"20\" class=\"baseinput\" name=\"password\" id=\"password\" /></td>\n";
    	$pagecontent .= "		<td><div id=\"msgPassword\" class=\"required\">*</div></td>\n";
    	$pagecontent .= "	</tr>\n";
    	$pagecontent .= "	<tr>\n";
    	$pagecontent .= "		<td width=\"160\">&nbsp;</td>\n";
    	$pagecontent .= "		<td width=\"120\"><input type=\"submit\" class=\"button\" name=\"posted\" value=\"Войти\" /></td>\n";
    	$pagecontent .= "		<td>&nbsp;</td>\n";
    	$pagecontent .= "	</tr>\n";
    	$pagecontent .= "	</table>\n";
    	$pagecontent .= "</fieldset>\n";
    	$pagecontent .= "</form>\n";
    	$pagecontent .= "</div>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    	$pagecontent .= "<p>&nbsp;<p>\n";
    
    
    	$tpl = new Template();
    	$tpl->set_file('tpl/e-con_bw.tpl');
    	$tpl->add_var('PAGETITLE', $pagetitle);
    	$tpl->add_var('PAGECONTENT', $pagecontent);
    	echo $tpl->output();
    	$tpl = NULL;
        exit();
    }
    ?>

    Подскажите, пожалуйста, нахер с таким стилем кодинга вообще шаблонизатор надо?..

    Anderson, 04 Апреля 2012

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

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    int getGKnumber()
    {
       return 7000;
    }

    просто гет :)

    absolut, 19 Июня 2011

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

    +163

    1. 1
    substr_count(strtolower(php_uname()),'windows') ? ';' : ':')

    NetCat, такой NetCat. О существовании PATH_SEPARATOR даже и не знали.

    miraage, 19 Мая 2011

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

    +164

    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
    void Attr::setConvertedValue(std::string pValue)
    {
        /* ............. - BEGIN - Place the HTML code instead of the */
        /* plain values. This is needed since special XML characters      */
        /* might exist.                                                   */
        for(int i = 0; i < pValue.length(); i++)
        {
            int ascii = (int)pValue[i];
    
            if(!( (ascii == 32 ) ||
                  (ascii >= 48 && ascii <= 57) ||
                  (ascii >= 65 && ascii <= 90) ||
                  (ascii >= 97 && ascii <= 122) ) )
            {
                if( ascii < 0 )
                    ascii += 256;
    
                std::ostringstream stream;
                stream << ascii;
    
                std::string newString = stream.str();
                newString = "&#" + newString + ';';
    
                pValue.replace(i, 1, newString);
    
                i += newString.length() - 1;
            }
        }
        /* ............. - END - Place the HTML code instead of the */
        /* plain values. This is needed since special XML characters      */
        /* might exist.                                                   */
        mConvertedValue = pValue;
    }

    я стою на асфальте, ноги в лыжы абуты.

    мы эскайпим значения для ХМЛ.

    вы тут посмейтесь, а я пошел головой об стенку стучатся.

    ЗЫ пысано в Бразилии.

    Dummy00001, 11 Января 2011

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

    −160

    1. 1
    2. 2
    3. 3
    4. 4
    function midVal(X, Y)
    {
        return (Math.max(X, Y) - Math.min(X, Y)) / 2 + Math.min(X, Y);
    }

    Это среднее арифметическое один один чел так считает.
    Взято отсюда: http://www.gamedev.ru/flame/forum/?id=137879&page=4#m47
    Тема сама по себе весёлая.

    TarasB, 10 Сентября 2010

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

    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
    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
    const int sum(int a, int b){
        return a+b;
    }
    
    int a(int x)
    {
        const std::function<int(int)> sum4 = std::bind(sum,_1, 4);    
        return sum4(123);
    }
    
    int b(int x)
    {
        puts("bagor");    
        const std::function<int(int)> sum4 = std::bind(sum,_1, 4);    
        return sum4(123);
    }
    
    int c(int x)
    {
        const std::function<int(int)> sum4 = std::bind(sum,_1, 4);    
        puts("bagor");    
        return sum4(123);
    }
    
    // Функции a и b нормально инлайнятся. Ассемблерный выхлоп:
    
    sum(int, int):                               # @sum(int, int)
            lea     eax, [rdi + rsi]
            ret
    a(int):                                  # @a(int)
            mov     eax, 127
            ret
    b(int):                                  # @b(int)
            push    rax
            mov     edi, offset .L.str
            call    puts
            mov     eax, 127
            pop     rcx
            ret
    
    //А вот int c(int x)
    c(int):                                  # @c(int)
            push    rbx
            sub     rsp, 32
            mov     edi, 16
            call    operator new(unsigned long)
            mov     rbx, rax
            mov     qword ptr [rax], offset sum(int, int)
            mov     dword ptr [rax + 8], 4
            mov     qword ptr [rsp], rax
            mov     qword ptr [rsp + 24], offset std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&)
            mov     qword ptr [rsp + 16], offset std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation)
            mov     edi, offset .L.str
            call    puts
            mov     esi, dword ptr [rbx + 8]
            mov     edi, 123
            call    qword ptr [rbx]
            mov     ebx, eax
            mov     rax, qword ptr [rsp + 16]
            test    rax, rax
            je      .LBB3_3
            mov     rdi, rsp
            mov     rsi, rdi
            mov     edx, 3
            call    rax
    .LBB3_3:
            mov     eax, ebx
            add     rsp, 32
            pop     rbx
            ret
            mov     rdi, rax
            call    __clang_call_terminate
            mov     rbx, rax
            mov     rax, qword ptr [rsp + 16]
            test    rax, rax
            je      .LBB3_6
            mov     rdi, rsp
            mov     rsi, rdi
            mov     edx, 3
            call    rax
    .LBB3_6:
            mov     rdi, rbx
            call    _Unwind_Resume@PLT
            mov     rdi, rax
            call    __clang_call_terminate
    __clang_call_terminate:                 # @__clang_call_terminate
            push    rax
            call    __cxa_begin_catch
            call    std::terminate()
    std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&): # @std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_invoke(std::_Any_data const&, int&&)
            mov     rax, qword ptr [rdi]
            mov     rcx, qword ptr [rax]
            mov     edi, dword ptr [rsi]
            mov     esi, dword ptr [rax + 8]
            jmp     rcx                             # TAILCALL
    std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation): # @std::_Function_handler<int (int), std::_Bind<int const (*(std::_Placeholder<1>, int))(int, int)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation)

    Решил попробовать std::bind.

    https://godbolt.org/z/eW5eT5oj4

    3.14159265, 27 Августа 2021

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