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

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

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private static class Errors extends ArrayList<String> {
    	private static final long serialVersionUID = 1L;
    }
    
    private static class Notices extends ArrayList<String> {
    	private static final long serialVersionUID = 1L;
    }

    две большие разницы

    Lure Of Chaos, 11 Апреля 2014

    Комментарии (9)
  3. Java / Говнокод #15657

    +73

    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
    private void CopyFiles(String dirName) {
    	InputStream is = this.getClass().getResourceAsStream(
    			"/18.xslt");
    	OutputStream os;
    	try {
    		os = new FileOutputStream(dirName + "/18.xslt");
    		byte[] buffer = new byte[4096];
    		int length;
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02.tif");
    		os = new FileOutputStream(dirName + "/13_02.tif");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream("/13_02.xslt");
    		os = new FileOutputStream(dirName + "/13_02.xslt");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02_t.tif");
    		os = new FileOutputStream(dirName + "/13_02_t.tif");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    		is = this.getClass().getResourceAsStream(
    				"/13_02_t.xslt");
    		os = new FileOutputStream(dirName + "/13_02_t.xslt");
    		while ((length = is.read(buffer)) > 0) {
    			os.write(buffer, 0, length);
    		}
    		os.close();
    		is.close();
    	} catch (FileNotFoundException e1) {
    		e1.printStackTrace();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    }

    evg_ever, 03 Апреля 2014

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

    +73

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    private boolean isAuthorized( ExecutionResult result )
    {
        Iterator<Long> accessCountIterator = result.columnAs( "accessCount" );
        while ( accessCountIterator.hasNext() )
        {
            if (accessCountIterator.next() > 0L)
            {
                return true;
            }
        }
        return false;
    }

    Человек написал книжку по програмированию :(
    isbn:1449356265/9781449356262

    wvxvw, 24 Марта 2014

    Комментарии (145)
  5. Java / Говнокод #14583

    +73

    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
    final double[][] matrix = new double[companies.size() + 1][(sampleSizeTo - sampleSizeFrom) / sampleSizeStep + 2];
    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[0].length; j++) {
            if (i == 0 && j == 0) {
                continue;
            }
            if (i == 0) {
                matrix[i][j] = sampleSizeFrom + (j - 1) * sampleSizeStep;
                continue;
            }
            if (j == 0) {
                matrix[i][j] = companies.get(i-1);
                continue;
            }
        }
    }

    Название функции getSmartDistibution (именно так) какбэ намекает, что дальше будет весело

    roman-kashitsyn, 14 Февраля 2014

    Комментарии (5)
  6. Java / Говнокод #14514

    +73

    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
    class MyException extends Exception {
    	/* конструкторы, геттеры-сеттеры и прочее-прочее */
    	
    	public void handle() { /* over 9000 строк */ }
    }
    
    class MyClass {
    	public void myMethod() {
    		try { /* ... */ }
    		catch (MyException e) {
    			e.handle();
    		}
    	}
    }

    исключение, которое обрабатывает, можно сказать, само себя, бред?

    evg_ever, 06 Февраля 2014

    Комментарии (19)
  7. Java / Говнокод #14337

    +73

    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
    public enum Action {
    
        ADD, DELETE, UPDATE, REFRESH;
    
        public static Action getEnum(String value) {
            for (Action current : values()) {
                if (current.name().equalsIgnoreCase(value)) {
                    return current;
                }
            }
            throw new IllegalArgumentException("Unknown input value. Input value is '" + value + "'");
        }
    
        @Override
        public String toString() {
            return this.name().toLowerCase();
        }
    }
    
    public enum Manager {
    
        USER, ROLE, SERVICE;
    
        public static Manager getEnum(String value) {
            for (Manager current : values()) {
                if (current.name().equalsIgnoreCase(value)) {
                    return current;
                }
            }
            throw new IllegalArgumentException("Unknown input value. Input value is '" + value + "'");
        }
    
        @Override
        public String toString() {
            return this.name().toLowerCase();
        }
    
        public boolean isUser() {
            return this == USER;
        }
    
        public boolean isRole() {
            return this == ROLE;
        }
    
        public boolean isService() {
            return this == SERVICE ;
        }
    }
    
    public class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
        @Override
        public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
            return new StringToEnumConverter<T>(targetType);
        }
    
        private final class StringToEnumConverter<T extends Enum> implements Converter<String, T> {
    
            private Class<T> enumType;
    
            private StringToEnumConverter(Class<T> enumType) {
                this.enumType = enumType;
            }
    
            @Override
            public T convert(String source) {
                if (enumType.getName().equalsIgnoreCase("com.finder.enumerator.manager")) {
                    return (T) Manager.getEnum(source);
                }
                if (enumType.getName().equalsIgnoreCase("com.finder.enumerator.action")) {
                    return (T) Action.getEnum(source);
                }
                return (T) Enum.valueOf(this.enumType, source);
            }
        }
    }
    
    /* -- Mapping -- */
    @RequestMapping(value = "manage/index/{manager}/{action}", method = RequestMethod.GET)
    public String addValueToEntity(@PathVariable("manager") Manager manager, @PathVariable("action") Action action) {
    ...
    
    @RequestMapping(value = "/manage/index", method = RequestMethod.GET)
    public String indexPage(ModelMap model, @RequestParam(value = "manager", required = true) Manager manager) {
    ...

    Spring MVC. Проблема в том что строка lovercase а значения Enum-ов uppercase

    govnoacc, 10 Января 2014

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

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    GZIPOutputStream out = new GZIPOutputStream(out) {
        {
            def.setLevel(Deflater.BEST_COMPRESSION);
        }
    };

    Вот так можно выставить максимальную степень сжатия GZIP-потока в жабе.

    roman-kashitsyn, 13 Декабря 2013

    Комментарии (73)
  9. Java / Говнокод #14188

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int k = 0;
    for (int i = 1; i<=str.length(); i++){
      k = i;
    }
    System.out.println("dlina: "+k);

    Счётчик длины строки....

    fedes, 06 Декабря 2013

    Комментарии (58)
  10. Java / Говнокод #13744

    +73

    1. 1
    2. 2
    String format = String.format("%%0%dd", 2); // format = "%02d";
    String seconds = String.format(format, milTime % 60);

    nikanmf, 06 Сентября 2013

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

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Дорогой участник! Не спеши покидать страницу. Я прошу тебя помочь:
    не поленись, пройдись по всем постам, и поставь каждому участнику по минусу;
    минусуя других участников ты воспитываешь в себе чувство меры и помогаешь обществу снижать ЧСВ. 
    Заранее спасибо, друг мой. Ты будешь вознагражден за это деяние!
    
    Тот, кто покинул страницу, но не выполнил моей просьбы, умрет через 9 дней.

    Дорогой участник! Не спеши покидать страницу. Я прошу тебя помочь:
    не поленись, пройдись по всем постам, и поставь каждому участнику по минусу;
    минусуя других участников ты воспитываешь в себе чувство меры и помогаешь обществу снижать ЧСВ.
    Заранее спасибо, друг мой. Ты будешь вознагражден за это деяние!


    Тот, кто покинул страницу, но не выполнил моей просьбы, умрет через 9 дней.

    Stertor, 11 Июля 2013

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