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

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

    +74

    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
    $lang_ru = '<a class=lang-ru-RU href="#" id="btn1">RU</a>';
    $lang_en = '<A class=lang-en-US href="#" id="btn2">EN</A>';
    $lang_de = '<A class=lang-de-DE href="#" id="btn3">DE</A>';
    if (!isset($HTTP_COOKIE_VARS["language"])) {
    	$lang_1 = $lang_ru;
    	$lang_2 = $lang_en;
    	$lang_3 = $lang_de;
    } else {
    	if ($HTTP_COOKIE_VARS["language"] == 'en') {
    		$lang_1 = $lang_en;
    		$lang_2 = $lang_ru;
    		$lang_3 = $lang_de;
    	} else {
    		if ($HTTP_COOKIE_VARS["language"] == 'de') {
    			$lang_1 = $lang_de;
    			$lang_2 = $lang_ru;
    			$lang_3 = $lang_en;
    		} else {
    			$lang_1 = $lang_ru;
    			$lang_2 = $lang_en;
    			$lang_3 = $lang_de;
    		}
    	}
    }

    А если языков было бы больше?

    My_own_private_pony, 10 Мая 2012

    Комментарии (26)
  3. PHP / Говнокод #10224

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if($this->getRequest()->isPost()) {
    			$month = $this->getRequest()->getPost('month', null);
    			$year  = $this->getRequest()->getPost('year', null);
    		} else {
    			$month = $this->getRequest()->getParam('month', null);
    			$year  = $this->getRequest()->getParam('year', null);
    		}

    Индусы, такие индусы.

    anycolor, 09 Мая 2012

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    for(int i = 0; i < fCount; i++)
    {
           result += Integer.parseInt(String.valueOf((fPart.charAt(i))), 10)*Math.pow(base, fCount-(i+1));	    			
    }

    brainy, 14 Апреля 2012

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

    +74

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    public class FSMSmilesMatcher {
    	private Callback mCallback;
    	private State mStartState;
    	
    	public interface Callback {
    		public void onMatch(int matchStart, int matchEnd, int matchId);
    	}
    	
    	//matching whole leading substring cause it's easier to build that way
    	private class State {
    		protected HashMap<String, State> substates; //substring which led to this state + next symbol
    		protected String whole; //whole match
    		protected int matchId;
    		
    		//result = symbols to skip before starting next match
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equals(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchStart, matchEnd));
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    	
    	//checks only next symbol
    	//removes long tails (into single 'whole' match)
    	private class OptimizedState extends State{
    		private OptimizedState(State inState) {			
    			if(inState.substates != null) {
    				this.substates = new HashMap<String, State>();
    				for(String key : inState.substates.keySet()) {
    					this.substates.put(key.substring(key.length()-1, key.length()).toLowerCase(), new OptimizedState(inState.substates.get(key)));
    				}				
    				if(this.substates.size() == 1) {
    					State subState = this.substates.values().iterator().next();
    					if(subState.substates == null) {
    						this.substates = null;
    						this.whole = subState.whole;
    						this.matchId = subState.matchId;
    					}
    				}
    			} else {
    				this.whole = inState.whole;
    				this.matchId = inState.matchId;
    			}
    		}
    		
    		@Override
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equalsIgnoreCase(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchEnd - 1, matchEnd).toLowerCase());
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    
    	...	
    
    	private HashMap<String, State> generateSubstates(List<ImageMatchElement> matches, String lead) {
    		List<String> variants = new ArrayList<String>();
    		HashMap<String, Integer> completeMatches = new HashMap<String, Integer>();
    		
    		...		
    
    		if(variants.size() == 0) {
    			return null;
    		} else {
    			HashMap<String, State> substates = new HashMap<String, State>();
    			for(String variant: variants) {
    				State state = new State();
    				if(completeMatches.containsKey(variant)) {
    					state.whole = variant;
    					state.matchId = completeMatches.get(variant);
    				} else {
    					state.substates = generateSubstates(matches, variant);
    				}
    				substates.put(variant, state);
    			}
    		...

    Требовалось заменить коды смайликов в текстовом сообщении заменить на соответствующие картинки (типа ":* привет :-p ^_^" заменить на "[картинка] привет [картинка] [картинка]".

    enikey87, 09 Апреля 2012

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

    +74

    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
    package com.euc.csvprocessor.misc;
    
    import java.awt.Color;
    /**
     * Генератор кольорів .
     * @author crasht
     *
     */
    public class ColorGenerator {
    	private int c=0;
    	/**
    	 * Повертає наступний колір .
    	 * @return color
    	 */
    	public Color getNextColor(){
    		switch(c){
    		case 0: c++; return Color.BLACK;
    		case 1: c++; return Color.BLUE;
    		case 2: c++; return Color.CYAN;
    		case 3: c++; return Color.DARK_GRAY;
    		case 4: c++; return Color.GRAY;
    		case 5: c++; return Color.GREEN;
    		case 6: c++; return Color.LIGHT_GRAY;
    		case 7: c++; return Color.MAGENTA;
    		case 8: c++; return Color.ORANGE;
    		case 9: c++; return Color.PINK;
    		case 10: c++; return Color.RED;
    		default : c=0; return getNextColor();
    		}
    	}
    }

    Самый рандомный цвет из существующих.

    crashtua, 26 Марта 2012

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private int getDSR(ViolationCache violation){
        int dsr = 0;
        for (StandardViolationCache standardViolation : violation.getStandardViolations()) {    	
            dsr = Integer.valueOf(standardViolation.getOrigPointAssignment()) > dsr ? Integer.valueOf(standardViolation.getOrigPointAssignment()) : dsr;
        }
        return dsr;
    }

    Изящненько...

    roman-kashitsyn, 13 Марта 2012

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

    +74

    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
    94. 94
    95. 95
    for (Tm_RecipientConstructor recipient: m_Recipients) {
    	
    	Tm_PHB_Contact m_Contact = recipient.getContact();
    	
    	if ( m_Contact != null) {					
    		if(m_Contact.getMobile()!=null) {						
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"mobile");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getMobile());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}
    		if(m_Contact.getName()!=null) {						
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"first_name");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getName());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}
    		if(m_Contact.getSurName()!=null) {
    			
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"last_name");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getSurName());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}					
    		if(m_Contact.getPatrName()!=null) {
    			
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"second_name");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getPatrName());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}					
    		if(m_Contact.getCompanyName()!=null) {
    			
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"company");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getCompanyName());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}
    		if(m_Contact.getComment()!=null) {
    			
    			st.setLong(1,recipient.getEntry().getID());//nWebEntryID
    			st.setLong(2,Tm_Registry.getInstance().getAttachementTypes().getID(En_AttachementType.ARGUMENT));//NTYPE
    			st.setString(3,"comments");//STRNAME
    			st.setLong(4,Tm_Registry.getInstance().getAttributeType().getID(En_AttributeType.STRING));//NDATATYPE
    			st.setString(5,m_Contact.getComment());//STRVALUE
    			st.addBatch();
        		index++;
        		if (index % 5000 == 0){		    				
        			st.executeBatch();
        			st.clearBatch();				            
        			st = conn.prepareStatement(sql);
        		}
    		}	
    	}
    }

    Функции? Не, не слышал.

    SadKo, 12 Марта 2012

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    synchronized public void refreshConversionTable() {
            btnClick = true;
            if (dataModel != null)
                dataModel.reset();
            dataModel = null;
        }

    если модель данных существует, сначала сбросить все данные, а потом занулим....

    mrFoxs, 31 Января 2012

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

    +74

    1. 1
    String.format("USR-БГПУ", new Object[] { new SimpleDateFormat("dd MMMM yyyy", new Locale("ru", "RU")) })

    Нашёл в самолично написанной утильке (из серии блиц-[говно]кодинга). Думал.

    0rt, 19 Января 2012

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

    +74

    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
    public class DataRetriever
    {
        public static Object deserializeData(String fileName)
        {
            Object returnValue = null;
            try
            {
                File inputFile = new File(fileName);
                if (inputFile.exists() && inputFile.isFile())
                {
                    try (ObjectInputStream readIn = new ObjectInputStream(new FileInputStream(fileName)))
                    {
                        returnValue = readIn.readObject();
                    }
                }
                else
                {
                    throw new RuntimeException(new FileNotFoundException(fileName + " not found"));
                }
            }
            catch (ClassNotFoundException | IOException exc)
            {
                throw new RuntimeException(exc);
            }
            return returnValue;
        }
    
        private DataRetriever() { throw new AssertionError(); }
    }

    Паранойя неконтролируемых исключений

    dwinner, 17 Января 2012

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