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

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

    +81

    1. 1
    item.getName().equals("")==false

    Art, 23 Сентября 2011

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    THIS:while(true){
                if(true)break;
                ...
    }

    fcuk ну как так можно кодить?

    Mooncrafter, 01 Сентября 2011

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    while( !par1.end_flag ) 
       {
        if( !par1.end_flag)
          System.out.println("Now waiting par1.end_flag");
       }

    кусок из методички по Java

    ramzes_2, 06 Апреля 2011

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

    +81

    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
    public void actionPerformed(java.awt.event.ActionEvent e)
    {
    	/* code	here */					
    	thr = new Potok(Spisok,f,papk);
    	thr.setWork(true);
    	try { thr.join(); } 
    	catch (InterruptedException e1) 
    	{
    		// TODO Auto-generated catch block
    		e1.printStackTrace();
    	}
    	/* another code here */
    }
    
    /* in the galaxy far-far away */
    class Potok extends Thread
    {
    	private boolean isWork = true;
    
    	public Potok() {}
    
    	public void run()
    	{
    		while ( isWork )
    		{
    			/* code here */
    		}
    	}
    	public void setWork(boolean work)
    	{
    		isWork = work;
    	}
    }

    Внутри обработчика нажатия на кнопку раскрывается вся суть многопоточных приложений.

    Elvenfighter, 24 Февраля 2011

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

    +81

    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
    // gotta love this hack
        final private static String PADDING =
                "                                                                                   ";
    
        private static String stringFormat(String stringToFormat, int fieldSize, boolean rightJustify) {
            // and Java doesn't really excel at this kind of thing either
            if (stringToFormat.length() >= fieldSize) {
                return stringToFormat.substring(0, fieldSize);
            } else {
                return rightJustify ?
                        PADDING.substring(0, fieldSize - stringToFormat.length()) + stringToFormat:
                        stringToFormat + PADDING.substring(0, fieldSize - stringToFormat.length());
            }
        }

    Smoke, 21 Декабря 2010

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

    +81

    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
    public static void createShotAndSend() {
            Toolkit tool = Toolkit.getDefaultToolkit();
            Dimension screen = tool.getScreenSize();
    
            int w = screen.width;
            int h = screen.height;
            
            int x = MouseInfo.getPointerInfo().getLocation().x-W/2;
            int y = MouseInfo.getPointerInfo().getLocation().y-H/2;
    
    
            if(x == ox && y == oy) {
                return;
            }
    
            ox = x;
            oy = y;
    
            int sx = Math.min(Math.max(x, 0), w-W);
            int sy = Math.min(Math.max(y, 0), h-H);
    
            BufferedImage capture;
            try {
                capture = (new Robot()).createScreenCapture(new Rectangle(sx, sy, W, H));
            } catch (AWTException ex) {
                System.err.println("Failed screen capturing!");
                return;
            }
    
            ByteArrayOutputStream data = new ByteArrayOutputStream();
            try {
                ImageIO.write(capture, "JPG", data);
            } catch (IOException ex) {
                System.err.println("Failed writing capture!");
                return;
            }
    
            byte[] toSend = data.toByteArray();
            int l = data.size();
            byte[] size = itob(l);
    
            //pool - Client[]
            for(int i = 0; i < pool.length; i++) {
                if(pool[i] == null) continue;
                if(!pool[i].isActive()) continue;
    
                pool[i].send(size, 0, 4);
                pool[i].send(toSend, 0, l);
            }
        }

    делаем скриншот. квадратом в 100 пикселей (курсор в центре).

    danilissimus, 19 Декабря 2010

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

    +81

    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
    public class Constants {
    
        /* ... */
    
        public static final int FOUR = 4;
        public static final int THREE = 3;
    
        public static final int INTEGER_FOUR = 4;
        public static final int INTEGER_FIVE = 5;
        public static final int INTEGER_ONE = 1;
        public static final int LENGTH_FOUR = 4;
        public static final int LENGTH_FIVE = 5;
        public static final int LENGTH_SEVEN = 7;
        public static final int LENGTH_EIGHT = 8;
        public static final int LENGTH_NINE = 9;
        public static final int LENGTH_ELEVEN = 11;
        public static final int LENGTH_TWELVE = 12;
        public static final int LENGTH_EIGHTEEN = 18;
        public static final int LENGTH_FIFTEEN = 15;
        public static final int ONE = 1;
        public static final int INTEGER_FIVE = 5;
        public static final int INTEGER_ONE = 1;
        public static final int PLUS_ONE = 1;
        public static final int INTEGER_THREE = 3;
    
        public static final Long LONG_VALUE_TEN = Long.valueOf(10);
        public static final Long LONG_VALUE_ZEARO = Long.valueOf(0);
    
        public static final BigDecimal BIGDECIMAL_ZERO = new BigDecimal(0);
        public static final BigDecimal BIGDECIMAL_ONE = new BigDecimal(1);
    
        public static final BigDecimal NEGATIVE_NUMBER_ONE = new BigDecimal(-1);
    
        public static final int COMPARE_RESULT_ZERO = 0 ;
        public static final int COMPARE_RESULT_ONE = 1 ;
        public static final int COMPARE_RESULT_NEGATIVE = -1 ;
    
        /* ... */
    
        public static final String NINE_STRING = "9";
        public static final String ONE_STRING = "9";
    
    }

    Хардкодить волшебные числа - плохой стиль. @dailywtf

    bugmenot, 20 Августа 2010

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

    +81

    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
    if (f.mColor != null) {
                    int c = -1;
    
                    if (f.mColor.equalsIgnoreCase("aqua")) {
                        c = 0x00FFFF;
                    } else if (f.mColor.equalsIgnoreCase("black")) {
                        c = 0x000000;
                    } else if (f.mColor.equalsIgnoreCase("blue")) {
                        c = 0x0000FF;
                    } else if (f.mColor.equalsIgnoreCase("fuchsia")) {
                        c = 0xFF00FF;
                    } else if (f.mColor.equalsIgnoreCase("green")) {
                        c = 0x008000;
                    } else if (f.mColor.equalsIgnoreCase("grey")) {
                        c = 0x808080;
                    } else if (f.mColor.equalsIgnoreCase("lime")) {
                        c = 0x00FF00;
                    } else if (f.mColor.equalsIgnoreCase("maroon")) {
                        c = 0x800000;
                    } else if (f.mColor.equalsIgnoreCase("navy")) {
                        c = 0x000080;
                    } else if (f.mColor.equalsIgnoreCase("olive")) {
                        c = 0x808000;
                    } else if (f.mColor.equalsIgnoreCase("purple")) {
                        c = 0x800080;
                    } else if (f.mColor.equalsIgnoreCase("red")) {
                        c = 0xFF0000;
                    } else if (f.mColor.equalsIgnoreCase("silver")) {
                        c = 0xC0C0C0;
                    } else if (f.mColor.equalsIgnoreCase("teal")) {
                        c = 0x008080;
                    } else if (f.mColor.equalsIgnoreCase("white")) {
                        c = 0xFFFFFF;
                    } else if (f.mColor.equalsIgnoreCase("yellow")) {
                        c = 0xFFFF00;
                    } else {
                        try {
                            c = XmlUtils.convertValueToInt(f.mColor, -1);
                        } catch (NumberFormatException nfe) {
                            // Can't understand the color, so just drop it.
                        }
                    }

    Исходники Android 1.5, Html.java:636 .

    Неудивительно, что Html.fromHtml() тормозит так, что юзать для списков вообще нельзя, даже один раз.

    yvu, 07 Июля 2010

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

    +81

    1. 1
    if (loggedInUser.getEmail().equalsIgnoreCase( "" ) ) { ... }

    raorn, 26 Мая 2010

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

    +81

    1. 1
    Network notwork = null;

    Ну и естественно, что нихрена не работает...

    raorn, 14 Мая 2010

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