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

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

    +2

    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
    #define max(x, y)  ((x) > (y) ? (x) : (y)) // Вводим макрос
    #define MAX(x, y) max(x, y) // Чтобы не конфликтовал со стандартным max
    #define Std namespace std // Так короче
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using Std;
    
    int main()
    
    {
        bool vvedeno = false;
        int kolichestvo;
        cin >> kolichestvo;
        vector<char> A(kolichestvo);
        A: if (vvedeno){goto B;}else{
        while(kolichestvo != 0){vvedeno = true; cin >> A[kolichestvo - 1]; kolichestvo = kolichestvo - 1;} // вводим
    
    }
        reverse (A.begin(), A.end()); // для определённости развернём
        B:
        vector<int> B; // Массив из цифр
        try{
            for (char tipachislo : A)
                B.push_back(int(tipachislo) - 48);  // преобразуем char к int
        }catch(errc){vvedeno = false; kolichestvo = A.size(); goto A;} // ну что-то же ввести надо
        C:
        int maxim = B[1];
        int dlina = B.size();
        D:
        maxim = MAX(B[dlina - 1], maxim);
        dlina--;
        if(dlina == -1){cout << maxim;}else{goto D;} // ищем
    }

    Caladrius, 29 Октября 2017

    Комментарии (7)
  3. Haskell / Говнокод #23446

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    -- https://haskell-lang.org/library/http-client
    let request = setRequestBodyFile "people.yaml"
                $ setRequestHeader "Content-Type" ["application/x-yaml"]
                $ "PUT https://httpbin.org/put"
    response <- httpJSON request

    Товарищ Снойман, конечно, молодец, но его творчество мне зачастую больше напоминает жабу, чем хачкель. У меня одного такое ощущение?

    (Неявное) преобразование "PUT https://httpbin.org/put" в значение Request — это, кмк, какой-то ⊥(bottom)

    #нытьё #CHayT

    roman-kashitsyn, 23 Октября 2017

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

    +2

    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
    #define PS *p++!=*s++  /* Body of inner unrolled matching loop.         */
    #define ITEMMAX 16     /* Maximum number of bytes in an expanded item.  */
    {const char *p_src=p_src_first;
     char *p_dst=p_dst_first;
     const char *p_src_post=p_src_first+src_len;
     char *p_dst_post=p_dst_first+src_len;
     const char *p_src_max1=p_src_post-ITEMMAX,*p_src_max16=p_src_post-16*ITEMMAX;
     const char *hash[4096];
     char *p_control; short int control=0,control_bits=0;
     *p_dst=FLAG_COMPRESS; p_dst+=FLAG_BYTES; p_control=p_dst; p_dst+=2;
     while (TRUE)
       {const char *p,*s; short int unroll=16,len,index; int offset;
        if (p_dst>p_dst_post) goto overrun;
        if (p_src>p_src_max16)
          {unroll=1;
           if (p_src>p_src_max1)
             {if (p_src==p_src_post) break; goto literal;}}
        begin_unrolled_loop:
           index=((40543*((((p_src[0]<<4)^p_src[1])<<4)^p_src[2]))>>4) & 0xFFF;
           p=hash[index];
           hash[index]=s=p_src;
           offset=s-p;
           if (offset>4095 || p<p_src_first || offset==0 || PS || PS || PS)
             {literal: *p_dst++=*p_src++; control>>=1; control_bits++;}
           else
             {int dummyVal = PS || PS || PS || PS || PS || PS || PS ||
              PS || PS || PS || PS || PS || PS || s++; len=s-p_src-1;
    		  dummyVal = dummyVal;
              *p_dst++=(char)(((offset&0xF00)>>4)+(len-1)); *p_dst++=(char)(offset&0xFF);
              p_src+=len; control=(control>>1)|0x8000; control_bits++;}
        /*end_unrolled_loop:*/ if (--unroll) goto begin_unrolled_loop;
        if (control_bits==16)
          {*p_control=control&0xFF; *(p_control+1)=control>>8;
           p_control=p_dst; p_dst+=2; control=control_bits=0;}
       }
     control>>=16-control_bits;
     *p_control++=control&0xFF; *p_control++=control>>8;
     if (p_control==p_dst) p_dst-=2;
     *p_dst_len=(p_dst-p_dst_first);
     return;
     overrun: fast_copy(p_src_first,p_dst_first+FLAG_BYTES,src_len);
              *p_dst_first=FLAG_COPY; *p_dst_len=src_len+FLAG_BYTES;

    Красота в одном из методов кода одной MMO игры)

    Sigos, 16 Октября 2017

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    bool valueToString(std::string_view str, float& value) try {
        const auto end = std::numeric_limits<std::size_t>::max();
        const float parsed = std::stof(str.data(), &end);
        if (end != str.size())
            return false;
        value = parsed;
        return true;
    } catch (...) {
        return false;
    }

    string_view пирформанс! Спойлер: да, там std::stof

    Elvenfighter, 22 Сентября 2017

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

    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
    namespace parse_main_config {
    
        struct _main_config_ {
            std::string m_sCurrentConfigFile;
            std::string m_sBaseFile;
            std::string m_sBasePrefix;
            std::string m_sCheckRuleFile;
            std::string m_sReplacementTablesFile;
            std::string m_sPasswdFile;
            std::string m_sTestsListFile;
            std::string m_sModesFile;
            std::string m_sIfacesFile;
            std::string m_sCmcCheckFile;
            std::string m_sUpsCheckFile;
            std::string m_sSetLocalIpFile;
            std::string m_sShortLogFile;
            std::string m_sFullLogFile;
            std::string m_sListLogFile;
    
    	int m_iNTPTime;
    	int m_iNTPOffset;
    	int m_iMonNumber;
            int m_iOSRebootTime;
            int m_iMonitorCount;
            QString m_sStationType;
            int m_iHddTimeout;
            std::string m_sWinIconFile;
            std::string m_sWinMenuOptFile;
            std::string m_sWinMenuCloseFile;
            std::string m_sWindowTitle;
    
            QString m_sServerIP;
            QString m_sServerNetMask;
            QString m_sServerNetIP;
            int m_iPort;
            int m_iTimeout;
    		// Remote work
            std::string m_sRemoteHost;
    		std::string m_sRemoteUser;
    		std::string m_sRemotePass;
    		std::string m_sRemoteFtpUser;
    		std::string m_sRemoteFtpPass;
    
            // defaults
            _main_config_() {
                m_sCurrentConfigFile    = "";
                m_sBaseFile             = "./base.cfg";
                m_sBasePrefix           = "Workstation";
                m_sCheckRuleFile        = "./check_rules.cfg";
                m_sModesFile            = "./view_modes.cfg";
                m_sIfacesFile           = "./ip.cfg";
                m_sReplacementTablesFile = "./replacement_tables.xml";
                m_sShortLogFile         = "./short.log";
                m_sFullLogFile          = "./full.log";
                m_sListLogFile          = "./list.log";
                m_sPasswdFile           = "./passwd";
    
                m_iNTPTime              = 0;
                m_iNTPOffset            = 0;
    
                m_sServerNetMask        = "255.255.255.0";
                m_sServerNetIP          = "1.1.1.1";
                m_sServerIP             = "127.0.0.1";
                m_iPort                 = 1;
                m_iTimeout              = 11;
                m_iMonNumber	    = 2;
    
                m_iOSRebootTime         = -1;
    
            std::string m_sRemoteHost = "127.0.0.1";
                    std::string m_sRemoteUser = "blablabla";
                    std::string m_sRemotePass = "blablabla";
    		std::string m_sRemoteFtpUser = "blablabla";
    		std::string m_sRemoteFtpPass = "";
            }
        };
    
        // parsing file
        int read_configuration(const std::string &, _main_config_ &);
    }

    Поддерживаю старый проект. Большой и настолько старый, что написан с использованием Qt3.
    Дело дошло до релиза.
    Соль в том, что я добавил в эту структуру поле с именем - m_sCurrentConfigFile (первое)
    При сборке debug конфигурации все норм, с release конфигурацией - приложение вылет при QMainWindow::show();
    Стоит закомментить это поле и все места, где оно юзается, естественно - как сука, все хорошо.
    Юзается в двух местах - и в обоих случаях к нему просто присваивается строка.
    На тот самый метод -- ну никак не должно влиять.
    Не подскажете, какая сегодня фаза луны?

    OlegUP, 29 Августа 2017

    Комментарии (7)
  7. Swift / Говнокод #23282

    0

    1. 1
    2. 2
    3. 3
    4. 4
    if let attrs = profile?.attrs {
        let json = NSKeyedUnarchiver.unarchiveObject(with: attrs as Data) as? [String:AnyObject]
        textField.text = String(format: "%@", (json?["number"] as? String)!)
    }

    Кто пишет на Swift – разделит всю боль поддержки такого кода.

    pavelsmelovsky, 21 Августа 2017

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

    +4

    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
    // Consumer
    $channel->run(
        new GracefulHandler(
            new LoggingHandler(
                new AcknowledgingHandler(
                    new JsonDecodingHandler(
                        new ValidatingHandler(
                            new DbalReconnectingHandler(
                                new AmqpPublishingHandler(
                                    new Mailman($channel, $exchangeName),
                                    new PrintNodePrinterPool(
                                        new PluginClient(
                                            new HttpClient(),
                                            [new AuthenticationPlugin(new BasicAuth($key, ''))]
                                        ),
                                        MessageFactoryDiscovery::find()
                                    ),
                                    new DbalBatchFactory(
                                        $connection,
                                        new S3BatchLabelFactory(
                                            new S3Client(
                                                [
                                                    'version' => 'latest',
                                                    'region' => $region,
                                                    'credentials' => [
                                                        'key' => $key,
                                                        'secret' => $secret,
                                                    ],
                                                ]
                                            ),
                                            $bucket,
                                            $logger
                                        ),
                                        new LabelFactory(
                                            new GuzzleClient(),
                                            new PickTicketFactory($template, $layouts)
                                        )
                                    )
                                ),
                                $connection
                            ),
                            __DIR__ . '/schema.json'
                        )
                    )
                ),
                $logger
            )
        ),
        $name
    );

    Пример consumer на PHP для RabbitMQ (Yegor OOP style)

    belka3000, 14 Июля 2017

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    defmodule Utils.String do
      @moduledoc false
      def comma_split(str), do: String.split(str, " ", trim: true)
    end

    AndrewDryga, 10 Июля 2017

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

    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
    97. 97
    98. 98
    #include <optional>
    
    namespace aim {
    
            template <typename T, template <typename> typename Cont>
            struct is_valid {};
    
            template <typename T, template <typename> typename Cont>
            struct chain;
    
            template <typename T, template <typename> typename Cont>
            struct chain {
                    using value_type_t = T;
                    using holder_t = Cont<value_type_t>;
    
                    chain()
                    {}
    
                    chain(holder_t&& value_)
                    : value(std::move(value_))
                    {}
    
                    template <typename Func>
                    constexpr auto otherwise(Func&& func) {
                            return chain<T, Cont>{std::move(func())};
                    }
    
                    template <typename Func>
                    constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
                            if (bool(value)) {
                                    return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
                            }
                            else {
                                    return chain<value_type_t, Cont>{};
                            }
                    }
    
                    holder_t value;
            };
    
            template <typename T, template <typename> typename Cont>
            chain(Cont<T>&&) -> chain<T, Cont>;
    
            template <typename T, template <typename> typename Cont>
            struct use {
                    using value_type_t = T;
                    using holder_t = Cont<value_type_t>;
    
                    use(holder_t&& value)
                    : value(std::move(value))
                    {}
    
                    template <typename Func>
                    constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
                            if (is_valid<T, Cont>{}(value)) {
                                    return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
                            }
                            else {
                                    return chain<value_type_t, Cont>{};
                            }
                    }
    
                    holder_t value;
            };
    
            template <typename T, template <typename> typename Cont>
            use(Cont<T>&&) -> use<T, Cont>;
            
    }
    
    namespace aim {
            template <typename T>
            struct is_valid<T, std::optional> {
                    constexpr bool operator()(std::optional<T> const& value) {
                            return bool(value);
                    }
            };
    }
    
    #include <iostream>
    #include <memory>
    
    int main() {
            {
                    std::optional<int> a;
    
                    aim::use(std::move(a)).with([](auto v) {
                            std::cout << v << '\n';
                            return 1;
                    }).otherwise([](){
                            std::cout << "it's none!\n";
                            return 2;
                    }).with([](auto v){
                            std::cout <<  v << '\n';
                            return 3;
                    });
            }
    }

    говно

    j123123, 06 Июля 2017

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function color_search($color) {
         $arColor["COLOR"] = explode(",","aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen,black,dimgray,gray,darkgray,silver,lightgrey,gainsboro,whitesmoke,white,snow,rosybrown,lightcoral,indianred,brown,firebrick,maroon,darkred,red,salmon,mistyrose,tomato,darksalmon,coral,orangered,lightsalmon,sienna,seashell,saddlebrown,chocolate,peachpuff,sandybrown,linen,peru,bisque,darkorange,antiquewhite,tan,burlywood,blanchedalmond,navajowhite,papayawhip,moccasin,oldlace,wheat,orange,floralwhite,goldenrod,darkgoldenrod,cornsilk,gold,lemonchiffon,khaki,palegoldenrod,darkkhaki,ivory,beige,lightyellow,olive,yellow,olivedrab,yellowgreen,darkolivegreen,greenyellow,lawngreen,chartreuse,honeydew,darkseagreen,lightgreen,palegreen,forestgreen,limegreen,darkgreen,green,lime,seagreen,mediumseagreen,mintcream,springgreen,mediumspringgreen,mediumaquamarine,aquamarine,turquoise,lightseagreen,mediumturquoise,azure,paleturquoise,darkslategray,teal,darkcyan,aqua,cyan,lightcyan,darkturquoise,cadetblue,powderblue,lightblue,deepskyblue,skyblue,lightskyblue,steelblue,aliceblue,slategray,lightslategray,dodgerblue,lightsteelblue,cornflowerblue,royalblue,ghostwhite,lavender,midnightblue,navy,darkblue,mediumblue,blue,darkslateblue,slateblue,mediumslateblue,mediumpurple,blueviolet,indigo,darkorchid,darkviolet,mediumorchid,thistle,plum,violet,purple,darkmagenta,fuchsia,magenta,orchid,mediumvioletred,deeppink,hotpink,lavenderblush,palevioletred,crimson");
         if(in_array($color, $arColor["COLOR"])){
             return $color;
         }
     }

    scph77008, 25 Мая 2017

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