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

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

    +23

    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
    struct S* gpS;
    
    struct S
    {
       // this class has no user-defined default ctor
       void *operator new (size_t size, void*p, int i)
       {
          ((S*)p)->i = i;   // ordinarily, should not initialize
                            // memory contents inside placement new
          return p;
       }
       int i;
    };

    Код с сайта майкрософт.

    LispGovno, 09 Января 2013

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

    +23

    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
    #include <iostream>
    using namespace std;
     
    class Class {
    public:
        explicit Class(int a) : m_int(a) {}
        
        int get() const { return m_int; }
        
        void swapThis(int a) {
            delete this;
            Class **thisptr = reinterpret_cast<Class**>(&a);
            thisptr--;
            *thisptr = new Class(a);
            cout << "this: " << this << endl
                 << "that: " << *thisptr << endl;
        }
    private:
        int m_int;
    };
     
    int main() {
        Class *s = new Class(13);
        s->swapThis(42);
        cout << s->get() << endl;
        delete s;
        
        return 0;
    }

    Что творит хакингкостылинг + инлайн методы.
    http://ideone.com/5Kyitw

    Elvenfighter, 29 Декабря 2012

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

    +23

    1. 1
    2. 2
    typedef const AbstractParameter ConstAbstractParameter;
    class Parameter: public ConstAbstractParameter{

    GCC это не компилирует, но в 2008 ms vs компилируется без предупреждений. Я это как увидел, так сразу переписал на

    class Parameter: public AbstractParameter{

    А вот теперь я дома и не могу заснуть. Гложет чувство, что я поступил не правильно. Такое чувство как-будто этот const, пусть и не в рамках стандарта С++, но что-то он делал.

    LispGovno, 20 Ноября 2012

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

    +23

    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 <iostream>
    #include <stdlib.h>
    #include <typeinfo>
     
    using namespace std;
     
    #define ololo for(volatile register int i=0;i<10;++i);
     
    struct VB
    {
            virtual void f() const =0;
    };
     
    class V1: public VB
    {
            void f() const {ololo}
    };
     
    class V2: public VB
    {
            void f() const {ololo}
    };
     
    struct TU1
    {
            inline void f() const {ololo}
    };
     
    struct TU2
    {
            inline void f() const {ololo}
    };
     
    struct TUB
    {
            const type_info* type;
            union 
            {
                    TU1 tu1;
                    TU2 tu2;
            };
     
            template<class T>
            void ctor()
            {
                    this->type=&typeid(T);
            }
            
            template<class T>
            inline void call(const T& f)
            {
                    if(this->type==&typeid(TU1))
                            f(this->tu1);
                    else
                            f(this->tu2);
            }
    };
     
    enum {N=1000, N2=N*50};
     
    int main() {
            cout<<"ok"<<endl;
            {
                    VB*v[N];
                    for(int i=0;i<N;++i)
                            if(rand()%2)
                                    v[i]=new V1;
                            else
                                    v[i]=new V2;
                    volatile clock_t a=clock();
                    for(int j=0;j<N2;++j)
                            for(int i=0;i<N;++i)
                                    v[i]->f();
                    volatile clock_t b=clock();
                    cout<< (double)(b - a) / CLOCKS_PER_SEC<<endl;
            }
            cout<<"ok"<<endl;
            {
                    TUB v[N];
                    for(int i=0;i<N;++i)
                            if(rand()%2)
                                    v[i].ctor<TU1>();
                            else
                                    v[i].ctor<TU2>();
                    struct Continuation
                    {
                            inline void operator()(const TU1& a) const {a.f();}
                            inline void operator()(const TU2& a) const {a.f();}
                    } cps;
                    volatile clock_t a=clock();
                    for(int j=0;j<N2;++j)
                            for(int i=0;i<N;++i)
                                    v[i].call(cps);
                    volatile clock_t b=clock();
                    cout<< (double)(b - a) / CLOCKS_PER_SEC<<endl;
            }
            cout<<"ok"<<endl;
            return 0;
    }

    http://ideone.com/plFaLM
    Тут в соседней теме разгорелся спор, что быстрее - полиморфизм виртуальных функций или полиморфизм tagget union. По сути последнее - выбор по if нужной виртуальной функции. Говорят в Java быстрее второе.
    Тема родилась из http://govnokod.ru/12025#comment158188
    Получилось по результатам измерений:
    Виртуальные функции: 1.8 секунд.
    tagget union: 1.94 секунд.
    Притом это всего 2 полиморфных типа в tagget union, а если рост числа полиморфных классов будет расти, то разрыв между виртуальными функциями и tagget union только увеличится. Притом производительность tagget union будет только падать.
    Тема поднята ещё со взглядом на функциональные языки. Это ведь там так модны ADT с постоянным внутри ifподобным паттернматчингом по ним.
    Жду указания на косяки или способы поднять производительность tagget union.

    LispGovno, 31 Октября 2012

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

    +23

    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
    %:include <iostream>
     
    int main(int argc, char *argv<::>) 
    <%
        if (argc > 1 and argv<:1:> not_eq '\0') <%
            std::cout << "Hello " << argv<:1:> << '\n';
        %>
        std::cout<<"ko"<<std::endl;
    %>
     
     
    
    ??=include <iostream>
     
    int main(int argc, char *argv??(??)) 
    ??<
        if (argc > 1 and argv??(1??) not_eq '\0') ??<
            std::cout << "Hello " << argv??(1??) << '\n';
        ??>
        std::cout<<"ko"<<std::endl;
    ??>

    http://liveworkspace.org/code/150ad59b81b309bbffed963829f4fc9e
    http://liveworkspace.org/code/c64104e4272af4d89f2f74c35c5c2ee3
    Просто оставлю это здесь.

    HaskellGovno, 20 Августа 2012

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

    +23

    1. 1
    QHash<QByteArray, QSharedPointer<KeywordAnalyzerResult::Statistics> >::const_iterator i = res.result()->constBegin();

    Создание STL-style итератора для Qt-ных контейнеров обычно выглядит уродски.

    viktorious, 10 Августа 2012

    Комментарии (14)
  8. C++ / Говнокод #11458

    +23

    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
    const Tifon& Tifon::operator=(const Tifon& Buffer)
    {
            assert(&Buffer!=this);
            if(&Buffer==this)
                    return *this;
            Tifon OldForExceptionSafe(*this);
            try{
                    this->~Tifon();
                    ::new((void*)this)Tifon(Buffer);
            }catch(...){//try restore
                    ::new((void*)this)Tifon(OldForExceptionSafe);
            }
            return *this;
    };
     //...
    namespace std
    {
            const Tifon&swap (Tifon& a, Tifon& b) {
            assert(&a!=&b);
            if(&a==&b)
                    return a;
            Tifon c(a);
            a=b;
            b=c;
            }
    };

    USB, 22 Июля 2012

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

    +23

    1. 1
    2. 2
    if(this==NULL)
      return;

    HaskellGovno, 04 Июля 2012

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

    +23

    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
    <?php
    	class AppController extends Controller {
    	 
    	  var $uses = array('Config', "Cats");
    	 
    		  function beforeFilter() 
    		  {
    		    $config1 = $this->Config->find('list', array('fields'=>array('key', 'value')));
    		    $category1 = $this->Cats->findAll();
    		    
    		    $this->set(compact('config1'));
    		    $this->set(compact('category1'));
    		    
    		  }
    		  
    		  
    	}
    ?>

    тупой код =)

    guest, 23 Января 2009

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

    +23

    1. 1
    $z=(($m+1)-1);

    Кусочек из одного похек скрипта

    guest, 19 Января 2009

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