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

    В номинации:
    За время:
  2. Си / Говнокод #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)
  3. Java / Говнокод #11333

    +121

    1. 1
    2. 2
    3. 3
    @SuppressWarnings("deprecation")
    // Stupid GWT doesn't have Calendar, so we have to use a deprecated method. :(
    final int year = new Date().getYear() + 1900;

    someone, 02 Июля 2012

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

    +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
    minChunksSize=1000.0 -- 100.0
     
    facbig :: Integer -> Integer
    facbig n = 
            let 
                    divisionProportion = 0.9 -- 2.0/3.0
                    amountOfChunk = truncate $ logBase divisionProportion $ minChunksSize/fromIntegral n
                    proportions = map (divisionProportion^) [amountOfChunk, amountOfChunk-1 .. 1]
                    centralChunkResults = map product [
                            let
                                    begin = proportionToItemNumber 1 beginRangeProportion
                                    end = proportionToItemNumber 0 endRangeProportion
                            in
                            [begin..end] | (endRangeProportion, beginRangeProportion) <- zip proportions $ tail proportions ]
                    beginChunkResult = product [1 .. proportionToItemNumber 0 $ last proportions]
                    endChunkResult = product [proportionToItemNumber 1 $ head proportions .. n]
            in product $ beginChunkResult:endChunkResult:centralChunkResults
            where
                    proportionToItemNumber shift proportion =
                            shift + truncate ((1.0-proportion)*fromIntegral n)
     
    fac n = if n <= (truncate $ 3.0*minChunksSize)
            then product [1..n]
            else facbig n
     
    main = print $ length $ show $ fac 100000

    Вот так вот школота считают число цифр в факториале числа.

    HaskellGovno, 10 Мая 2012

    Комментарии (7)
  5. Pascal / Говнокод #10030

    +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
    procedure TForm1.Timer2Timer(Sender: TObject);
    begin
    image75.Visible:=false;image76.Visible:=false;
    image1.Visible:=true;image2.Visible:=true;image3.Visible:=true;
    image4.Visible:=true;image5.Visible:=true;image6.Visible:=true;
    image7.Visible:=true;image8.Visible:=true;image9.Visible:=true;
    image10.Visible:=true;image11.Visible:=true;image12.Visible:=true;
    image13.Visible:=true;image14.Visible:=true;image15.Visible:=true;
    image16.Visible:=true;image17.Visible:=true;image18.Visible:=true;
    image19.Visible:=true;image20.Visible:=true;image21.Visible:=true;
    image22.Visible:=true;image23.Visible:=true;image24.Visible:=true;
    image25.Visible:=true;image26.Visible:=true;image27.Visible:=true;
    image28.Visible:=true;image29.Visible:=true;image30.Visible:=true;
    image31.Visible:=true;image32.Visible:=true;image33.Visible:=true;
    image34.Visible:=true;image35.Visible:=true;image36.Visible:=true;
    image37.Visible:=true;image38.Visible:=true;image39.Visible:=true;
    image40.Visible:=true;image41.Visible:=true;image42.Visible:=true;
    image43.Visible:=true;image44.Visible:=true;image45.Visible:=true;
    image46.Visible:=true;image47.Visible:=true;image48.Visible:=true;
    image49.Visible:=true;image50.Visible:=true;image51.Visible:=true;
    image52.Visible:=true;image53.Visible:=true;image54.Visible:=true;
    image55.Visible:=true;image56.Visible:=true;image57.Visible:=true;
    image58.Visible:=true;image59.Visible:=true;image60.Visible:=true;
    image61.Visible:=true;image62.Visible:=true;image63.Visible:=true;
    image64.Visible:=true;image65.Visible:=true;image66.Visible:=true;
    image67.Visible:=true;image68.Visible:=true;image69.Visible:=true;
    image70.Visible:=true;image71.Visible:=true;image72.Visible:=true;
    image73.Visible:=true;
    if image1.left<360 then begin timer2.Enabled:=false;button2.Visible:=true;
    image1.Visible:=false;image2.Visible:=false;image3.Visible:=false;
    image4.Visible:=false;image5.Visible:=false;image6.Visible:=false;
    image7.Visible:=false;image8.Visible:=false;image9.Visible:=false;
    image10.Visible:=false;image11.Visible:=false;image12.Visible:=false;
    image13.Visible:=false;image14.Visible:=false;image15.Visible:=false;
    image16.Visible:=false;image17.Visible:=false;image18.Visible:=false;
    image19.Visible:=false;image20.Visible:=false;image21.Visible:=false;
    image22.Visible:=false;image23.Visible:=false;image24.Visible:=false;
    image25.Visible:=false;image26.Visible:=false;image27.Visible:=false;
    image28.Visible:=false;image29.Visible:=false;image30.Visible:=false;
    image31.Visible:=false;image32.Visible:=false;image33.Visible:=false;
    image34.Visible:=false;image35.Visible:=false;image36.Visible:=false;
    image37.Visible:=false;image38.Visible:=false;image39.Visible:=false;
    image40.Visible:=false;image41.Visible:=false;image42.Visible:=false;
    image43.Visible:=false;image44.Visible:=false;image45.Visible:=false;
    image46.Visible:=false;image47.Visible:=false;image48.Visible:=false;
    image49.Visible:=false;image50.Visible:=false;image51.Visible:=false;
    image52.Visible:=false;image53.Visible:=false;image54.Visible:=false;
    image55.Visible:=false;image56.Visible:=false;image57.Visible:=false;
    image58.Visible:=false;image59.Visible:=false;image60.Visible:=false;
    image61.Visible:=false;image62.Visible:=false;image63.Visible:=false;
    image64.Visible:=false;image65.Visible:=false;image66.Visible:=false;
    image67.Visible:=false;image68.Visible:=false;image69.Visible:=false;
    image70.Visible:=false;image71.Visible:=false;image72.Visible:=false;
    image73.Visible:=false;end
    else begin image1.left:=image1.Left-3;image1.top:=image1.top-1;
    image2.left:=image2.Left+2;image2.top:=image2.top+2;
    image3.left:=image3.Left-1;image3.top:=image3.top-3;
    image4.left:=image4.Left-2;image4.top:=image4.top+4;
    ...

    Ещё 65 строк кода!
    Анимация взрыва на Delphi 7.

    artar94, 24 Апреля 2012

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private static string GetShortDisciplineName(string longDsciplineName){
                string[] words = longDsciplineName.Split(' ');
                switch (words.Count()){
                    case 1:{
                        return longDsciplineName;
                        break;
                        }

    pm2t29jf47, 13 Апреля 2012

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

    +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
    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
    case 64:
    						{
    							this.RA.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_555 = this.CCR;
    							expr_555.Value += 1;
    							break;
    						}
    					case 65:
    						{
    							this.RB.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_58F = this.CCR;
    							expr_58F.Value += 1;
    							break;
    						}
    					case 66:
    						{
    							this.RC.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_5C9 = this.CCR;
    							expr_5C9.Value += 1;
    							break;
    						}
    					case 67:
    						{
    							this.RD.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_603 = this.CCR;
    							expr_603.Value += 1;
    							break;
    						}
    					default:
    						if (command != 129)
    						{
    							switch (command)
    							{
    							case 192:
    								if (this.getBit(this.FR.Value, 0))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_67C = this.CCR;
    									expr_67C.Value += 1;
    								}
    								break;
    							case 193:
    								if (!this.getBit(this.FR.Value, 0))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_6CF = this.CCR;
    									expr_6CF.Value += 1;
    								}
    								break;
    							case 194:
    								if (this.getBit(this.FR.Value, 1))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_71F = this.CCR;
    									expr_71F.Value += 1;
    								}
    								break;
    							case 195:
    								if (!this.getBit(this.FR.Value, 1))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_76C = this.CCR;
    									expr_76C.Value += 1;
    								}
    								break;
    							}
    						}
    						else
    						{
    							this.CCR.Value = this.memory.getValue(this.CCR.Value);
    						}
    						break;
    					}
    				}
    			}
    			this.FR.Value = value;
    		}

    Элсы,свечи,ифы и просто хороший код №3
    (продолжение следует)
    годная реализация того что можно было написать в 10 строчек

    budlokoder_steb_dm, 03 Марта 2012

    Комментарии (11)
  8. Java / Говнокод #9580

    +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
    public static boolean isAssignable(Class cls, Class toClass, boolean autoboxing) {
        if (toClass == null) {
            return false;
        }
        // have to check for null, as isAssignableFrom doesn't
        if (cls == null) {
            return !(toClass.isPrimitive());
        }
        //autoboxing:
        if (autoboxing) {
            if (cls.isPrimitive() && !toClass.isPrimitive()) {
                cls = primitiveToWrapper(cls);
                if (cls == null) {
                    return false;
                }
            }
            if (toClass.isPrimitive() && !cls.isPrimitive()) {
                cls = wrapperToPrimitive(cls);
                if (cls == null) {
                    return false;
                }
            }
        }
        if (cls.equals(toClass)) {
            return true;
        }
        if (cls.isPrimitive()) {
            if (toClass.isPrimitive() == false) {
                return false;
            }
            if (Integer.TYPE.equals(cls)) {
                return Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
            }
            if (Long.TYPE.equals(cls)) {
                return Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
            }
            if (Boolean.TYPE.equals(cls)) {
                return false;
            }
            if (Double.TYPE.equals(cls)) {
                return false;
            }
            if (Float.TYPE.equals(cls)) {
                return Double.TYPE.equals(toClass);
            }
            if (Character.TYPE.equals(cls)) {
                return Integer.TYPE.equals(toClass)
                    || Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
            }
            if (Short.TYPE.equals(cls)) {
                return Integer.TYPE.equals(toClass)
                    || Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
            }
            if (Byte.TYPE.equals(cls)) {
                return Short.TYPE.equals(toClass)
                    || Integer.TYPE.equals(toClass)
                    || Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
            }
            // should never get here
            return false;
        }
        return toClass.isAssignableFrom(cls);
    }

    org.apache.commons.lang.ClassUtils

    3.14159265, 01 Марта 2012

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

    +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
    package simplecms
    import auth.*
    
    class AuthFilters {
    
    	private checkPermission(def controller, def p, def session, def params) {
    		if (p) {
    			boolean result = session.user?.profile?.permissions?.contains(p)
    			if (p.delegate) {
    				result |=  controller.checkDelegation[p.name](session, params)
    			} else if (p.controllerChecked) {
    				result &= controller.checkPermission[p.name](session, params)
    			}
    			if (!result && p.parent) {
    				result = checkPermission(controller, p.parent, session, params)
    			}
    			return result
    		}
    		return true
    	}
    
    	def filters = {
    		main(controller:'*', action:'*') {
    			before = {
    				def mappings = PermissionMapping.findAllByControllerAndMethodInList(controllerName, [actionName, '*'])
    				boolean denied = mappings?.size() > 0
    				if (denied) {
    					def permissions = []
    					session.user?.attach()
    					mappings.each { mapping ->
    						if (mapping.permission?.guest) {
    							denied = false
    						} else if (permission.parent == null){
    							permissions << mapping.permission
    						}
    					}
    					if (denied) {
    						denied = !permissions.any { checkPermission(grailsApplication.mainContext.getBean(controllerName), it, session, params) }
    					}
    				}
    				return !denied
    			}
    		}
    	}
    }

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

    0rt, 29 Февраля 2012

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

    +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
    class Program
    {
        static bool v1;
        static bool v2;
        static bool v3;
        static bool v4;
        //...
    
        static void Main()
        {
            getValues();
    
            if (v1)
            { }
            else
            {
                //Делаем раз
            }
            if (v2)
            { }
            else
            {
                //Делаем два
            }
            if (v3)
            { }
            else
            {
                //Делаем три
            }
            if (v4)
            { }
            else
            {
                //Делаем три с половиной
            }
        }
    
        static void getValues()
        {
            //Булевым переменным присваиваются значения из БД
        }
    }

    Один из студентов усердно выдавал такие конструкции. Логическое отрицание? Не, не слышал...

    vistefan, 31 Января 2012

    Комментарии (16)
  11. C# / Говнокод #9201

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private List<string> _items
    
    ...				
    
    if (_items.Count <= 0)
        return;

    Alx, 23 Января 2012

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