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

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

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public new string ID
    {
    	get
    	{
    		return base.ID;
    	}
    	set
    	{
    		base.ID = value;
    	}
    }

    taburetka, 24 Октября 2014

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

    +117

    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
    @Override
    public void afterPersistenceInit() {
    	val conn = emProvider.get().unwrap(Connection.class);
    
    	try {
    		log.info("Transaction isolation level: {}", getLevelString(conn.getTransactionIsolation()));
    	} catch (final SQLException e) {
    		log.error("Error getting transaction isolation level", e);
    	}
    }
    
    private String getLevelString(final int isolationLevel) {
    	// Poor man's enums. Use reflection to find a constant with the given value
    	try {
    		for (val maybeLevelConstant: Connection.class.getDeclaredFields()) {
    			if (maybeLevelConstant.getType() == int.class && maybeLevelConstant.getName().startsWith("TRANSACTION_")
    					&& maybeLevelConstant.getInt(null) == isolationLevel) {
    				return maybeLevelConstant.getName();
    			}
    		}
    	} catch (final IllegalArgumentException | IllegalAccessException e) {
    		return "UNKNOWN";
    	}
    	
    	return "UNKNOWN";
    }

    Ищем рефлексией константу с нужным значением. И всё для того, чтобы напечатать её в логе. Вот что крест животворящий отсутствие энумов в legacy API делает.

    someone, 23 Октября 2014

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

    +117

    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
    @Nullable
    public static BigDecimal getWidth(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallWidth();
    	case M:
    		return spec.getMediumWidth();
    	case L:
    		return spec.getLargeWidth();
    	default:
    		throw new AssertionError();
    	}
    }
    
    @Nullable
    public static BigDecimal getHeight(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallHeight();
    	case M:
    		return spec.getMediumHeight();
    	case L:
    		return spec.getLargeHeight();
    	default:
    		throw new AssertionError();
    	}
    }
    
    public static BigDecimal getDiameter(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallDiameter();
    	case M:
    		return spec.getMediumDiameter();
    	case L:
    		return spec.getLargeDiameter();
    	default:
    		throw new AssertionError();
    	}
    }
    
    @Nullable
    public static BigDecimal getWeight(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallWeight();
    	case M:
    		return spec.getMediumWeight();
    	case L:
    		return spec.getLargeWeight();
    	default:
    		throw new AssertionError();
    	}
    }

    Бойлерплейт - он такой. А можно ли с JPA это как-то изящнее сделать? Дело в том, что {small|medium|large}{Width|Height|Diamet er|Weight} - это двенадцать столбцов таблицы в БД. Пока единственное, что приходит на ум - это сделать три одинаковых @Embedded'а на каждый размер.

    someone, 19 Октября 2014

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

    +158

    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
    if($mark['data']){
         switch ($mark['data']->point) {
         case '0':
             $table.= "незачет";
             break;
         case '1':
             $table.= "зачет";
             break;
         case '2':
             $table.=  "неудовлетворительно";
             break;
         case '3':
             $table.=  "удовлетворительно";
             break;
         case '4':
             $table.=  "хорошо";
             break;
         case '5':
             $table.=  "отлично";
             break;
            
         default:
             $table.=  "";
             break;
        }
    }else{
        $table.=  "";
    }

    saksmt, 17 Октября 2014

    Комментарии (6)
  6. PHP / Говнокод #16881

    +158

    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
    96. 96
    97. 97
    98. 98
    99. 99
    $table = "<w:tbl>";
    $table .='<w:tblPr>
                <w:tblW w:w="0" w:type="auto"/>
                <w:jc w:val="center"/>
                <w:tblBorders>
                    <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                </w:tblBorders>
                <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
            </w:tblPr>';
    $table .= "<w:tblGrid>
        <w:gridCol w:w='800'/>
        <w:gridCol w:w='3700'/>
        <w:gridCol w:w='2000'/>
        <w:gridCol w:w='1757'/>
        <w:gridCol w:w='1000'/>
        <w:gridCol w:w='1000'/>
    </w:tblGrid>";
    $table .= "<w:tr>";
    $table .='
    <w:trPr>
        <w:jc w:val="center"/>
    </w:trPr>
    ';
    $table .= "<w:tc>";
    $table .= "<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>"; 
    $table .= "<w:t>";
    $table .= "№ п/п";
    $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                <w:cantSplit/>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Фамилия, И.О. студента";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Номер билета";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Оценка* прописью";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
    // ... over200 LOC

    Это контроллер, чтоб вы знали...

    saksmt, 17 Октября 2014

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function viplogin() {
        global $lang, $userrec;
        $ret="<div class=viplogin>".array_pop($var1=mqfa("select id, mixtxt$lang from txts where name='viplogin'")).(!INADMIN?"":"<input style=\"width:35px;\" type=button class=\"changebtn\" value=\"Edit 721\" onclick=\"window.open('edit.php?table=txts&id=$var1[id]&&'+Math.random(),'_blank','toolbar=0, scrollbars=1, resizable=1, width=653, height=620');\">")."</div>".($userrec["local"] || $userrec["isadmin"]?"<a href=# onclick=\"window.open('txted.php?lang=$lang&id=$var1[id]','_blank','width=700, height=500')\">edit</a>":"");
        $ret.="<center><a href=\"".echolink("lang=$lang&page=buyvip")."\">".echoword2("buyvip")."</a></center>";
        return $ret;
    }

    как правильно логинить важных пользователей

    afwbkbc, 15 Октября 2014

    Комментарии (6)
  8. bash / Говнокод #16855

    −112

    1. 1
    `dirname $1`"/"`basename $1 | sed "s/\.squashfs//"`

    шелл. обрезаем расширение имени файла (заданого в $1). хергештельт ин дойчланд.

    Dummy00001, 15 Октября 2014

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $("a").easyTooltip();
    		$("a#link").easyTooltip({
    			tooltipId: "easyTooltip2",
    			content: '<img src="new/img/our_work/mosdacha_g.jpg" />'
    		});

    Неуверенный программист.

    Vasiliy, 03 Октября 2014

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

    +78

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    protected String getFeedText() {
      StringBuffer answer = new StringBuffer();
      if (getFeedName() != null) {
       answer.append("Feed Named: " + getFeedName() + " - ");
    
      }
      return answer.toString();
     }

    1. Похоже на праведное намерение использовать StringBuilder :)
    2. Положение звезд и фаза луны помешали воспользоваться хотя бы StringBuffer, вычисление все равно сделано на простых String

    tort, 01 Октября 2014

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

    −118

    1. 1
    set -xexexe

    из тестового скрипта. началось все с очепятки.

    в дурмане тупого писания тупых тестов, не мог остановится хихикать.

    Dummy00001, 27 Сентября 2014

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