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

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

    −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
    #include <stdio.h>
    #include <time.h>
    
    int main(int argc, char const *argv[])
    {
    	printf("Подождите...\n");
    	long start = time(NULL);
    	FILE *f;
    	f = fopen("test", "w");
    	if(f == NULL) {
    		perror("fopen");
    		return 1;
    	}
    	for(int i=0; i<10000000; i++)
    		fputs("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", f);
    	fclose(f);
    	long stop = time(NULL);
    	long sec = stop-start;
    	int result = 1000/sec;
    	printf("Результат: секунд:%li скорость:%iмб/с\n", sec, result);
    	return 0;
    }

    понос.c

    pawn-master, 04 Ноября 2017

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

    −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
    43. 43
    44. 44
    45. 45
    46. 46
    <?php
    
    for($a = 1;$a <= 1;$a++){
        echo "$a";
        for ($b = 2 ;$b <= 2;$b++){
            echo "<br /> $b";
            for ($c = 3 ;$c <= 3;$c++){
                echo "$c";
                for ($d = 4;$d <= 4;$d++){
                    echo "<br/> $d";
                    for ($e = 5;$e <= 5;$e++){
                        echo "$e";
                        for($f = 6;$f <= 6;$f++){
                            echo "$f";
                            for ($j = 7;$j <= 7;$j++){
                                echo "<br />$j";
                                for ($h = 8;$h <=8;$h++)
                                echo "$h";
                                for ($i = 9;$i <= 9;$i++){
                                    echo "$i";
                                    for ($k = 10;$k <= 10;$k++){
                                        echo "$k";
                                        for ($l = 11;$l <= 11;$l++){
                                            echo "<br />$l";
                                            for ($m = 12;$m <= 12;$m++){
                                                echo "$m";
                                                for ($n = 13;$n <= 13;$n++){
                                                    echo "$n";
                                                    for ($o = 14;$o <= 14;$o++){
                                                        echo "$o";
                                                        for ($p = 15;$p <= 15;$p++){
                                                            echo "$p";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    talibana, 30 Октября 2017

    Комментарии (7)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)