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

    +164.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int _I_ = 0;
    if (x > GetConstVal ())
       _I_ = 1;
    int ka = (_I_) * k;
    int kaka = (_I_); //Это случайно получилось :(

    Просто просится наложить...

    guest, 27 Января 2009

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

    +155

    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
    void SimpleTest::testTrivial() {
        wxTst::TempInteractive interactive;
        wxTst::ModalDialogTimer timer(wxID_OK);
       // *** Loop up top level containers ***
        CPPUNIT_ASSERT_MESSAGE ("Application top window invalid", 
    			    wxTheApp->GetTopWindow () != NULL);
        wxMDIParentFrame *topFrame = 
    	dynamic_cast< wxMDIParentFrame * >(wxTheApp->GetTopWindow ());
        CPPUNIT_ASSERT_MESSAGE ("Top window is not an MDI Parent frame", 
    			    topFrame != NULL);
        wxMenuBar *menuBar = topFrame->GetMenuBar ();
        CPPUNIT_ASSERT_MESSAGE ("Menubar not found", menuBar != NULL);
    
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        // *** Check menu item ***
        int platformMenuItemId = menuBar->FindMenuItem (_("Advanced"), 
                MC _T("Platform Specific Example"));
        CPPUNIT_ASSERT_MESSAGE ("Menu item ID 'platformMenuItem' not found",
                platformMenuItemId != wxNOT_FOUND);
        wxMenuItem *platformMenuItem = menuBar->FindItem (
                platformMenuItemId);
        CPPUNIT_ASSERT_MESSAGE ("Menu item 'platformMenuItem' not found",
                platformMenuItem != NULL);
        wxTst::EventSimulationHelper::SelectMenuItem (
                platformMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        wxWindow* wdw = topFrame->FindWindow(_T("platform_child"));
        if (wdw == NULL)
    	wdw = wxWindow::FindWindowByName(_T("platform_child"));
        CPPUNIT_ASSERT_MESSAGE("First Child not found", wdw != NULL);
        wxMDIChildFrame* child1 = dynamic_cast<wxMDIChildFrame*>(wdw);
        CPPUNIT_ASSERT_MESSAGE("Window isn't an MDI Child", child1 != NULL);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        wxTst::EventSimulationHelper::SelectMenuItem (
                platformMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
    
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
    
        wxMDIChildFrame* child2 = topFrame->GetActiveChild();
        CPPUNIT_ASSERT_MESSAGE("Second child not found", child2 != NULL);
        CPPUNIT_ASSERT_MESSAGE("Second child same as first ", child2 != child1);
    
        child2->Close();
    
        int derived_toolMenuItemId = menuBar->FindMenuItem (_("Advanced"),
                MC _T("Custom Class Example"));
        CPPUNIT_ASSERT_MESSAGE ("Menu item ID 'derived_toolMenuItem' not found",
                derived_toolMenuItemId != wxNOT_FOUND);
        wxMenuItem *derived_toolMenuItem = menuBar->FindItem (
                derived_toolMenuItemId);
        CPPUNIT_ASSERT_MESSAGE ("Menu item 'derived_toolMenuItem' not found",
                derived_toolMenuItem != NULL);
        wxTst::EventSimulationHelper::SelectMenuItem (
                derived_toolMenuItemId, topFrame);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
    
         wxWindow *custom_child = 
    	 wxWindow::FindWindowByName (_T("custom_class_child"));
         CPPUNIT_ASSERT_MESSAGE ("Container window for button 'wxID_OK' not found", 
     			    custom_child != NULL);
    //    interactive.ShowCurrentGui (_T(__FILE__), __LINE__);
        wxWindow *wxID_OKWdw4 = custom_child->FindWindow (XRCID("wxID_OK"));
        CPPUNIT_ASSERT_MESSAGE ("Window for button 'wxID_OK' not found", 
                wxID_OKWdw4 != NULL);
        wxTst::EventSimulationHelper::ClickButton (wxID_OKWdw4->GetId (), 
                wxID_OKWdw4);
        wxTst::WxGuiTestHelper::FlushEventQueue ();
        CPPUNIT_ASSERT_MESSAGE("OK Button didn't hide Mac Specific Dialog",
    			   custom_child->IsShown() == false);
    
    
    
    
    }

    Источник: метод примера из wxGuiTesting

    guest, 27 Января 2009

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

    +35.9

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    void Gllibform::setYear(int year)
    {
    	if ( (!is_connection) && ( (_IRZ=="t0406") || (_IRZ=="t0306") ) )
    	{
    		defaultDB = (QSqlDatabase*)year;
    		is_connection = true;
    	} else {
    		plgod = year;
    	}
    }

    Отформатировано для удобочитаемости.
    Цель кода - хз.
    ИРЗ - это Информационно-расчётная задача (номер модуля).
    Приведение int'а к подключению БД - это просто финиш...

    guest, 20 Января 2009

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

    +28

    1. 1
    http://www.xs4all.nl/~weegen/eelis/analogliterals.xhtml

    guest, 18 Января 2009

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

    +39.1

    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
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define N 50
    #define K 6
    main()
    {int i,j,n,error,max,imax,min=0,imin=0;
    int a[N][K],b[N][K];
    long c[N],r;
    do
         {error=0;
            printf("Vvedite kol-vo raznih dat: ");
            scanf("%d",&n);
            if(n<1 || n>N)
                {printf("\nVi vveli kol-vo elementov massiva men'she 2 ili bol'she 50!\nPovtorite vvod!\n\n");
                 error=1;
                }
         }
    while (error);
        printf("\nDati v formate GG MM DD cc mm ss:\n");
        for(i=0;i<n;i++)
         {do a[i][0]=rand()%2008; while(a[i][0]<1970);
            do a[i][1]=rand()%13; while(a[i][1]<1);
            do a[i][2]=rand()%32; while(a[i][2]<1);
                 a[i][3]=rand()%24;
                 a[i][4]=rand()%60;
                 a[i][5]=rand()%60;
                 printf("\nData %d:",i+1);
                 for (j=0;j<K;j++)
                    printf(" %.2d",a[i][j]);
            }
    max=0;
    for(i=0;i<n;i++)
        if (a[i][0]>max)
         {
            max=a[i][0];
            imax=i;
         }
    min=a[0][0];
    for(i=0;i<n;i++)
        if (a[i][0]<min)
         {
            min=a[i][0];
            imin=i;
         }
    for(i=0;i<2;i++)
    {
        for(j=0;j<K;j++)
         {
            b[i][j]=a[imax][j];
         }
        imax=imin;
    }
    for(i=0;i<2;i++)
    {
    printf("\n");
    for(j=0;j<K;j++)
        printf(" b[%d,%d]=%d",i,j,b[i][j]);
    }
    for(i=0;i<2;++i)
         {
            c[i]=(b[i][0]-1971)*31536000;
            c[i]+=b[i][2]*86400;
            c[i]+=b[i][3]*3600;
            c[i]+=b[i][4]*60;
            c[i]+=b[i][5]-86400;
            c[i]+=((b[i][0]-69)/4)*86400;
            if(b[i][1]>12)
                c[i]+=31*86400;
            if(b[i][1]>11)
                c[i]+=30*86400;
            if(b[i][1]>10)
                c[i]+=31*86400;
            if(b[i][1]>9)
                c[i]+=30*86400;
            if(b[i][1]>8)
                c[i]+=31*86400;
            if(b[i][1]>7)
                c[i]+=31*86400;
            if(b[i][1]>6)
                c[i]+=30*86400;
            if(b[i][1]>5)
                c[i]+=31*86400;
            if(b[i][1]>4)
                c[i]+=30*86400;
            if(b[i][1]>3)
                c[i]+=31*86400;
            if(b[i][1]>2)
                c[i]+=28*86400;
            if(b[i][1]>1)
                c[i]+=31*86400;
            if(((b[i][1]==2 && b[i][2]==29) || b[i][1]>2) && b[i][1]>1 && b[i][0]%4==0 && b[i][0]%100!=0 || b[i][0]%400==0)
             c[i]+=151936;
         }
    printf("\n\nDati v formate vremennoi metki UNIX:\n\n");
    for(i=0;i<2;i++)
         {printf("Data %d: %ld\n",i+1,c[i]);
         }
          r=c[0]-c[1];

    Нетленное твАрение участницы Truegirl с vingrad.ru
    Глядя на ЭТО, начинаешь понимать: женщин в программинг пускать нельзя.
    НЕ РЕКОМЕНДУЕТСЯ смотреть код после плотного приёма пищи :lol:

    guest, 15 Января 2009

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

    +22

    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
    #include <stdlib.h>
    #include <stdio.h>
    #include <cerr.h>
    #include <bash.h>
    
    #define INFINITE ~0u
    
    int main(int argc, char *argv[]) {
        printf("Hello world!\n");
        while(INFINITE) {
            printf("login: ");
            char login[8];        
            scanf("%s", login);//buffer overflow, i have no beer for fix it        
            printf("passsword: ");
            char pwd[8];
            scanf("%s", pwd);//wtf?! beer! beer! beer!
            if(0.25 > rand() / (float)RAND_MAX) {
                 startBash(login);
            } else {
                 printf("Login is incorrect!\n");
            }
            if(0.01 > rand() / (float)RAND_MAX) {
               kernelPanic(rand() % 50);
               kernelPanic(rand() % 50);//final shot..DIE! or beer..
            }
        }
        return 0;
    }

    guest, 14 Января 2009

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

    +46.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    int checkSpecialPrice(ItemId _item, TransDate _fromDate, TransDate _toDate)
    {
      if (specialPrice == true)
      {
       return 1;
      }
      else
      {
       return 0;
      }
    }

    Такой вот метод класса. И весь класс такой же.
    Язык, на самом деле, был X++, но сути это не меняет =)

    guest, 14 Января 2009

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

    +18.3

    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
    MyObject a;
    switch(id)
    {
    case id_1:
    ....
    break;
    
    case id_2:
    break;
    
    case id_3:
    MyObject a;
    a = value;
    break;
    }
    
    res = a;

    псевдо код моей ошибки(((

    guest, 12 Января 2009

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

    +40

    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
    class T
    {
    private:
      T();
      ~T();
    public:
      static T& instance()
      {
        static T t[5];
        return t[rand() % 6];
      }
      ...
    };

    придумалось при обсуждении паттерна синглтон и его возможых реализаций.
    "Антисинглтон" или "Русская рулетка".

    guest, 07 Января 2009

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

    +31.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /* ...*/ someMethod (/*someargs*/) {
        //...
    	Create();
    	Create();
    	Create();
    	Create();
    	Create();
        //...
    }

    guest, 05 Января 2009

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