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

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

    +146

    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
    class User {
    
      protected $login;
      protected $password;
      protected $email;
    
      public function __construct($login, $password, $email) {
        $this->login = $login;
        $this->password = $password;
        $this->email = $email;
      }
    
      public function __get($name) {
        $reflector = new ReflectionClass($this);
        return $reflector->hasProperty($name) ? $this->{$name} : null;
      }
    
    }

    __proto__, 10 Марта 2013

    Комментарии (24)
  3. PHP / Говнокод #12709

    +152

    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
    function getTestDataById ($testid) {
    
    	$query="select * from mdl_test where id=".$testid."";
    	$result = mysql_query($query) or die('getTestDataById query failed: ' . mysql_error());
    
    	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
    	$courseid=$row['courseid'] ;
    	$moduleid=$row['moduleid'];
    	$name=$row['name'];
    	$maxscore=$row['maxscore'];
    	$successscore=$row['successscore'];
    	$attempts=$row['attempts'];
    	$dur=$row['dur'];
    	$showsuccessmessage=$row['showsuccessmessage'];
    	$successmessage=$row['successmessage'];
    	$showfailedmessage=$row['showfailedmessage'];
    	$failedmessage=$row['failedmessage'];
    	$showtestsuccessmessage=$row['showtestsuccessmessage'];
    	$testsuccessmessage=$row['testsuccessmessage'];
    	$showtestfailedmessage=$row['showtestfailedmessage'];
    	$testfailedmessage=$row['testfailedmessage'];
    	$freequestions=$row['freequestions'];
    	$questionsorder=$row['questionsorder'];
    	$defertest=$row['defertest'];
    	$totalperpage=$row['totalperpage'];
    	$showcorrectreply=$row['showcorrectreply'];
    	$showscore=$row['showscore'];
    	$limittype = $row['limittype'];
    	$annotation = $row['annotation'];
    
    	} // end while
    
    	$res=array('courseid'=>$courseid,
    			   'moduleid'=>$moduleid,
    			   'name'=>stripslashes($name),
    			   'maxscore'=>$maxscore,
    			   'successscore'=>$successscore,
    			   'attempts'=>$attempts,
    			   'dur'=>$dur,
    			   'showsuccessmessage'=>$showsuccessmessage,
    			   'successmessage'=>stripslashes($successmessage),
    			   'showfailedmessage'=>$showfailedmessage,
    			   'failedmessage'=>stripslashes($failedmessage),
    			   'showtestsuccessmessage'=>stripslashes($showtestsuccessmessage),
    			   'testsuccessmessage'=>stripslashes($testsuccessmessage),
    			   'showtestfailedmessage'=>stripslashes($showtestfailedmessage),
    			   'testfailedmessage'=>stripslashes($testfailedmessage),
    			   'freequestions'=>stripslashes($freequestions),
    			   'questionsorder'=>stripslashes($questionsorder),
    			   'defertest'=>stripslashes($defertest),
    			   'totalperpage'=>stripslashes($totalperpage),
    			   'showcorrectreply'=>stripslashes($showcorrectreply),
    			   'showscore'=>stripslashes($showscore),
    				'limittype' => stripslashes($limittype),  // Total 21 items
    				'annotation' => stripslashes($annotation));
    
    	return $res;
    
    	} // end of function

    От начальника отдела))) Как вам?))

    Krugly, 09 Марта 2013

    Комментарии (24)
  4. Java / Говнокод #12696

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public Double toDouble(String str){
    	if ((str==null)||(str.equals(""))) str = "0.0";
    	if ((str.contains(","))&&(!str.contains("."))) str = str.replace(",", ".");
    	return new Double(str);
    }

    Лишняя защита никогда не бывает лишней

    nafania217518, 06 Марта 2013

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

    +19

    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
    std::vector<int> data;
    std::vector<int> indexes;
    
    // ...
    
    for (int i = 0; i < data.size(); ++i) {
    	if (data[i] == to_remove) {
    		indexes.push_back(i);
    	}
    }
    for (int i = 0; i < indexes.size(); ++i) {
    	data.erase(data.begin() + i);
    }

    "Эффективное" удаление элементов из вектора. Об <algorithm> человек не слышал...

    Cpp, 25 Февраля 2013

    Комментарии (24)
  6. Pascal / Говнокод #12646

    +93

    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
    begin
    if n=15 then
    begin
    a:=7200*56*99*12*13*14*15;
    end
    else
    begin
    if n=16 then
    begin
    a:=7200*56*99*12*13*14*15*16;
    end
    else
    begin
    if n=17 then
    begin
    a:=7200*56*99*12*13*14*15*16*17;
    end
    else
    begin
    if n=18 then
    begin
    a:=7200*56*99*12*13*14*15*16*17*18;
    end
    else
    begin
    if n=19 then
    begin
    a:=7200*56*99*12*13*14*15*16*17*18*19;
    end
    else
    begin
    if n=20 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19;
    end
    else
    begin
    if n=21 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21;
    end
    else
    begin
    if n=22 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22;
    end
    else
    begin
    if n=23 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23;
    end
    else
    begin
    if n=24 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24;
    end
    else
    begin
    if n=25 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25;
    end
    else
    begin
    if n=26 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26;
    end
    else
    begin
    if n=27 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27;
    end
    else
    begin
    if n=28 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28;
    end
    else
    begin
    if n=29 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28*29;
    end
    else
    begin
    if n=30 then
    begin
    a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28*29*30;
    end
    else
    begin
    if n=31 then
    begin

    crazy_horse, 25 Февраля 2013

    Комментарии (24)
  7. Куча / Говнокод #12620

    +124

    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
    import Control.Monad
    import Control.Arrow
    import Data.List
    
    solve' :: [String] -> [[String]]
    solve' = nub . filter (
                and . uncurry (
                    zipWith (
                        (.head) . (==) . last
                    )
                ) . (id &&& tail)
             ) . uncurry ($) . (
                last . (((
                    map (
                        last . fst &&& uncurry (++) . (init . fst &&& snd)
                    ) . tail . uncurry (zipWith (,)) . (inits &&& tails)
                ) >=> (uncurry map) . 
                    ((:) *** solve')
                ):
                ) . (uncurry takeWhile) . (
                        const . null &&& const [const [[]]]
                    ) &&& id
             )
    
    main = print $ solve' ["123","321","123"]

    HaskellGovno, 20 Февраля 2013

    Комментарии (24)
  8. Pascal / Говнокод #12564

    +86

    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
    Function TMainForm.PrimGenerateMaze(Width, Height: Integer): Maze;
    
    Type Point = record
      x, y: Integer;
    end;
    
    Var
      TehMaze: Maze;
      Todo: array of Point;
      todonum: integer;
      x,y,n,d: integer;
    
    Const
      dx: array [0..3] of Integer = (0, 0, -1, 1);
      dy: array [0..3] of Integer = (-1, 1, 0, 0);
    
    BEGIN
      SetLength(TehMaze, Width, Height);
      SetLength(Todo, (Width * Height) - 1);
    
      For x:=0 to Width-1 do
        For y:=0 to Height-1 do
          If (x = 0) or (x = Width-1) or (y = 0) or (y = Height-1) then
            TehMaze[x][y]:=32
          Else TehMaze[x][y]:=63;
    
      Randomize;
      x := Random(Width-2)+1;
      y := Random(Height-2)+1;
      todonum := 0;
    
      TehMaze[x][y]:= TehMaze[x][y] and not 48; // Пометить клетку как принадлежащую лабиринту
    
       // Пока не обработаны все клетки
       Repeat
        Begin
           // Занести в список todo все ближайшие необработанные клетки
           For d:=0 to 3 do
               if (TehMaze[x + dx[d]][y + dy[d]] and 16) <> 0 then
               Begin
                 todo[todonum].x := x + dx[d];
                 todo[todonum].y := y + dy[d];
                 Inc(todonum);
                 TehMaze[x + dx[d]][y + dy[d]] := TehMaze[x + dx[d]][y + dy[d]] and not 16;
               End;
    
           // Выбрать из списка todo произвольную клетку
           n:= Random(todoNum);
           x:= ToDo[n].x;
           y:= ToDo[n].y;
    
           // Удалить из списка обработанную клетку
           Dec(todonum);
           ToDo[n]:= todo[todonum];
    
           // Выбрать направление, которое ведет к лабиринту
           Repeat
               d:=Random(4);
           Until ((TehMaze[x + dx[d]][y + dy[d]] and 32) = 0);
    
           // Присоединить выбранную клетку к лабиринту
           TehMaze[x][y] := TehMaze[x][y] and not ((1 shl d) or 32);
           TehMaze[x + dx[d]][y + dy[d]] := TehMaze[x + dx[d]][y + dy[d]] and not (1 shl (d xor 1));
        End;
       Until (todonum = 0);
    
       TehMaze[1][1] := TehMaze[1][1] and -2;                 // начало лабиринта - в левом верхнем углу
       TehMaze[Width-2][Height-2] := TehMaze[Width-2][Height-2] and not 2; // конец лабиринта - в правом нижнем углу
    
       Result := TehMaze;
    END;

    Генерация лабиринтов по алгоритму Прима.

    Govnocoder#0xFF, 10 Февраля 2013

    Комментарии (24)
  9. JavaScript / Говнокод #12550

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    <form action="..." ...>
    ...
      <input type="button" ... onclick="$('form').submit();" />
    </form>

    Живет на свете один c# девелопер, который всегда всем говорит: "я не верстальщик - я c# девелопер. я не js программист - я c# девелопер" ну и т.д. И вот однажды он решил самостоятельно сделать функционал поиска...
    (На самом деле на стороне сервера еще гуще развивались события...но это уже другая история...) с серверным c# кодом вы можете ознакомится тут http://govnokod.ru/user/5616/codes

    mangyst, 07 Февраля 2013

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

    +7

    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
    #include <iostream>
    namespace detail
    {
      class CRWO;
      class CRO;
      class CWO;
      class CO;
    }
    typedef detail::CRWO&  CRWO;
    typedef detail::CRO&  CRO;
    typedef detail::CWO&  CWO;
    typedef detail::CO&  CO;
    class C
    {
        friend class detail::CRWO; 
        friend class detail::CRO; 
        friend class detail::CWO; 
        friend class detail::CO; 
      public:
        C( int a ) : value(a) {}
        ~C() {};
        operator CRWO() { return *static_cast<detail::CRWO*>(static_cast<void*>(this)); }
        operator CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
        operator CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
        operator CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
      private:
        void set( int newValue ) { value = newValue; }
        int get() { return value; }
      private:
        int value;
    };
    class detail::CRWO
    {
      public:
        void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
        int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
        operator ::CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
        operator ::CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
        operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }    
      private:
        CRWO(); CRWO(const CRWO&);~CRWO();CRWO& operator=(const CRWO&);void operator&(); void operator*();
    };
    class detail::CWO
    {
      public:
        void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
         operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }    
      private:
        CWO(); CWO(const CWO&);~CWO();CWO& operator=(const CWO&);void operator&(); void operator*();
    };
    class detail::CRO
    {
      public:
        int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
        operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }    
      private:
        CRO(); CRO(const CRO&);~CRO();CRO& operator=(const CRO&);void operator&(); void operator*();
    };
    class detail::CO
    {
      public:
      private:
        CO(); CO(const CO&);~CO();CO& operator=(const CO&);void operator&(); void operator*();
    };int main(int argc, char *argv[])
    {
    C c(3);
    CRWO rwo = c;
    CRO ro = c;
    CWO wo = c;
    CO o = c;
      std::cout  << rwo.get() << std::endl;
      wo.set( 5);
      std::cout  << ro.get() << std::endl;
    return 0;
    }

    Оттуда.

    Автор требует указывать авторство при копировании.

    LispGovno, 02 Февраля 2013

    Комментарии (24)
  11. 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)