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

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

    +98

    1. 1
    2. 2
    3. 3
    public String toString() {
            return new String(body.toString());
        }

    Но зачем?

    3.14159265, 14 Ноября 2012

    Комментарии (23)
  3. Куча / Говнокод #12105

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if(Normal(Pawn.Acceleration) Dot Vect(1,0,0) > 0)
          {
             tempRot.Yaw = 0;
             Pawn.SetRotation(tempRot);
          }

    Из туториала по UDK. Почему просто не написать Pawn.Acceleration > 0 ?

    tirinox, 12 Ноября 2012

    Комментарии (23)
  4. Куча / Говнокод #12074

    +126

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    infixr 6 `then'`
    then' True = fst
    then' False = snd
    if' = id
    else' suc fail = (suc, fail)
    main = do
        print $ if' (1<5) `then'` "true" `else'` "false"
        print $ if' False `then'` "true" `else'` "false"

    bormand
    У ифа особый синтаксис. Как ты его реализуешь?
    Challenge accepted:
    Сначала был тред
    http://govnokod.ru/12068#comment159236
    а потом родилось говно:
    http://ideone.com/rOKDPP
    Реализовал if. За правильными приоритетами операций и ассоциативностью не следил.

    HaskellGovno, 07 Ноября 2012

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

    +122

    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
    data IdPState a r = IdPEnd r | IdPNeedInput | IdPHaveInput a
    {-# INLINE_STREAM idP #-}
    idP :: (Monad m) => Stream l a a r m r
    idP = Stream next IdPNeedInput where
    	{-# INLINE_INNER next #-}
    	next (IdPEnd r) = Done r
    	next IdPNeedInput = NeedInput IdPHaveInput IdPEnd
    	next (IdPHaveInput a) = HaveOutput IdPNeedInput (return ()) a
    
    {-# INLINE_STREAM pipe #-}
    pipe :: Monad m => Stream l a b r0 m r1 -> Stream Void b c r1 m r2 -> Stream l a c r0 m r2
    pipe (Stream nextL sL) (Stream nextR sR) = Stream next (Right (return (), sL, Right sR)) where
    	{-# INLINE_INNER next #-}
    	next (Left r) = Done r
    	next (Right (final, sL, Right sR)) = case nextR sR of
    		Skip sR' -> Skip (Right (final, sL, Right sR'))
    		HaveOutput sR' c o -> HaveOutput (Right (final, sL, Right sR')) (c >> final) o
    		NeedInput p c -> Skip (Right (final, sL, Left (p, c)))
    		Done r -> PipeM (final >> return (Left r))
    		PipeM ms -> PipeM (liftM (Right . (final, sL,) . Right) ms)
    		Leftover _ i -> absurd i
    	next (Right (final, sL, Left (p, c))) = case nextL sL of
    		Skip sL' -> Skip (Right (final, sL', Left (p, c)))
    		HaveOutput sL' final' o -> Skip (Right (final', sL', Right (p o)))
    		NeedInput pL cL -> NeedInput (Right . (final,, Left (p, c)) . pL) (Right . (final,, Left (p, c)) . cL)
    		Done r -> Skip (Right (return (), sL, Right (c r)))
    		PipeM ms -> PipeM (liftM (Right . (final,, Left (p, c))) ms)
    		Leftover sL' i -> Leftover (Right (final, sL', Left (p, c))) i
    
    {-# INLINE_STREAM purePipe #-}
    purePipe :: (forall m . Monad m => Stream l a b r0 m r1) -> (forall m . Monad m => Stream Void b c r1 m r2) -> (forall m . Monad m => Stream l a c r0 m r2)
    purePipe (Stream nextL sL) (Stream nextR sR) = Stream next (sL, Right sR) where
    	{-# INLINE_INNER next #-}
    	next (sL, Right sR) = case nextR sR of
    		Skip sR' -> Skip (sL, Right sR')
    		HaveOutput sR' _ o -> HaveOutput (sL, Right sR') (return ()) o
    		NeedInput p c -> Skip (sL, Left (p, c))
    		Done r -> Done r
    		PipeM ms -> Skip (sL, Right (runIdentity ms))
    		Leftover _ i -> absurd i
    	next (sL, Left (p, c)) = case nextL sL of
    		Skip sL' -> Skip (sL', Left (p, c))
    		HaveOutput sL' _ o -> Skip (sL', Right (p o))
    		NeedInput pL cL -> NeedInput ((, Left (p, c)) . pL) ((, Left (p, c)) . cL)
    		Done r -> Skip (sL, Right (c r))
    		PipeM ms -> Skip (runIdentity ms, Left (p, c))
    		Leftover sL' i -> Leftover (sL', Left (p, c)) i

    qbasic, 03 Ноября 2012

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

    +42

    1. 1
    2. 2
    3. 3
    4. 4
    objbase.h:
    
    #define __STRUCT__ struct
    #define interface __STRUCT__

    спасибо Микрософт за счастливое детство соответствие стандарту при засирании глобального неймспейса своими больными фантазиями

    defecate-plusplus, 03 Октября 2012

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

    +141

    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
    public string Search(string title)
     {
     List<string> str1 = new List<string>();
     string count = cmainlibrary.Count.ToString();
     int counter = Convert.ToInt32(count);
     int i = 0;
    
     for ( i = 0; i < counter; i++)
     {
     string title_library = cmainlibrary[i].Title.ToString();
     if (title.ToUpper().Contains(title_library. ToUpper()))
     {
     str1.Add(cmainlibrary[i].Title);
    
     }
     }
     return str1[i];
     }

    Хотя я это выкладывал в коментариях к говнокоду #11830, решил повеселить народ отдельным постом.
    Это реализация библиотеки книг. Метод должен искать список книг которые соответствуют title.

    sater, 25 Сентября 2012

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

    +42

    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
    std::string loc =
    	( {
    		const char *str = "";
    
    		switch (location) {
    		case Net::HANDSHAKE_TIMEOUT:
    			str = _(" due to handshake timeout");
    			break;
    		case Net::RECV_HANDSHAKE:
    			str = _(" while waiting for handshake");
    			break;
    		case Net::HANDSHAKE_DATA:
    			str = _(" due to unsupported handshake data");
    			break;
    		case Net::HANDSHAKE_AUTH:
    			str = _(" while parsing handshake data");
    			break;
    		case Net::WAIT_DEVICE:
    			str = _(" while waiting for device");
    			break;
    		case Net::TRANSFER_DATA:
    			str = _(" while transferring data");
    			break;
    		}
    		str;
    	});

    Я хуею с юных оптимизаторов.

    gvy, 28 Августа 2012

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

    +133

    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
    if ((textBox1.Text == textBox2.Text) | (textBox1.Text == textBox3.Text) | (textBox1.Text == textBox4.Text) | (textBox1.Text == textBox7.Text) |
        (textBox2.Text == textBox1.Text) | (textBox2.Text == textBox3.Text) | (textBox2.Text == textBox5.Text) | (textBox2.Text == textBox8.Text) |
        (textBox3.Text == textBox1.Text) | (textBox3.Text == textBox2.Text) | (textBox3.Text == textBox6.Text) | (textBox3.Text == textBox9.Text) |
        (textBox4.Text == textBox5.Text) | (textBox4.Text == textBox6.Text) | (textBox4.Text == textBox1.Text) | (textBox4.Text == textBox7.Text) |
        (textBox5.Text == textBox4.Text) | (textBox5.Text == textBox6.Text) | (textBox5.Text == textBox2.Text) | (textBox5.Text == textBox8.Text) |
        (textBox6.Text == textBox4.Text) | (textBox6.Text == textBox5.Text) | (textBox6.Text == textBox3.Text) | (textBox6.Text == textBox9.Text) |
        (textBox7.Text == textBox8.Text) | (textBox7.Text == textBox9.Text) | (textBox7.Text == textBox1.Text) | (textBox7.Text == textBox4.Text) |
        (textBox8.Text == textBox7.Text) | (textBox8.Text == textBox9.Text) | (textBox8.Text == textBox2.Text) | (textBox8.Text == textBox5.Text) |
        (textBox9.Text == textBox7.Text) | (textBox9.Text == textBox8.Text) | (textBox9.Text == textBox3.Text) | (textBox9.Text == textBox6.Text)) ;
    else
    }
       label1.Visible = true;
       label2.Visible = true;
    }

    Это эпик.

    Fai, 07 Июля 2012

    Комментарии (23)
  10. PHP / Говнокод #11312

    +65

    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
    $quGroup = mysql_query($x = "
            SELECT
                a.latitude, a.longitude, a.catid, a.id, a.title, a.arttype, a.userid, b.firstname, b.lastname, b.usertype,
                a.latitude2, a.longitude2, a.latitude3, a.longitude3, a.latitude4, a.longitude4, a.latitude5, a.longitude5,
                a.latitude6, a.longitude6, a.latitude7, a.longitude7, a.latitude8, a.longitude8, a.latitude9, a.longitude9,
                a.latitude10, a.longitude10, a.latitude11, a.longitude11
            from materials a, users b
            where a.status='1' and a.userid=b.id and add_date > $day)
            $sql_cond");
        while ($flGroup = mysql_fetch_row($quGroup)) {
            $j++;
            $a1 = $a2 = array ();
            $l1 = $flGroup[0];
            $l2 = $flGroup[1];
            if ($l1 && $l2) {
                $a1[] = $l1;
                $a2[] = $l2;
            }
    
            $latitude2 = $flGroup[10];
            $longitude2 = $flGroup[11];
            if ($latitude2 && $longitude2) {
                $a1[] = $latitude2;
                $a2[] = $longitude2;
            }
    
            $latitude3 = $flGroup[12];
            $longitude3 = $flGroup[13];
            if ($latitude3 && $longitude3) {
                $a1[] = $latitude3;
                $a2[] = $longitude3;
            }
    
            $latitude4 = $flGroup[14];
            $longitude4 = $flGroup[15];
            if ($latitude4 && $longitude4) {
                $a1[] = $latitude4;
                $a2[] = $longitude4;
            }
    
            $latitude5 = $flGroup[16];
            $longitude5 = $flGroup[17];
            if ($latitude5 && $longitude5) {
                $a1[] = $latitude5;
                $a2[] = $longitude5;
            }
    
            $latitude6 = $flGroup[18];
            $longitude6 = $flGroup[19];
            if ($latitude6 && $longitude6) {
                $a1[] = $latitude6;
                $a2[] = $longitude6;
            }
    
            $latitude7 = $flGroup[20];
            $longitude7 = $flGroup[21];
            if ($latitude7 && $longitude7) {
                $a1[] = $latitude7;
                $a2[] = $longitude7;
            }
    
            $latitude8 = $flGroup[22];
            $longitude8 = $flGroup[23];
            if ($latitude8 && $longitude8) {
                $a1[] = $latitude8;
                $a2[] = $longitude8;
            }
    
            $latitude9 = $flGroup[24];
            $longitude9 = $flGroup[25];
            if ($latitude9 && $longitude9) {
                $a1[] = $latitude9;
                $a2[] = $longitude9;
            }
    
            $latitude10 = $flGroup[26];
            $longitude10 = $flGroup[27];
            if ($latitude10 && $longitude10) {
                $a1[] = $latitude10;
                $a2[] = $longitude10;
            }
    
            $latitude11 = $flGroup[28];
            $longitude11 = $flGroup[29];
            if ($latitude11 && $longitude11) {
                $a1[] = $latitude11;
                $a2[] = $longitude11;
            }
    
            if (!$l1 && !$l2 && !$latitude2 && !$longitude2 && !$latitude3 && !$longitude3 && !$latitude4 && !$longitude4 && !$latitude5 && !$longitude5 && !$latitude6 && !$longitude6 && !$latitude7 && !$longitude7 && !$latitude8 && !$longitude8 && !$latitude9 && !$longitude9 && !$latitude10 && !$longitude10 && !$latitude11 && !$longitude11)
                continue;
    
    ...
    }

    как изящно

    shmaltorhbooks, 28 Июня 2012

    Комментарии (23)
  11. Си / Говнокод #11280

    +130

    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
    int print_entry(const char* name, const char* dir,const struct stat* st)
    {
      if(!S_ISDIR(st->st_mode)){
          if(S_ISREG(st->st_mode)){
            printf("<file type=\"regular file\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          };
          if(S_ISCHR(st->st_mode)){
            printf("<file type=\"charcter device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISBLK(st->st_mode)){
            printf("<file type=\"block device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISFIFO(st->st_mode)){
            printf("<file type=\"FIFO(named pipe)\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISLNK(st->st_mode)){
             char *linkname;
             ssize_t r;
             char *lname=strcat(dir,"");
             linkname =  new char[st->st_size + 1];
             if (linkname == NULL) {
                fprintf(stderr, "insufficient memory\n");
                exit(EXIT_FAILURE);
             }
            r=readlink(lname, linkname, st->st_size + 1);
            if (r < 0) {
              return 0;
            }
               if (r > st->st_size) {
            fprintf(stderr, "symlink increased in size "
                            "between lstat() and readlink()\n");
            exit(EXIT_FAILURE);
        }
    
            linkname[st->st_size] = '\0';
            printf("<file type=\"symbolic link\" owner=\"%d\" group=\"%d\" linkname=\"%s\">%s/%s</file>\n",st->st_uid,st->st_gid,linkname,dir,name);
          }
          if(S_ISSOCK(st->st_mode)){
            printf("<file type=\"socket\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
        }
        return 0;
    }
     
    int main(int argc, char* argv[])
    {
    if(argc != 2)
        {
        fprintf(stderr, "Usage: %s DIR\n", argv[0]);
        exit(1);
        }
        printf("<dir name=\"%s\">\n",argv[1]);
        walk(argv[1], print_entry, 1,0);
        printf("</dir>",argv[1]);
    }

    Создание xml файла всех директорий, поддиректорий и их файлов

    AliceGoth, 22 Июня 2012

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