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

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

    +165

    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
    function findeFreePlace()
        {
            try
            {
                var x = random(gs.cells.x - 1),
                    y = random(gs.cells.y - 1);
                if (gs.balls[y][x] != null)
                {
                    return findeFreePlace();
                }
                else
                {
                    return [x, y];
                }
            }
            catch (e)
            {
                isEndGame = true;
                showfinish();
                return false;
            }
        }

    Игра "линии". Нужно случайно выбрать клеточку, в которую будет добавлен новый шарик. Ну, а чтобы узнать, что пустых клеточек нет, ловим ошибку переполнения стека.

    vovams, 24 Октября 2012

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

    +34

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int main()
    try
    {
    }
    catch (...)
    {
    }

    http://ideone.com/luh8p

    LispGovno, 24 Сентября 2012

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

    +131

    1. 1
    o?o.f():{};

    Мне было стыдно постить это в С++.

    http://www.gamedev.ru/flame/forum/?id=167142&page=2#m25

    LispGovno, 20 Сентября 2012

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

    +22

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    string toString( int i ) {
    	stringstream s;
    	s << i;
    	return s.str();
    }

    Наткнулся на эту функцию в одном из своих старых проектом.

    Fai, 11 Сентября 2012

    Комментарии (28)
  6. Python / Говнокод #11732

    −91

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if value == '' or value == None or value == False or value == 0:
        ...
    
    if count(data) <= 0:
        ...
    
    # так же он еще умеет рефакторить это
    if post_data is None:
        ...
    # вот в это
    if not post_data:
        ...

    Пара примеров, как у нас в проекте "кодит" товарищ из Индии

    larikov, 09 Сентября 2012

    Комментарии (28)
  7. Си / Говнокод #11374

    +121

    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
    #include "uni.h"
    
    int getopt_long(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
    int getopt__long_only(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
    int chown(const char *path, uid_t owner, gid_t group);
    uid_t getuid(void);
    int mkdir(const char *pathname, mode_t mode);
    gid_t getgid(void);
    
    char *dirname;
    mode_t perm;
    uid_t owner;
    gid_t group;
    
    int main(int argc,char **argv){
      owner=getuid();
      group=getgid();
      perm=0600;
    char *pEnd;
    char *dirname=(char*)malloc(16);
      if(dirname==NULL){fprintf(stderr, "out of memory!\n");return -1;}
       memset( dirname,'\0',16); 
       strcat(dirname,argv[argc-1]);
    struct option longopts[] = {
      { "mode", required_argument, NULL, 'm' },
      { "parents", NULL, NULL, 'p'},
      { "verbose", required_argument, NULL, 'v'},
      { "context", required_argument, NULL, 'c'},
      { "help", NULL, NULL, 'h'},
      { "version", NULL, NULL, 'r'},
    { 0, 0, 0, 0 } 
    };
    char c;
    while((c=getopt_long(argc,argv,"m:p:v:c:r:h",longopts,NULL)) != -1) {
      switch (c) {
        case 'm':
          perm=strtol(optarg,&pEnd,8);
          printf("%s\n",pEnd);
          break;
        case 'p':
          if(rmdir(dirname)<0){
            fprintf(stderr, "don't manage to delete folder!\n");return -1;
          }
          break;
        case 'v':
          if(mkdir(dirname,perm)<0){
            fprintf(stderr, "mkdir: cannot create directory `%s`: file exists\n",dirname);return -1;
          } else {
            printf("mkdir: created directory `%s`\n",dirname);
            return 0;
          }
          break;
        case 'c':
          break;
        case 'h':
          printf("Usage: mkdir [OPTION]... DIRECTORY...\n");
          printf("Create the DIRECTORY(ies), if they do not already exist.\n");
          printf("\n");
          printf("Mandatory arguments to long options are mandatory for short options too.\n");
          printf("  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask\n");
          printf("  -p, --parents     no error if existing, make parent directories as needed\n");
          printf("  -v, --verbose     print a message for each created directory\n");
          printf("  -Z, --context=CTX  set the SELinux security context of each created\n");
          printf("                      directory to CTX\n");
          printf("      --help     display this help and exit\n");
          printf("      --version  output version information and exit\n");
          printf("\tAuthor AliceGoth\n");
          return 0;
          break;
        case 'r':
          printf("\tMy own mkdir\n");
          printf("\tVersion 1.0\n");
          printf("\tAuthor AliceGoth\n");
          printf("\tEmail [email protected]\n");
          break;
        case 1:

    Мой mkdir

    AliceGoth, 07 Июля 2012

    Комментарии (28)
  8. Си / Говнокод #11321

    +137

    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
    void
    meta_window_constrain (MetaWindow          *window,
                           MetaFrameBorders    *orig_borders,
                           MetaMoveResizeFlags  flags,
                           int                  resize_gravity,
                           const MetaRectangle *orig,
                           MetaRectangle       *new)
    {
      ConstraintInfo info;
    
      /* ... */
    
      setup_constraint_info (&info, window,  orig_borders, flags, resize_gravity, orig, new);
    
      /* ... */
    
      /* Ew, what an ugly way to do things.  Destructors (in a real OOP language,
       * not gobject-style--gobject would be more pain than it's worth) or
       * smart pointers would be so much nicer here.  *shrug*
       */
      if (!orig_borders)
        g_free (info.borders);
    }
    
    static void
    setup_constraint_info (/* ... */)
    {
      /* ... */
    
      /* Create a fake frame geometry if none really exists */
      if (orig_borders && !window->fullscreen)
        info->borders = orig_borders;
      else
        info->borders = g_new0 (MetaFrameBorders, 1);
    
      /* ... */
    }

    http://git.gnome.org/browse/mutter/tree/src/core/constraints.c

    rat4, 29 Июня 2012

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

    −85

    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
    if ([stringMonth isEqualToString:NSLocalizedString(@"M1", nil)]) {
            stringMonth = @"01";}
        else if ([stringMonth isEqualToString:NSLocalizedString(@"M2", nil)]) {
                stringMonth = @"02";}
            else if ([stringMonth isEqualToString:NSLocalizedString(@"M3", nil)]) {
                    stringMonth = @"03";}
                else if ([stringMonth isEqualToString:NSLocalizedString(@"M4", nil)]) {
                        stringMonth = @"04";}
                    else if ([stringMonth isEqualToString:NSLocalizedString(@"M5", nil)]) {
                            stringMonth = @"05";}
                        else if ([stringMonth isEqualToString:NSLocalizedString(@"M6", nil)]) {
                                stringMonth = @"06";}
                            else if ([stringMonth isEqualToString:NSLocalizedString(@"M7", nil)]) {
                                    stringMonth = @"07";}
                                else if ([stringMonth isEqualToString:NSLocalizedString(@"M8", nil)]) {
                                        stringMonth = @"08";}
                                    else if ([stringMonth isEqualToString:NSLocalizedString(@"M9", nil)]) {
                                            stringMonth = @"09";}
                                        else if ([stringMonth isEqualToString:NSLocalizedString(@"M10", nil)]) {
                                                stringMonth = @"10";}
                                            else if ([stringMonth isEqualToString:NSLocalizedString(@"M11", nil)]) {
                                                    stringMonth = @"11";}
                                                else if ([stringMonth isEqualToString:NSLocalizedString(@"M12", nil)]) {
                                                        stringMonth = @"12";}

    Как-то так, че.

    1101_debian, 25 Июня 2012

    Комментарии (28)
  10. Куча / Говнокод #10973

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    >>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[
    ->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<
    ]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>
    +<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-
    [<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[
    >->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]

    Yo dawg I heard you like brainfuck so we put brainfuck in your brainfuck so you can brainfuck while you brainfuck

    rat4, 15 Июня 2012

    Комментарии (28)
  11. PHP / Говнокод #10533

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    foreach($succes_type as $value) {
    	if (strcasecmp($typefile, $value) == 0) $resultat = 1;
    }
    		
    # Проверка загружаемого
    if($resultat != 1 OR $resultat == null OR $resultat == 0) {
    	...
    }

    $resultat выше не определялась...

    nethak, 03 Июня 2012

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