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

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    HRESULT SomeClass::GetVersion(std::wstring& version)
    {
        CComBSTR versionBstr;
        m_Interface->get_Version(&versionBstr);
        version = std::move(std::wstring((_bstr_t)versionBstr, versionBstr.Length()));
        return S_OK;
    }

    Как показать в одном методе (не)знание move семантики, правил приведения типов и COM фреймворка

    salamon_style, 18 Января 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #include <xmmintrin.h>
    
    void crasher() {
        constexpr __m128 w = {1,2,3,4};
        asm ("addps %[w], %[w]" : : [w] ""(w));
    }

    Крашим GCC
    https://ideone.com/iIAN0i

    Antervis, 28 Февраля 2018

    Комментарии (58)
  4. Lua / Говнокод #23489

    −13

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    for i=1,1000 do
    	str = string.format("xyi%i", i)
    	f = io.open(str, "w")
    	f:write("я вирус! приветикиии")
    	f:flush()
    	f:close()
    end

    оцениваем по 1000 бальной шкале плиз!

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

    Комментарии (58)
  5. Си / Говнокод #23350

    +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
    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
    99. 99
    #include<stdio.h>
    #include<math.h>
    
    int const n = 50, n1 = 40, m = n / n1;
    double f1(double t, double x, double y, double z);
    double f2(double t, double x, double y, double z);
    double f3(double t, double x, double y, double z);
    
    int main() {
    	int i, k, ll;
    	double k11, k12, k13, k21, k22, k23, k31, k32, k33, k14, k24, k34;
    	double x, y, z, max;
    	double res[12][n1 + 1], h, a, b, t, pi, xn, yn, zn;
    	max = 1000.0; x = 3.0;
    	y = -2.0; z = -3.0;
    	a = 0.0; b = 1.0;
    	h = (b - a) / double(n);
    
    	k = 0; t = a;
    	res[0][0] = t; res[1][0] = x;
    	res[2][0] = y;
    	res[3][0] = z;
    	for (i = 1; i <= n; i++) {
    		k11 = f1(t, x, y, z);
    		k21 = f2(t, x, y, z);
    		k31 = f3(t, x, y, z);
    		k12 = f1(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k22 = f2(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k32 = f3(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
    		k13 = f1(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k23 = f2(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k33 = f3(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
    		k14 = f1(t + h, x + h*k13, y + h*k23, z + h*k33);
    		k24 = f2(t + h, x + h*k13, y + h*k23, z + h*k33);
    		k34 = f3(t + h, x + h*k13, y + h*k23, z + h*k33);
    		x = x + h*(k11 + 2.0*(k12 + k13) + k14) / 6.0;
    		y = y + h*(k21 + 2.0*(k22 + k23) + k24) / 6.0;
    		z = z + h*(k31 + 2.0*(k32 + k33) + k34) / 6.0;
    		t = t + h;
    		if (i%m == 0) {
    			k = k + 1;
    			res[0][k] = t;
    			res[1][k] = x;
    			res[2][k] = y;
    			res[3][k] = z;
    			res[4][k] = exp(t) + exp(2.0*t) + exp(-t);
    			res[5][k] = exp(t) - 3.0*exp(-t);
    			res[6][k] = exp(t) + exp(2.0*t) - 5.0*exp(-t);
    			res[7][k] = res[4][k] - res[1][k];
    			res[8][k] = res[5][k] - res[2][k];
    			res[9][k] = res[6][k] - res[3][k];
    		} if (res[7][k] < 0.0) {
    			res[7][k] = -res[7][k];
    		}
    		else if (res[8][k] < 0.0) {
    			res[8][k] = -res[8][k];
    		}
    		else if (res[9][k] < 0.0) {
    			res[9][k] = -res[9][k];
    		}
    		res[10][k] = res[7][k] + res[8][k] + res[9][k];
    	}
    
    	ll = k;
    	printf("k=%d\n", ll);
    	for (i = 0; i <= ll; i++) {
    		if (res[10][i] < max) max = res[10][i];
    	} for (i = 0; i <= n1; i++) {
    		printf("t=%.16lf\n", res[0][i]);
    		printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][k], res[4][k], res[1][k] - res[4][k]);
    		printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][k], res[5][k], res[2][k] - res[5][k]);
    		printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][k], res[6][k], res[3][k] - res[6][k]);
    	}
    	printf("result:\n");
    	printf("t=%.16lf\n", res[0][n1]);
    	printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][n1], res[4][n1], res[1][n1] - res[4][n1]);
    	printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][n1], res[5][n1], res[2][n1] - res[5][n1]);
    	printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][n1], res[6][n1], res[3][n1] - res[6][n1]);
    	printf("max norma|x|1=%.16lf \n", max / 3.0);
    
    	system("pause");
    
    	return 0;
    }
    
    double f1(double t, double x, double y, double z)
    {
    	return x + z - y;
    }
    
    double f2(double t, double x, double y, double z)
    {
    	return x + y - z;
    }
    
    double f3(double t, double x, double y, double z)
    {
    	return 2.0*x - y;
    }

    Кандидат физико-математических наук сделал методичку по предмету "Моделирование систем". Это он так описал алгоритм решения системы ОДУ методом Рунге-Кутты.

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

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

    +6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(int i = 0; i < codes.size(); ++i) {
        switch(i) {
            case 0: ret.code0 = codes[i]; break;
            case 1: ret.code1 = codes[i]; break;
            case 2: ret.code2 = codes[i]; break;
            case 3: ret.code3 = codes[i]; break;
            case 4: ret.code4 = codes[i]; break;
            case 5: ret.code5 = codes[i]; break;
        }
    }

    А всё потому, что ret.code[0-5] - битовые поля. Эх.

    Xom94ok, 25 Мая 2016

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

    −3

    1. 1
    2. 2
    3. 3
    >ipconfig   | find "IP"
    ═рёЄЁющър яЁюЄюъюыр IP фы  Windows
            IP-рфЁхё  . . . . . . . . . . . . : 192.168.1.60

    ЧЗХ (кодировка)?

    3_14dar, 01 Марта 2016

    Комментарии (58)
  8. Python / Говнокод #17792

    −115

    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
    def _message_handler_thread(self):
            self._nick_change_failed = []
            while self.running:
                msg = self._message_queue.get(True)
                text = msg.get_data()
                conn = msg.get_connection()
                args = text.replace("\r", "").replace("\n", "").split(" ")
                command = args[0].upper()
                command_args = args[1:]
                if command == "NICK":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        ident = self._clients[conn].identifier if self._clients[conn].identifier else None
                        if not self._set_nick(conn, command_args[0], ident):
                            self._nick_change_failed.append(conn)
                elif command == "USER":
                    if conn in self._clients:
                        if len(command_args) < 2:
                            self._send_not_enough_parameters(conn, command)
                        else:
                            ''''
                            self._send_lusers(conn)
                            self._clients[conn].real_name = command_args[:]
                            self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
                                                                   command_args[0] + "@" + self.name
                            '''
                            self._set_nick(conn, command_args[0], command_args[1])
                            self._send_motd(conn)
                    else:  # Another way to identify is USER command.
                        if len(command_args) < 2:
                            self._send_not_enough_parameters(conn, command)
                        elif conn in self._nick_change_failed:
                            self._nick_change_failed.remove(conn)
                        else:
                            if self._set_nick(conn, command_args[0], command_args[1]):
                                self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
                                    command_args[0] + "@" + self.name
                                self._send_motd(conn)
                elif command == "PRIVMSG" or command == "NOTICE":
                    if len(command_args) < 2:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        message_text = command_args[1] if not command_args[1][0] == ":" else \
                            text.replace("\r\n", "")[text.index(":")+1:]
                        src = self._clients[conn].get_identifier()
                        dest = command_args[0]
                        if not dest.startswith("#"):
                            for clnt in self._clients.values():
                                if clnt.nick == dest:
                                    clnt.connection.send(
                                        ":%s %s %s :%s" % (src, command, dest, message_text)
                                    )
                                    break
                            else:
                                self._send_no_user(conn, dest)
                        else:
                            for chan in self._channels:
                                if chan.name == dest:
                                    self._channel_broadcast(conn, chan, ":%s %s %s :%s" %
                                                (src, command, dest, message_text))
                                    break
                            else:
                                self._send_no_user(conn, dest)
                elif command == "JOIN":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    elif not all(c in ALLOWED_CHANNEL for c in command_args[0]) and len(command_args[0]):
                        self._send_no_channel(conn, command_args[0])
                    else:
                        for chan in self._channels:
                            if chan.name == command_args[0]:
                                chan.users += 1
                                self._clients[conn].channels.append(chan)
                                self._send_to_related(conn, ":%s JOIN %s" % (self._clients[conn].get_identifier(),
                                                                             chan.name), True)
                                self._send_topic(conn, chan)
                                self._send_names(conn, chan)
                        else:
                            chan = Channel(command_args[0], 1)
                            chan.users = 1  # We have a user, because we have created it!
                            self._channels.append(chan)
                            self._clients[conn].channels.append(chan)
                            self._clients[conn].send(":%s JOIN %s" % (self._clients[conn].get_identifier(),
                                                       command_args[0]))
                elif command == "PART":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        for chan in self._channels:
                            if chan.name == command_args[0]:
    
                                self._send_to_related(conn, ":%s PART %s" % (self._clients[conn].get_identifier(),
                                                                             command_args[0]))
                                self._clients[conn].channels.remove(chan)
                                chan.users -= 1
                                break
    ...

    Я писал сервер для IRC...
    Больше говнокода: https://github.com/SopaXorzTaker/irc-server/

    GoUseGitHub, 15 Марта 2015

    Комментарии (58)
  9. Python / Говнокод #16358

    −422

    1. 1
    2. 2
    3. 3
    4. 4
    import math
    print math.pow(2,64) //1.84467440737e+19
    print pow(2,64)         //18446744073709551616
    print 2**64               //18446744073709551616

    http://ideone.com/kmGrBa
    http://ideone.com/otSgCP

    Говно в обоих версиях калькулятора.

    3.14159265, 16 Июля 2014

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

    +15

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int getRandomNumber(){
       int Number[1];
       return Number[6];
    }
    //Я только учусь, поэтому не судите строго.

    И кому теперь нужно srand(GetTickCount());

    Ignat776, 26 Марта 2014

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

    +42

    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
    #include <time.h>
    #include <string>
    #include <iostream>
    #include <functional>
    
    using namespace std::placeholders;
    
    class F
    {
            int inc;
    
    public:
    
            F( int inc_v ): inc( inc_v ) {};
    
            int calc( int x )
            {
                    return x + inc;
            };
    };
    
    F a1( -10 );
    F a2( 11 );
    
    int f1( int x )
    {
            return x - 10;
    };
    
    int f2( int x )
    {
            return x + 11;
    };
    
            struct my_ftor
            {
                    F *obj;
                    int (F::*meth)(int);
                    int operator()(int x)
                    {
                            return (obj->*meth)( x );
                    };
                    my_ftor() {};
                    my_ftor( F *x, int(F::*y)(int) ) : obj(x), meth(y) {};
            };
    
    template<typename functor_type>
    void test( std::function<functor_type(int)> filler, char *name )
    {
            const int size = 1000;
            const int iters = 10000;
    
            int beg_time, end_time;
    
            functor_type funcs[ size ];
    
            beg_time = clock();
            for ( int i = 0; i < iters; i++ )
            {
                    for ( int j = 0; j < size; j++ )
                    {
                            funcs[ j ] = filler(j);
                    }
            };
            end_time = clock();
            float creation = ((float)(end_time - beg_time) / CLOCKS_PER_SEC);
    
            beg_time = clock();
            int res = 0;
            for ( int i = 0; i < iters; i++ )
            {
                    for ( int j = 0; j < size; j++ )
                    {
                            res = funcs[ j ]( res );
                    };
            };
            end_time = clock();
            float execution = ((float)(end_time - beg_time) / CLOCKS_PER_SEC);
            std::cout << name << " creation time: " << creation << " execution time: " << execution << " result: " << res << "\n";
    }
    
    int main(int c, char * * v) 
    {
            test<int(*)(int)>( [](int i) {return i % 2 ? f1 : f2; }, "simple &function test" );
    
            test<std::function<int(int)>>( [](int i) {return i % 2 ? f1 : f2; }, "functor &function test" );
    
            test<std::function<int(int)>>( [](int i) {return i % 2 ? std::bind( &F::calc, &a1, _1 ) : std::bind( &F::calc, &a2, _1 ); }, "functor &object test" );
    
            test<my_ftor>( [](int i) {return i % 2 ? my_ftor( &a1, &F::calc ) : my_ftor( &a2, &F::calc ); }, "obj->*meth struct test" );
    
            std::cout << "END\n";
            return 0;
    }

    http://ideone.com/1iNzR
    Чем код так долго занимается?
    simple &function test creation time: 0.05 execution time: 0.09 result: 5000000
    functor &function test creation time: 0.51 execution time: 0.14 result: 5000000
    functor &object test creation time: 1.25 execution time: 0.14 result: 5000000
    obj->*meth struct test creation time: 0.12 execution time: 0.05 result: 5000000
    END

    LispGovno, 05 Февраля 2014

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