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

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

    +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
    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
    public final class Equality {
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eq(@Nullable O o, @Nullable O a) {
            return Objects.equals(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
            return eq(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
            return eq(o, a) || eq(o, b);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
            return eqAny(o, a, b) || eq(o, c);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
            return eqAny(o, a, b, c) || eq(o, d);
        }
    
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @param e an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
            return eqAny(o, a, b, c, d) || eq(o, e);
        }
        
        /**
         * @param o an object
         * @param a an array of objects to be compared
         * @return true if any the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, O... a) {
            for(O e: a)
                if(eq(o, e))
                    return true;
            return false;
        }
    }

    Мой любимый класс.
    Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
    И да, комментарии врут, и да, там еще столько же методов eqAll(...)

    stasmarkin, 05 Марта 2015

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

    +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
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    int[] pirates = {
                    R.drawable.final_0001, R.drawable.final_0002, R.drawable.final_0003, R.drawable.final_0004,
                    R.drawable.final_0005, R.drawable.final_0006, R.drawable.final_0007, R.drawable.final_0008,
                    R.drawable.final_0009, R.drawable.final_0010, R.drawable.final_0011, R.drawable.final_0012,
                    R.drawable.final_0013, R.drawable.final_0014, R.drawable.final_0015, R.drawable.final_0016,
                    R.drawable.final_0017, R.drawable.final_0018, R.drawable.final_0019, R.drawable.final_0020,
                    R.drawable.final_0021, R.drawable.final_0022, R.drawable.final_0023, R.drawable.final_0024,
                    R.drawable.final_0025, R.drawable.final_0026, R.drawable.final_0027, R.drawable.final_0028,
                    R.drawable.final_0029, R.drawable.final_0030, R.drawable.final_0031, R.drawable.final_0032,
                    R.drawable.final_0033, R.drawable.final_0034, R.drawable.final_0035, R.drawable.final_0036,
                    R.drawable.final_0037, R.drawable.final_0038, R.drawable.final_0039, R.drawable.final_0040,
                    R.drawable.final_0041, R.drawable.final_0042, R.drawable.final_0043, R.drawable.final_0044,
                    R.drawable.final_0045, R.drawable.final_0046, R.drawable.final_0047, R.drawable.final_0048,
                    R.drawable.final_0049, R.drawable.final_0050, R.drawable.final_0051, R.drawable.final_0052,
                    R.drawable.final_0053, R.drawable.final_0054, R.drawable.final_0065, R.drawable.final_0056,
                    R.drawable.final_0057, R.drawable.final_0058, R.drawable.final_0059, R.drawable.final_0060,
                    R.drawable.final_0061, R.drawable.final_0062, R.drawable.final_0063, R.drawable.final_0064,
                    R.drawable.final_0065, R.drawable.final_0066, R.drawable.final_0067, R.drawable.final_0068,
                    R.drawable.final_0069, R.drawable.final_0070, R.drawable.final_0071, R.drawable.final_0072,
                    R.drawable.final_0073, R.drawable.final_0074, R.drawable.final_0075, R.drawable.final_0076,
                    R.drawable.final_0077, R.drawable.final_0078, R.drawable.final_0079, R.drawable.final_0080,
                    R.drawable.final_0081, R.drawable.final_0082, R.drawable.final_0083, R.drawable.final_0084,
                    R.drawable.final_0085, R.drawable.final_0086, R.drawable.final_0087, R.drawable.final_0088,
                    R.drawable.final_0089, R.drawable.final_0090, R.drawable.final_0091, R.drawable.final_0092,
                    R.drawable.final_0093, R.drawable.final_0094, R.drawable.final_0095, R.drawable.final_0096,
                    R.drawable.final_0097, R.drawable.final_0098, R.drawable.final_0099, R.drawable.final_0100,
                    R.drawable.final_0101, R.drawable.final_0102, R.drawable.final_0103, R.drawable.final_0104,
                    R.drawable.final_0105, R.drawable.final_0106, R.drawable.final_0107, R.drawable.final_0108,
                    R.drawable.final_0109, R.drawable.final_0110, R.drawable.final_0111, R.drawable.final_0112,
                    R.drawable.final_0113, R.drawable.final_0114, R.drawable.final_0115, R.drawable.final_0116,
                    R.drawable.final_0117, R.drawable.final_0118, R.drawable.final_0119, R.drawable.final_0120
            };

    Погромист на Ондроид наговнокодил это...

    argamidon, 18 Февраля 2015

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

    +85

    1. 1
    mDay = --mDay;

    no comments

    Hits, 14 Августа 2012

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

    +85

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try {
    	   keySpec = new PBEKeySpec(s.toCharArray());
    	   tempKey = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
         } catch (InvalidKeySpecException i) {}
    
    if(tempKey == null) {
          keySpec = new PBEKeySpec(s.toCharArray());
          tempKey = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
    }

    Будь настойчив и не сдавайся!!!!

    kibberpunk, 18 Октября 2011

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

    +85

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private List<List<List<List<WeatherData>>>> groupByCityServerDate(List<List<List<WeatherData>>> cityServerList) {
                                   List<List<List<List<WeatherData>>>> cityServerDateList = new ArrayList<List<List<List<WeatherData>>>>();
                                   for (List<List<WeatherData>> serverList : cityServerList) {
                                                   List<List<List<WeatherData>>> serverDateList = new ArrayList<List<List<WeatherData>>>();
                                                   for (List<WeatherData> list : serverList) {
                                                                   serverDateList.add(groupByDate(list));
                                                   }
                                                   cityServerDateList.add(serverDateList);
                                   }
                                   return cityServerDateList;
                    }

    Из кода тестового задания кандидата (с) kacit.ru

    alexinspir, 05 Октября 2011

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

    +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
    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
    nLen = m_aRealTexts[index].m_txtString.length();
    for (int iyhx = 0; iyhx < nLen; iyhx++) {
    	cLetter = m_aRealTexts[index].m_txtString.charAt(iyhx);
    	CTxtCharStyle pCharNode = new CTxtCharStyle(cLetter);
    	pCharNode.SetTxtFontFace(m_nFontFace);
    	m_aRealTexts[index].m_txtChars.add(pCharNode);
    }
    
    ...
    
    
    public void SetTxtFontFace(byte nType)
    {
    	String sLine, sTemp;
    	int nMark;
    	float xValue, yValue;		//笔画点位的临时坐标
    	byte bIsBigChar = 0;		//1表示ANSI字体UserArial_ansi.uft,2表示Unicode字体UserArial_unicode.uft,3表示宋体hztxt1.shx
    	m_cStroke.clear();			//清空笔画路径链表
    	
    	if(nType == 1)
    	{
    		if((int)m_cChar<0x7F || ((int)m_cChar>=0x2160&&(int)m_cChar<=0x2169))
    		{
    			//按Unicode编码顺序处理字符查找指定字库文件,避免读取不必要的字库文件
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/UserArial_ansi.uft");
    			
    			...
    			
    			fInFile.close();
    		}
    		else if((int)m_cChar>=0x007F && (int)m_cChar<0x2FFF)
    		{
    			//字符在UserArial_ansi.uft中未找到,看是否在UserArial_unicode.uft中
    			int nGetByte;
    			sLine = new String("");
    			sTemp = new String("");
    			//float xValue, yValue;
    			byte[] CharUnicode = new byte[2];			//一次读取两个字节,为一个字符
    			byte[] cBytes = new byte[2];
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/UserArial_unicode.uft");
    			while((nGetByte = fInFile.read(cBytes, 0, 2)) > 0)
    			{
    				...
    			}
    			fInFile.close();
    		}
    		else if((int)m_cChar>=0x3000)
    		{
    			//字符在西文字库UserArial.uft中未找到,是大字体,则在宋体文件hztxt1.shx中查找
    			m_cWidth = 112.0f;	//对于宋体,左下角点为坐标原点,包围盒长宽皆为127,调整量为(127-112)/2=5
    			m_cHeight = 112.0f;
    			byte nMoveDown = 5;
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/hztxt1.shx");
    			
    			...
    			
    			fInFile.close();
    		}
    		else if(bIsBigChar == 0)
    		{
    			//仍然没有找到字符字体,则按空格处理
    			m_cWidth = 12.0f;
    			m_cHeight = 16.0f;
    			m_cStroke.clear();
    		}
    	}
    	else if(nType == 2)
    	{
    		try
    		{
    			
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/hztxt1.shx");
    			
    			...
    			
    			fInFile.close();
    			
    		}
    		catch(IOException e)
    		{
    			//异常处理
    			e.printStackTrace();
    		}
    	}
    }

    Ещё один отжиг господ китайцев.

    Магические числа вместо энумов и закрытие файлов вне finally - это ещё полбеды. Больше всего умиляет, что при каждой отрисовке отдельно для каждой буквы файл шрифта открывается и сканируется по новой. Неудивительно, что отрисовка так тормозит. Буду переписывать это дело - загружать глифы из файла один раз и затем дёргать их из кэша.

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

    Комментарии (13)
  8. Куча / Говнокод #7848

    +85

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Да обойдут вас стороной фатал эрроры, и ужас от переписывания говнокода нубов!=) 
    Пишите так, чтобы программа не требовала дополнительной плашки памяти на 2 гектара!
    Желаю успешного развития в этой нелегкой сфере IT!
    
    Мои искренние поздравления с днем программиста!

    1_and_0, 12 Сентября 2011

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

    +85

    1. 1
    boolean ROLLBACK = new Boolean(false).booleanValue();

    И это пишет тимлид (сеньор) в моей конторе

    Loord, 15 Июня 2011

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

    +85

    1. 1
    String methodName = (new Exception()).getStackTrace()[1].getMethodName();

    Вот как надо получать имя метода. Это вам не __func__ ...

    roman-kashitsyn, 14 Июня 2011

    Комментарии (47)
  11. Pascal / Говнокод #5805

    +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
    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
    91. 91
    92. 92
    93. 93
    // ComPort1: TComPort; компонент для работы RS-232
    type
     Tst5=string[5];
    var
      Form1: TForm1;
      lastcnl:byte;
      CommonShiftTT:integer;
      roundtt:integer;
      Start_Proces:boolean;
      intN,intdg0,intdg50:integer;
      cerr,cerr0,cerr50:integer;
      intdg:integer;
      cnl:integer;
      b:array [1..5]of byte;
      s,sdg50,sdg0,ss:Tst5;
      tt,realdg:real;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.ComPort1RxBuf(Sender: TObject; const Buffer;
      Count: Integer);
    var
      i:integer;
      p:pointer;
    begin
     for i:=1 to 5 do b[i]:=0;
     ListBox1.Items.clear;
     if ComPort1.Connected then begin
        p:=@Buffer;
        b[1]:=byte(p^);
      end
      else begin
        exit;
      end;
      cnl:=b[1];
      if cnl=0 then begin
        Start_Proces:=true;
      end;
      ListBox1.Items.Add(inttostr(cnl));
      if Start_Proces=true then begin
        b[2]:=Byte(pointer(longint(p)+1)^);
        b[3]:=Byte(pointer(longint(p)+2)^);
        b[4]:=Byte(pointer(longint(p)+3)^);
        b[5]:=Byte(pointer(longint(p)+4)^);
    
        if (b[2] and $20)>0 then ss[1]:='+' else ss[1]:='-';
        if (b[2] and $40)>0 then ss[2]:='0' else ss[2]:='1';
    
        FOR i:=3 TO 5 DO begin
        case b[i] of
              $82:ss[i]:='0';
              $CF:ss[i]:='1';
              $A4:ss[i]:='2';
              $85:ss[i]:='3';
              $C9:ss[i]:='4';
              $91:ss[i]:='5';
              $90:ss[i]:='6';
              $C7:ss[i]:='7';
         {min}$80:ss[i]:='8';
              $81:ss[i]:='9';
              $FF:ss[i]:='x'
            else ss[i]:=chr(b[i]);
        end;
        ss[0]:=#5;
    
        case cnl of
          0:begin
            vaL(ss,intdg0,cerr0);
            stR(intdg0,sdg0);
            Label1.Caption:=inttostr(intdg0);
          end;
          1:begin
            vaL(ss,intdg50,cerr50);
            stR(intdg50,sdg50);
            Label2.Caption:=inttostr(intdg50);
          end;
          2..26:begin
            vaL(ss,intN,cerr);
            intN:=intN-intdg0+CommonShiftTT;
            realdg:=intN/((intdg50-intdg0)/500);{real type}
            intdg:=SMALLINT(round(realdg));{integer type}
            tt:=intdg/10;
            roundtt:=SMALLINT(round(tt));{integer}
            stR(roundtt:5,s);
          end;
        end;
      end;
      ListBox1.Items.Add('float='+floattostr(tt));
      ListBox1.Items.Add(inttostr(cnl)+'='+ss+' = '+inttostr(roundtt));
     end;
    end;

    Процедура приема и обработки Кодов АЦП с контроллера. Контроллер обрабатывает данные полученные с температурных (аналоговых) датчиков и передает на COM в цифровом виде.
    Сделано для АКГУП Индустриальный г. Барнаул

    zak, 25 Февраля 2011

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