1. C++ / Говнокод #3200

    +116

    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
    class DllContainer
    {
      DllContainer()
      {
        // тут грузятся дллки в количестве N.
        // LoadLibrary() + некоторые операции
      }
      
      ~DllContainer()
      {
        // FreeLibrary() и т.п.
      }
    
      template <class T>
      T* GetComponent(ComponentID id)
      {
        // аналог QueryInterface.
        // ищет компонент, проверяет можно ли статик_кастить
        // и вертает указатель нужного типа
      }  
    };
    
    class ComponentUser
    {
      void Method1()
      {
        DllContainer loader;
        SomethingDoer* comp = loader.GetComponent<SomethingDoer>(ID1);
        comp->DoSomething();
      }
      
      void Method2()
      {
        DllContainer loader;
        SomethingElseDoer* comp = loader.GetComponent<SomethingElseDoer>(ID2);
        comp->DoSomethingElse();
      }
      
      void MethodN()
      {
        DllContainer loader;
        ShitPerformer* comp = loader.GetComponent<ShitPerformer>(IDN);
        comp->PerformSomeShit();
      }
    };

    недавно обнаружил код примерно такого плана.
    крупный коммерческий проект...

    g26g, 12 Мая 2010

    Комментарии (49)
  2. C++ / Говнокод #3196

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /********************************************************************
    ОПЕРАЦИЯ ЛОГИЧЕСКОЕ ИСКЛЮЧАЮЩЕЕ ИЛИ
    ********************************************************************/
    static inline bool XOR(bool lhs, bool rhs)
    {
        return (lhs && !rhs) || ( !lhs && rhs);
    }

    Человек не знал, что есть стандартный xor...

    m08pvv, 11 Мая 2010

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

    +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
    #include "iostream"
    
    using namespace std;
    
    int main()
    {
    	cout << "Vvedite storonu a:";
    	int a;
    	cin >> a;
    	cout << "Vvedite storonu b:";
    	int b;
    	cin >> b;
    	cout << "Vvedite storonu c:";
    	int c;
    	cin >> c;
    	int g=1;
    	while(g=1){
    		if(a==0||b==0||c==0){ cout << "Ne treugolnik";
    		break;}
    		if(a<=b+c || c<=a+b || b<=a+c){ cout << "Daaa!!! Treugolnik";}
    		break;}
    	return 0;
    }

    Вот как мы узнаем, треугольник ли это по сторонам.

    hromjo, 11 Мая 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    string buf;
    ...
    char c_buf[MAX_LEN];
    strncpy(c_buf, buf.c_str(), MAX_LEN);

    в чём ошибка?

    skor4ik, 10 Мая 2010

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

    +116

    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 Epica
    {
    public:
    	signed int Value;
    };
    
    //...
    
    Epica* ValEp[10][17]; 
    
    //...
    
    ValEp[i][jj][0].Value;

    Угадайте, что с автором?

    Говногость, 09 Мая 2010

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

    +98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    template<unsigned AxesQount, class Conten>
    const Vector<AxesQount, Conten> Vector<AxesQount, Conten>::operator-(void) const
    {
        return *this*-1.0;
    };
    
    template<unsigned AxesQount, class Conten>
    const Vector<AxesQount, Conten> Vector<AxesQount, Conten>::operator+(void) const
    {
        return *this;
    };

    Чужой велосипед. Пытался использовать в своём проекте, но передумал.

    Говногость, 07 Мая 2010

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

    +100

    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
    int wmain()
    {
                    _rmCfg rmCfg;
                    double tt;
                    int i;
    
                            String *filePath=S"C:\\rm\\rm.cfg";
                            String * sqlstr;
                            rmCfg.isread=0;
                            String * dir[];
                            DateTime dt;
                            if (File::Exists(filePath))
                            {
                                    StreamReader *sr= new StreamReader(filePath);
                                    rmCfg.gosanPath=sr->ReadLine();
                                    rmCfg.iakServer=sr->ReadLine();
                                    rmCfg.iakUser=sr->ReadLine();
                                    rmCfg.iakPassword=sr->ReadLine();
                                    rmCfg.trackId=sr->ReadLine()->ToInt32(0);
                            //      rmCfg.trName=sr->ReadLine();
    
                                    Console::WriteLine(S"Viewing directory: ");
                                    Console::Write(rmCfg.gosanPath);
                                    Console::WriteLine();

    Писано было на втором фреймворке. Так бы и продолжал писать, если бы товарищ не намекнул про сериализацию.

    ursus, 05 Мая 2010

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

    +103

    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
    #include <iostream>
    #include <string>
    #include <boost/foreach.hpp>
    
    int main(int argc, char* argv[]) {
      std::string str = "Boost FOREACH!";
      char ch;
      if (boost::foreach_detail_::auto_any_t _foreach_col11 = boost::foreach_detail_::contain( ( str ) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else if (boost::foreach_detail_::auto_any_t _foreach_cur11 = boost::foreach_detail_::begin( _foreach_col11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else if (boost::foreach_detail_::auto_any_t _foreach_end11 = boost::foreach_detail_::end( _foreach_col11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else for (bool _foreach_continue11 = true; _foreach_continue11 && ! boost::foreach_detail_::done( _foreach_cur11 , _foreach_end11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) ; _foreach_continue11 ? boost::foreach_detail_::next( _foreach_cur11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) : (void)0) if (boost::foreach_detail_::set_false( _foreach_continue11 )) {} else for ( ch = boost::foreach_detail_::deref( _foreach_cur11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) ; ! _foreach_continue11 ; _foreach_continue11 = true) {
        std::cout << ch;
      }
      std::cout << std::endl;
      return 0;
    }

    Конечно, это не совсем говнокод, но... я офигел когда посмотрел во что превращается простой BOOST_FOREACH

    rudvil, 03 Мая 2010

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

    +89

    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
    void __fastcall TForm1::FormPaint(TObject *Sender)
    {
      for(int i=0;i<2;i++)
      {
        if(!White[i].Moves)
        {
          int j=0;
          for(int k=0;k<i;k++)
          {
            if(White[k].Position == White[i].Position)
            {
              j++;
            }
          }
          Image1->Canvas->MoveTo(Points[White[i].Position-1].X-20,Points[White[i].Position-1].Y - 30*j);
          Image1->Canvas->LineTo(Points[White[i].Position-1].X+20,Points[White[i].Position-1].Y - 30*j);
        }
      }
      //Image1->Canvas->LineTo(200,200);
    }

    Этот обработчик грузит проц. на 50 процентов и таймер не работает из-за него.
    Писал мой знакомый, который не любит продукты от борланда.
    В чем дерьмо? Думаю видно невооруженным глазом.

    fenryr, 30 Апреля 2010

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

    +73

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    ICQ::logInIcq( )
    {
          TLV   clid1,clid,clm,clmin,clless,clbild,cldistr,cllang,clcontr,t1;
          WSA   ws;
          int   packn;
          unsigned char st1[40];
    
       port=ControlIcqPropert.portIcqServer;        
       host=(char*)ControlIcqPropert.IcqServer;
       if((strlen(host)==0)|(port==0)) 
       {
          port=DEFAULT_SERVER_PORT;
          host=DEFAULT_SERVER_HOST;
       }
       if(strlen(password)<3) return 0;
    
       pn=sock.Connect( host,port );      
       packn=sock.Receive( ( char * )uc,sizeof( uc ),0,0 );
    
       if(  packn <= 0  ){return 1;}
       //SetIndic(10);
       tUin.type=0x0100;
       tUin.lenght[0]=0x00;//htons( ( BYTE )strlen( uin ) );
       tUin.lenght[1]=strlen(uin);
       memcpy( tUin.data,uin,strlen( uin ) );
       flap.chan_id=0x01;
       flap.Sequence+=0x0100;
       flap.datalenght[0]=0x00;
       flap.datalenght[1]=0x04;
       flap.data[0]=0x00;
       flap.data[1]=0x00;
       flap.data[2]=0x00;
       flap.data[3]=0x01;
       packn=sock.Send( ( const char * )&flap,10,0 );
       flap.Sequence+=0x0100;
       flap.chan_id=0x02;
       t1.type=0x1700;
       t1.lenght[0]=0x00;
       t1.lenght[1]=0x06;
       t1.data[0]=0x00;
       t1.data[1]=0x00;
       t1.data[2]=0x00;
       t1.data[3]=0x00;
       t1.data[4]=0x00;
       t1.data[5]=0x00;
       int lnum=0;
       lnum+=10;
       memcpy( &st1,&t1,lnum );
       memcpy( &st1[lnum],&tUin,strlen(uin)+4 );
       lnum+=strlen(uin)+4;
       
       unsigned char u1[4];
       u1[0]=0x00;
       u1[1]=0x4B;
       u1[2]=0x00;
       u1[3]=0x00;
       
       memcpy( &st1[lnum],&u1,4 );
       lnum+=4;
       memcpy( flap.data,&st1,lnum );
       flap.datalenght[0]=0x00;
       flap.datalenght[1]=0x1B;
       lnum+=6;
       packn=sock.Send( ( char * )&flap,lnum,0 );
       //memcpy( &flap,NULL,4096 );
       packn=sock.Receive( ( char * )&inflap,sizeof( inflap ),0 );
       memcpy( &uc,&inflap,packn );
       memcpy( &snac,&uc[6],packn-6 );
       memcpy( key,&snac.data[2],snac.data[1] );
       int ii;
       MD5_CTX Md5Ctx;
       HASH hash;
       MD5Init  (  &Md5Ctx  );
       MD5Update(  &Md5Ctx, (  unsigned char*  )password, strlen( password ) );
       MD5Final ( ( uchar*  )hash, &Md5Ctx  );
       MD5Init  (  &Md5Ctx  );
       MD5Update(  &Md5Ctx, (  unsigned char*  )key, snac.data[1] );
       MD5Update(  &Md5Ctx, (  unsigned char*  )hash, 16 );
       MD5Update(  &Md5Ctx, (  unsigned char*  )AIM_MD5_STRING, strlen( AIM_MD5_STRING ) );
       MD5Final ( (  uchar*  )hash, &Md5Ctx  );
    
       flap.chan_id=0x02;
       flap.Sequence+=0x0100;
       flap.datalenght[0]=0x00;
       flap.datalenght[1]=0x72;
       t1.lenght[0]=0x00;               //Not Lenght!!! it is SNAC!!!
       t1.lenght[1]=0x02;
       memcpy( uc,&t1,10 );
       memcpy( &uc[10],&tUin,13 );
       TLV auth_h;
       auth_h.type=0x2500;
       auth_h.lenght[0]=0x00;
       auth_h.lenght[1]=0x10;
       memcpy( &auth_h.data,&hash,16 );
       memcpy( &uc[23],&auth_h,20 );
       uc[43]=0x00;
       uc[44]=0x4c;
       uc[45]=0x00;
       uc[46]=0x00;
       clid1.type=0x0300;

    Много лет назад, будучи молодым программером писал абсолютное гавно. Была поставлена задача реализовать протокол оскар 11 в одной бухгалтерской системе. Полное отсутствие архитектуры приложения, бизнес-слоя. В общем мне тогда сказали что так писать не надо и с треском выгнали. После этого так перестал писать :-)

    ursus, 29 Апреля 2010

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