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

    +3

    1. 1
    2. 2
    3. 3
    class ... {
        void enable(bool enabled = false);
    }

    tar_gz, 30 Июня 2018

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

    −1

    1. 1
    std::function<CPlayer*> pickedUp = nullptr;

    vadzz, 06 Июня 2018

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

    +1

    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
    void Table::draw() {
    	SetConsoleCursorPosition(consOutput, { 0,0 });
    	for (int i = 0; i < lY*(lengthOfCageY + 1) + 1; i++) {
    		for (int j = 0; j < lX*(lengthOfCageX + 1) + 1; j++) {
    			if (i == 0 && j == 0)
    				cout << (char)201;
    			else if (i == 0 && j == lX*(lengthOfCageX + 1))
    				cout << (char)187;
    			else if (i == lY*(lengthOfCageY + 1) && j == 0)
    				cout << (char)200;
    					else
    						if (i == lY*(lengthOfCageY + 1) && j == lX*(lengthOfCageX + 1))
    							cout << (char)188;
    						else
    							if (i == 0)
    								if (j % (lengthOfCageX + 1) == 0)
    									cout << (char)203;
    								else
    									cout << (char)205;
    							else
    								if (i == lY*(lengthOfCageY + 1))
    									if (j % (lengthOfCageX + 1) == 0)
    										cout << (char)202;
    									else
    										cout << (char)205;
    								else
    									if (j == 0)
    										if (i % (lengthOfCageY + 1) == 0)
    											cout << (char)204;
    										else
    											cout << (char)186;
    									else
    										if (j == lX*(lengthOfCageX + 1))
    											if (i % (lengthOfCageY + 1) == 0)
    												cout << (char)185;
    											else
    												cout << (char)186;
    										else
    											if (i % (lengthOfCageY + 1) == 0 && j % (lengthOfCageX + 1) == 0)
    												cout << (char)206;
    											else
    												if (i % (lengthOfCageY + 1) == 0)
    													cout << (char)205;
    												else
    													if (j % (lengthOfCageX + 1) == 0)
    														cout << (char)186;
    													else
    														cout << " ";
    		}
    		cout << endl;
    	}
    }

    И прекрасно и ужасно. Плохой но хороший код для вывода красивой таблицы в консоль

    the-alator, 03 Июня 2018

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

    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
    // Tools.cpp
    
    class SleepQClass : public QThread
    {
    public:
    	static void Sleep( int ms )
    	{
    		msleep(ms); // static msleep is protected
    	}
    };
    
    void SleepQ( int ms )
    {
    	SleepQClass::Sleep(ms);
    }

    Паблик Морозов. Делаем глобальную функцию Sleep, чтобы можно было вызывать из любого места и потока. А что, реализация все равно тот же Sleep(DWORD dwMilliseconds) вызывает.

    Steve_Brown, 28 Мая 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void Foo::singleShot()
    {
        QTime delay = QTime::currentTime().addMSecs(50);  
        while(QTime::currentTime() < delay ) {
           QCoreApplication::processEvents(QEventLoop::AllEvents, 5;
        }
        // do something
    }

    Вот такой бриллиант инженерной мысли, написанный с использованием фреймворка Qt.
    Товарисч ещё спрашивал, чем его реализация хуже чем QTimer::singleShot() :D

    Titus_PuIIo, 26 Мая 2018

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

    +3

    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
    using namespace std;
    #include <typeinfo>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string>
    #include <math.h>
    #include <stdarg.h>
    
    template <unsigned FRA,unsigned EXP>
    struct F {
        union{
            float     f;
            unsigned ui;
            unsigned ef : FRA+EXP;	    
            struct
            {
    	        unsigned f : FRA;
    	        unsigned e : EXP;
    	        unsigned s : 1;
            } s;
        };
        F (double x){f=x;}
        F operator =(const double x) { 
            f=x; return *this;
        }    
        
    #define NOOP ;
    #define  UN(OP,BODY, RET)   float    operator OP(	) { BODY; return RET;}
    #define BIN(OP,BODY, RET)   F    operator OP(F other	) { BODY; return RET;}
    #define BINF(OP,BODY,RET)   F    operator OP(const float other) { BODY; } BIN(OP,BODY,RET)
    #define CMP(OP)        bool operator OP(const F& other) 
    
        UN ( -  ,   s.s^=1   ,     (f)       )
        BIN( += , f+=other.f , (  *this  )   )
        BIN( +  , NOOP       , { f+other.f}   )
        BIN( -  ,++other.s.s , {*this+other} )
        BIN( *  ,   NOOP    ,   fmul(f,{other})        )
        BIN( /  , div(other), (  *this  ) )
        BINF(*=, ui=fmul(*this   ,{other}).ui, (  *this  )   )  
        BINF(/=, ui=fmul(*this,rcp(other)).ui, (  *this  )   )  
    
    
        CMP(==){
            return other.ui==ui;
        }    
    
        F out(string s) const{
            printf("> %s%f\n",s.c_str(),f);
        }
        F plus(F other)
        {
            f+=other.f;
            return *this;        
        }    
        
        F div(F other)
        {
            ui=fmul(rcp(other),{f}).ui;
            return *this;        
        }    
        F sqrt()
        {
            s.e-=127;
            ui>>=1; 
            s.f-=(s.f>>4);
            s.e+=127;        
            return *this;        
        }
        F pow(int n)
        {
            s.e-=127;
            ui*=n; 
            ef+=(ef>>4);
            ef-=(ef>>9);
            s.e+=127;
            return *this;
        }    
    
    private:    
        static F rcp(F f) {
            f.s.e=(~f.s.e-2);
            f.s.f=(~f.s.f-2);
            return f;
        }
        
        static F fmul(F r,F b)
        {
            r.s.s   ^= b.s.s;
            r.ef += ((r.s.f&b.s.f)>>4);
            r.ef += b.ef ;
            r.s.e+= 129;
            return r;
        }
    
     
    };
    
    using F32 = F<23,8>;
    
    static F32 of32(float x)

    Царь был прав. Во всём.
    Патамучто это плавающий питух, который априори говно. И чем вы быстрее это поймёте, чем будет лучше.

    В соответствии со своим пониманием сделал мммаксимально простую реализацию плавающих питухов произвольного размера.
    Строго на интах.


    Пример здесь:
    uhttps://ideone.com/dDrj7s

    3.14159265, 16 Мая 2018

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

    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
    https://github.com/dotnet/coreclr/blob/a589e3926a1780256fdb52376f8681fe047daf54/src/vm/i386/cgenx86.cpp#L1551-L1553
    
        PAL_TRY(Param *, pParam, &param)
        {
            unsigned char buffer[16];
            DWORD* dwBuffer = NULL;
    
            DWORD maxCpuId = getcpuid(0, buffer);
    
            if (maxCpuId < 1)
                goto lDone;
    
            dwBuffer = (DWORD*)buffer;
    
            if (dwBuffer[1] == 'uneG') {
                if (dwBuffer[3] == 'Ieni') {
                    if (dwBuffer[2] == 'letn')  {  // get SMT/multicore enumeration for Intel EM64T

    С каких пор в одинарные кавычки можно писать больше одного символа? Это какое-то MSVC или что?

    j123123, 09 Мая 2018

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    // https://github.com/dotnet/coreclr/blob/a589e3926a1780256fdb52376f8681fe047daf54/src/vm/binder.cpp#L503-L511
    
    const MscorlibBinder::OffsetAndSizeCheck MscorlibBinder::OffsetsAndSizes[] =
    {
        #define DEFINE_CLASS_U(nameSpace, stringName, unmanagedType) \
            { PTR_CSTR((TADDR) g_ ## nameSpace ## NS ), PTR_CUTF8((TADDR) # stringName), sizeof(unmanagedType), 0, 0, 0 },
        
        #define DEFINE_FIELD_U(stringName, unmanagedContainingType, unmanagedOffset) \
            { 0, 0, 0, PTR_CUTF8((TADDR) # stringName), offsetof(unmanagedContainingType, unmanagedOffset), sizeof(((unmanagedContainingType*)1)->unmanagedOffset) },
        #include "mscorlib.h"
    };

    Дух старой школы всё еще живет в майкрософт

    j123123, 08 Мая 2018

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

    −1

    1. 1
    2. 2
    3. 3
    j123123, ты вообще пишешь полезный код или занимаешься 
    только тем, что постишь на говнокод советы космического масштаба
    и комической же глупости о том, как всё оптимизировать?

    dm_fomenok, 07 Мая 2018

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    struct Bar {};
    
    class Foo {
    public:
        Bar& bar() const { return *bp; }
    
    private:
        Bar b;
        Bar * const bp = &b;
    };

    https://wandbox.org/permlink/7JPzrvslrUwbvREb

    Как называется данный говнопаттерн?

    Elvenfighter, 27 Апреля 2018

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