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

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

    +56

    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
    #	define S_1(X,...)				\
    	template<class T, int N>		\
    	T X(const V<T, N>& v)			\
    	{								\
    		return v.X;					\
    	}
    #	define S_2(X,Y,...)				\
    	template<class T, int N>		\
    	V<T, 2> X##Y(const V<T, N>& v)	\
    	{								\
    		return V<T, 2>(v.X, v.Y);	\
    	}
    #	define S_3(X,Y,Z,...)				\
    	template<class T, int N>			\
    	V<T, 3> X##Y##Z(const V<T, N>& v)	\
    	{									\
    		return V<T, 3>(v.X, v.Y, v.Z);	\
    	}
    #	define S_4(X,Y,Z,W,...)					\
    	template<class T, int N>				\
    	V<T, 4> X##Y##Z##W(const V<T, N>& v)	\
    	{										\
    		return V<T, 4>(v.X, v.Y, v.Z, v.W);	\
    	}
    
    #	define S_E(S, X, Y, Z)	\
    	S(x, X, Y, Z);S(y, X, Y, Z);S(z, X, Y, Z);S(w, X, Y, Z);S(O, X, Y, Z);S(I, X, Y, Z);
    #	define S_E1(E, S, Z, W)	\
    	E(S, x, Z, W);			\
    	E(S, y, Z, W);			\
    	E(S, z, Z, W);			\
    	E(S, w, Z, W);			\
    	E(S, O, Z, W);			\
    	E(S, I, Z, W);
    
    #	define S_E2(E, S, W)	\
    	S_E1(E, S, x, W);		\
    	S_E1(E, S, y, W);		\
    	S_E1(E, S, z, W);		\
    	S_E1(E, S, w, W);		\
    	S_E1(E, S, O, W);		\
    	S_E1(E, S, I, W);
    
    #	define S_E3(E, S)	\
    	S_E2(E, S, x);		\
    	S_E2(E, S, y);		\
    	S_E2(E, S, z);		\
    	S_E2(E, S, w);		\
    	S_E2(E, S, O);		\
    	S_E2(E, S, I);
    
    	S_E1(S_E, S_2, void, void);
    	S_E2(S_E, S_3, void);
    	S_E3(S_E, S_4);
    
    // Где-то выше
    template<class T, int N>
    struct V;
    template<class T>
    struct V<T, 2>
    {
    	V(T x, T y) : x(x), y(y) {}
    	T x,y;
    	T O = 0;
    	T I = 1;
    };
    template<class T>
    struct V<T, 3>
    {
    	V(T x, T y, T z) : x(x), y(y), z(z) {}
    	T x,y,z;
    	T O = 0;
    	T I = 1;
    };
    template<class T>
    struct V<T, 4>
    {
    	V(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
    	T x,y,z,w;
    	T O = 0;
    	T I = 1;
    };

    Этот код рабочий и используется во многих местах моего проекта.
    Я его написал когда-то давно и уже забыл, как оно функционирует, но оно генерирует очень много (около 1.5k) функций.

    -Eugene-, 27 Июля 2014

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

    +90

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    const struct TExceptionSafety {
                TQueue& _queue;
                ::std::condition_variable& _pushToQueue;
                ~TExceptionSafety(){
                    if(!this->_queue.empty())
                        this->_pushToQueue.notify_one();
                }
            } exceptionSafety = {_queue, _pushToQueue};//Use BOOST_SCOPE_EXIT, Luke!

    laMer007, 23 Апреля 2014

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

    +24

    1. 1
    int f(int = 7, int * = nullptr, int (*(*)(double))[3] = nullptr){

    http://ideone.com/BcZ7Ja

    LispGovno, 02 Февраля 2014

    Комментарии (36)
  5. Куча / Говнокод #14443

    +126

    1. 1
    2. 2
    3. 3
    4. 4
    @echo off
    chcp 1251
    mygame.exe
    chcp 866

    Оттуда.

    LispGovno, 30 Января 2014

    Комментарии (36)
  6. PHP / Говнокод #13853

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $count = count($array);
    
    // Говорю коллеге: "У тебя там деление на ноль, исправь". 
    // После этого появилось следующее...
    if ( $count == 0 ) $count = 1;
    
    $result = (int) ((1/$count) * SOME_VALUE1 + SOME_VALUE2);

    Код, блять, Хемминга

    bot, 26 Сентября 2013

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

    −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
    #include <iostream>
    using namespace std;
    
    struct NG
    {
    	template<class T>
    	struct get
    	{
    		typedef typename T::f type;
    	};
    };
    
    template <typename T, typename NameGetter>
    struct has_member_impl
    {
        typedef char matched_return_type;
        typedef long unmatched_return_type;
        
        template <typename C>
        static matched_return_type f(typename NameGetter::template get<C>*);
        
        template <typename C>
        static unmatched_return_type f(...);
        
    public:
        static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
    };
    
    template <typename T, typename NameGetter>
    struct has_member{
       enum { value = has_member_impl<T, NameGetter>::value };
     };
     
     class T{};
    
    int main() {
    	cout<<has_member<T, NG>::value;
    	return 0;
    }

    http://ideone.com/4LDGhZ

    LispGovno, 04 Сентября 2013

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

    +9

    1. 1
    2. 2
    3. 3
    HRESULT hr = ReadGenericXMLFile(srcStorage, pagePath, result);
      if (hr == S_FALSE) return STG_E_FILENOTFOUND;  // File must exist
      if (FAILED(hr)) return hr;

    Могу понять, обратное, когда вызывающая функция просто возвращает "false" при любом неудачном вызове внутренней функции: нет файла / нет доступа / runtime error и т.д. Здесь же наоборот, при "общем" неудачном вызове внутренней функции возвращается "конкретное" сообщение об ошибке.

    Fogbit, 25 Июля 2013

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

    +135

    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
    switch (curWpn)
    {
        case WeaponType.Doublegun: DrawNumber(doublegunAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, doublegunAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(doublegunI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Grenade: DrawNumber(grenadeCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, grenadeCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(grenadeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), grenadeTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Knife: spriteBatch.Draw(knifeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Launcher: DrawNumber(rocketCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, rocketCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(launcherI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), launchTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Revolver: spriteBatch.Draw(revolverI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Cannon: DrawNumber(cannonAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, cannonAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(cannonI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), cannonTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Laser: DrawNumber(laserAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, laserAmmoCnt > 0 ? Color.White : Color.Red); break;
        case WeaponType.Minigun: DrawNumber(minigunAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, minigunAmmoCnt > 0 ? Color.White : Color.Red); break;
    }
    //в другом месте
    switch (curWpnIndex)
    {
        case 0: curWpn = WeaponType.Knife; break;
        case 1: curWpn = WeaponType.Revolver; break;
        case 2: curWpn = WeaponType.Doublegun; break;
        case 3: curWpn = WeaponType.Laser; break;
        case 4: curWpn = WeaponType.Minigun; break;
        case 5: curWpn = WeaponType.Rifle; break;
        case 6: curWpn = WeaponType.Grenade; break;
        case 7: curWpn = WeaponType.Launcher; break;
        case 8: curWpn = WeaponType.Cannon; break;
    }

    Это неописуемо. Нашел у себя...
    Видимо, придется снова идти мыться.

    RaZeR, 15 Июля 2013

    Комментарии (36)
  10. Java / Говнокод #13284

    +83

    1. 1
    2. 2
    3. 3
    4. 4
    while (today.before(endTrial)) {
    	today.add(Calendar.DAY_OF_MONTH, 1);
    	daysBetween++;
    }

    считаем разницу между двумя датами

    wooddy, 02 Июля 2013

    Комментарии (36)
  11. Pascal / Говнокод #13210

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function IPP (var i: integer): integer;
    begin
      Result := i;
      Inc(i);
    end;

    TarasB, 21 Июня 2013

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