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

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

    +72.2

    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
    private char readNextChar() throws IOException {
            synchronized (in) {
                if (plain) {
                    if (BANDWIDTH_DEBUG) {
                        CasinoServer.bandwidthChecker.addClientMessageReceived(1);
                    }
                    int c = in.read();
                    if (c == -1) {
                        throw new IOException("Client disconnected");
                    }
                    return (char) c;
                }
                if (num_bytes_read % 5 == 0) {
                    if (!isNgClient()) {
                        last_byte_read = readURLEncodedChar();
                    } else {
                        if (BANDWIDTH_DEBUG) {
                            CasinoServer.bandwidthChecker.addClientMessageReceived(1);
                        }
                        int c = in.read();
                        if (c == -1) {
                            throw new IOException("Client disconnected");
                        }
                        last_byte_read = c & 0xff;
                    }
                    ++num_bytes_read;
                }
                int x;
                if (!isNgClient()) {
                    x = readURLEncodedChar();
                } else {
                    if (BANDWIDTH_DEBUG) {
                        CasinoServer.bandwidthChecker.addClientMessageReceived(1);
                    }
                    int c = in.read();
                    if (c == -1) {
                        throw new IOException("Client disconnected");
                    }
                    x = c & 0xff;
                }
                last_byte_read ^= x;
                int y = last_byte_read;
                last_byte_read = (x & 0xff);
                ++num_bytes_read;
                return (char) (y & 0xff);
            }
        }

    This is the ingenious algorithm, invented by the estonians to read a simple byte from a socket. Couldn't think of anything more error-prone, and less readable. Enjoy!

    bot225, 20 Октября 2009

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

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    resultWhereClause += " AND (lower(concat(per.firstName,' ',per.lastName,' ',per.middleName)) like lower(#{utils.concat(\"%\", \"" + applicant + "\", \"%\")})";
    resultWhereClause += " or lower(concat(per.lastName,' ',per.firstName,' ',per.middleName)) like lower(#{utils.concat(\"%\", \"" + applicant + "\", \"%\")})";
    resultWhereClause += " or lower(concat(per.firstName,' ',per.middleName,' ',per.lastName)) like lower(#{utils.concat(\"%\", \"" + applicant + "\", \"%\")}))";
    resultWhereClause += "))";

    Изящный хак для (на самом деле нет) для поиска по ФИО

    chsh, 23 Марта 2015

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

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    try
    {
    	    tmp = stored.get( name ) != null;
    } catch (Exception e)
    {
    /***/
    }

    Умело обходим NullPointerException + свой велосипед вместо containsKey

    sakkath, 03 Февраля 2015

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

    +72

    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
    public class Командир {
        private String имя;
        private ПоходНаГерманию поход;
    
        public Командир(String имя) {
            this.имя = имя;
            поход = new ПоходНаГерманию();
         }
    
        public Богатство пойтиВпоход()
                             throws НеПолучилосьException {
            return поход.сходить();
        }
    }

    больше русской жабы тут http://www.spring-source.ru/docs_simple.php?type=manual&theme=docs_s imple&docs_simple=chap01_p03

    argamidon, 24 Января 2015

    Комментарии (15)
  6. Pascal / Говнокод #17371

    +72

    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
    var
      a : array[1..15000] of Integer;
      b : Real;
      c,k,i,j : Int64;
    begin
    
      c:=0;
      k:=0;
    
    for i:=1 to 15000 do
      a[i]:=i;
      
    for i:=1 to 15000 do
    begin
      for j:=1 to 15000 do
      begin
      b:=a[i] mod j;
        if b=0 then
          k:=k+1;
      end;
      if k=2 then
      begin
      WriteLn(a[i]);
      c:=c+1;
      end;
      
      k:=0;
    
      if c=1000 then
      break
    end;
      
    end.

    Ищем простые числа

    Toha, 25 Декабря 2014

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

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public final class DefaultConfig extends TTConfig {
        public DefaultConfig(final int whole, final int pause, final int warn) {
            super(60, 10, 3);
        }
    }

    конфига и ее стандартный вариант (подходящий в 99,9% случаев)

    Lure Of Chaos, 15 Декабря 2014

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

    +72

    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
    private String shutdown = "SHUTDOWN";
    
    ........
    
    // Read a set of characters from the socket
    int expected = 1024; // Cut off to avoid DoS attack
    
    <--Зачем это тут?-->
    while (expected < shutdown.length()) {
        if (random == null)
            random = new Random();
        expected += (random.nextInt() % 1024);
    }
    
    
    while (expected > 0) {
        int ch = -1;
        try {
            ch = stream.read();
        } catch (IOException e) {
            log.warn("StandardServer.await: read: ", e);
            ch = -1;
        }
        if (ch < 32)  // Control character or EOF terminates loop
            break;
        command.append((char) ch);
        expected--;
    }

    Не понимаю зачем тут while. Авторы Apache Tomcat расскажите...

    mrFoxs, 25 Ноября 2014

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

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    protected boolean matches(final PlasticField field) {
    		try {
    			return (this.type() == null) || this.type().getName().equals(field.getTypeName()) ? true : Class.forName(
    				this.type().getName()).isAssignableFrom(Class.forName(field.getTypeName()));
    		} catch (final ClassNotFoundException e) {
    			this.logger.error(e.getMessage(), e);
    		}
    		return false;
    	}

    DRY in action

    такая вот говнопластмасса

    Lure Of Chaos, 20 Августа 2014

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

    +72

    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
    private static String fetchEventName(LogEventTypes event) {
    	String result = null;
    	
    	if (LogEventTypes.A.name().equals(event.name()))) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.B.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.C.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.D.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.E.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.F.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.G.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.H.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.I.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.J.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.K.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	} else if (LogEventTypes.L.name().equals(event.name())) {
    		result = play.i18n.Messages.get("...");
    	}
    
    	return result;
    }

    Секретную инфу потер :) Но думаю, и так все ясно... LogEventTypes - у нас enum.
    Код писал индус (нет ну правда, индус).

    kostoprav, 24 Июня 2014

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

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    Date convertedDate = new Date();
    		SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy:MM:dd",
    				Locale.getDefault());
    
    		try {
    			convertedDate = dateFormatter.parse("" + year + ":" + month + ":"
    					+ day);
    		} catch (ParseException e) {
    			e.printStackTrace();
    		}
    		SimpleDateFormat fmtOut = new SimpleDateFormat("MM/dd/y");
    		String curDate = fmtOut.format(convertedDate).toString();

    andrew91, 13 Июня 2014

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