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

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

    +245

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    cmp     DWORD PTR [esi+4], 0     ; if obj->curChip == 0
        push    ebx
        push    edi
        jne     SHORT $LN8@harddetect
        movzx   ebx, WORD PTR [esi+12]   ; ebx = obj->baseport;
        jmp     SHORT $LN9@harddetect
    $LN8@harddetect:
        mov     ax, WORD PTR [esi+12]    ;\
        add     ax, 2                    ; шедевр!
        movzx   ebx, ax                  ;/
    $LN9@harddetect:

    Не понравился размер кода после компиляции. Полез посмотреть. Особо забавной показалась скомпилированная незатейливая конструкция:

    unsigned short port = (curChip == 0 ? baseport : baseport + 2);

    Компилятор VC++ 2005, с оптимизацией по размеру генерируемого кода. Наоптимизировал :D

    DemonId7, 22 Июля 2011

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

    +166

    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
    <?php $ago = time()-$time; ?>
    <?php $hour = sfConfig::get('app_hour_in_seconds'); ?>
    <?php $day = sfConfig::get('app_day_in_seconds'); ?>
    
    <?php if($ago < 60): ?>
    	<span>less than one minute ago</span>
    <?php elseif($ago < $hour): ?>
      <?php $m = floor($ago/60); ?>
    	<span><?php echo($m); ?> minute<?php echo(($m > 1 ? 's' :'')); ?> ago</span>
    <?php elseif($ago <= $day): ?>
    	<?php $h = floor($ago/$hour); ?>
    	<span><?php echo($h); ?> hour<?php echo(($h > 1 ? 's' :'')); ?> ago</span>
    <?php elseif ($ago <= $day*30): ?>
    	<?php $d = floor($ago/$day); ?>
    	<span><?php echo($d); ?> day<?php echo(($d > 1 ? 's' :'')); ?> ago</span>
    <?php elseif ($ago <= $day*365): ?>
    	<?php $m = floor($ago/$day*30); ?>
    	<?php $d = floor(($ago-$m)/$day); ?>
    	<span><?php echo($m); ?> month<?php echo(($m > 1 ? 's' :'')); ?> <?php echo($d); ?> day<?php echo(($d > 1 ? 's' :'')); ?> ago</span>
    <?php else: ?>
    	<?php $y = floor($ago/$day*365); ?>
    	<?php $m = floor(($ago-$y)/$day*30); ?>
    	<?php $d = floor(($ago-$y-$m)/$day); ?>
    	<span><?php echo($y); ?> year<?php echo(($y > 1 ? 's' :'')); ?> 
    		<?php echo($m); ?> month<?php echo(($m > 1 ? 's' :'')); ?> 
    		<?php echo($d); ?> day<?php echo(($d > 1 ? 's' :'')); ?> ago</span>
    <?php endif; ?>

    Кусок кода, выводящий дату поста в формате N days N hours ago....
    Кроме собственно говностиля забавляет наличие цифр 30 и 365 в коде)

    programmer, 18 Июля 2011

    Комментарии (17)
  4. SQL / Говнокод #7252

    −859

    1. 1
    2. 2
    3. 3
    4. 4
    SELECT 
    	InstanceID, 
    	DisplayValue AS VidDocValue 
    FROM [dvtable_{D25F1089-C63D-43E1-9FA4-864C48EECCB4}] AS [dvtable_{D25F1089-C63D-43E1-9FA4-864C48EECCB4}_1]

    HellMaster_HaiL, 15 Июля 2011

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

    +168

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    /*
    * Выводим чекбоксы :D
    * $name - имя инпута чеки
    * $val - тру ор фалсе
    */
    function checkbox($name, $val) 
    {
    	$checked = !empty($val) ? 'checked ' : false;
    	return "<input type=\"checkbox\" name=\"" . $name . "\" " . $checked . "/>";
    }

    Тру от фалсе

    nethak, 12 Июля 2011

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !trim(strip_tags($strAddress))){
            return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !trim(strip_tags($strAddress))){
    	return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !$this->address_houses && !trim(strip_tags($strAddress))){
    	return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !$this->address_houses && !$this->address_houseroom && !trim(strip_tags($strAddress))){
    	return '';
    }

    Найдено в одной CMS

    CRRaD, 12 Июля 2011

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

    +85

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

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

    Loord, 15 Июня 2011

    Комментарии (17)
  8. PHP / Говнокод #6901

    +168

    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
    function ($param)
    {
    	$cnt = 0;
    
    	$result = mysql_query("SELECT * FROM `table` WHERE `table_field` = ".$param);
    
    	if ($result) 
    	{
    		while($row_s = mysql_fetch_assoc($result))
    		{
    			$cnt++;
    		}
    	}
    	else 
    	{
    		$cnt = 0;
    	}
    
    	return $cnt;
    }

    Шедевр неизвестного программиста.

    devl, 08 Июня 2011

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

    +175

    1. 1
    $(this).parent().parent().parent().siblings('.last-email').removeClass('hidden');

    http://nsk.2gis.ru/media/js/main.js
    оттуда же :)

    Back, 31 Мая 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var color2array = function(color){
    	return color.length==4?color.slice(1).split('').map(function(x){return parseInt(x,16)}).concat([255]):
    	       color.length==7?[color.slice(1,3),color.slice(3,5),color.slice(5)].map(function(x){return parseInt(x,16)}).concat([255]):
    		   ~color.indexOf('rgba')?color.slice(5,-1).split(',').map(function(x){return +x}):
    		   ~color.indexOf('rgb')?color.slice(4,-1).split(',').map(function(x){return +x}).concat([255]):[0,0,0,255];
    }

    Один большой костыль преобразующий цвет из вида hex rgb rgba в массив значений от 1 до 255

    art543484, 25 Мая 2011

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

    +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
    import java.util.Calendar;
    public class CalendarTime {
    	public static void main(String args[]) {
    	Calendar now = Calendar.getInstance();
    	now.setTimeInMillis(System.currentTimeMillis());
    	System.out.println("Now : "+(((now.get(Calendar.YEAR))))+" year.");
    	System.out.println("Now : "+(((now.get(Calendar.MONTH))))+" month.");
    	System.out.println("Now : "+(((now.get(Calendar.DATE))))+" day.");
    	System.out.println("Now : "+(((now.get(Calendar.HOUR_OF_DAY))))+" hour.");
    	System.out.println("Now : "+(((now.get(Calendar.MINUTE))))+" minute.");
    	System.out.println("Now : "+(((now.get(Calendar.SECOND))))+" second.");
    	}
    }

    System.out.println("Now : "+(((now.get(Calendar.MONTH))))+" month.");
    Обратите внимание на эту строку. Отображение идёт некорректно , странно почему??
    С наилучшими пожеланиями, Sun Microsystems ^_^).

    Akira, 13 Мая 2011

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