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

    В номинации:
    За время:
  2. 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)
  3. Си / Говнокод #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)
  4. Си / Говнокод #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)
  5. 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)
  6. Куча / Говнокод #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)
  7. 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)
  8. C++ / Говнокод #10387

    +25

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #ncld<strm.h>
    vd mn()
    {
    ct<<"Hll, wrld!";
    cn.gt();
    }

    Нхй пргрммрвн.

    dos_, 29 Мая 2012

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

    +116

    1. 1
    append x = foldr (map (:) x) id

    HaskellGovno, 20 Мая 2012

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

    +1007

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #if defined( HPUX_11_31 )
    #define BDYNAMIC_CAST( CLASS, OBJECT )  (( CLASS ) ( OBJECT ))
    #else
    #define BDYNAMIC_CAST( CLASS, OBJECT )  (dynamic_cast< CLASS >(( OBJECT )))
    #endif

    чуть кофе не похлебнулся.

    при более детальном рассмотрении кода из-за которого это сделали, выяснилось что: (А) в проекте нет ни одного места где нужен динамик каст и (Б) половина наших С++ профисианалов не умеют пользоватся конст кастом (который по коду там и был им нужен, вместе со статик кастом).

    Dummy00001, 08 Февраля 2012

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

    +174

    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
    //присваиваем массиву значения
    	for ($i=0; $i<7; $i++) 
    		{
    		$rand[$i]=rand(1,52);
    		}
    
    //проверяем 50 раз что бы исключить повторы
    for ($i=0; $i<50; $i++) 
    	{
    //проверяем $rand[0] на совпадения
    	if ($rand[0]==$rand[1])
    		{
    		$rand[0]=rand(1,52);
    		}
    	else
    		{
    		if ($rand[0]==$rand[2])
    			{
    			$rand[0]=rand(1,52);
    			}
    		else
    			{
    			if ($rand[0]==$rand[3])
    				{
    				$rand[0]=rand(1,52);
    				}
    			else
    				{
    				if ($rand[0]==$rand[4])
    					{
    					$rand[0]=rand(1,52);
    					}
    				else
    					{
    					if ($rand[0]==$rand[5])
    						{
    						$rand[0]=rand(1,52);
    						}
    					else
    						{
    						if ($rand[0]==$rand[6])
    							{
    							$rand[0]=rand(1,52);
    							}
    						}
    					}
    				}
    			}
    		}
    
    //проверяем $rand[1] на совпадения
    	if ($rand[1]==$rand[0])
    		{
    		$rand[1]=rand(1,52);
    		}
    	else
    		{
    		if ($rand[1]==$rand[2])
    			{
    			$rand[1]=rand(1,52);
    			}
    		else
    			{
    			if ($rand[1]==$rand[3])
    				{
    				$rand[1]=rand(1,52);
    				}
    			else
    				{
    				if ($rand[1]==$rand[4])
    					{
    					$rand[1]=rand(1,52);
    					}
    				else
    					{
    					if ($rand[1]==$rand[5])
    						{
    						$rand[1]=rand(1,52);
    						}
    					else
    						{
    						if ($rand[1]==$rand[6])
    							{
    							$rand[1]=rand(1,52);
    							}
    						}
    					}
    				}
    			}
    		}

    Генератор "не повторяющихся цифр от 1 до 52"
    Влезло 2 if-блока из семи в оригинале :)

    govnokod-observer, 07 Февраля 2012

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