1. Куча / Говнокод #11688

    +142

    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
    program maze;{МАЗЬ}
    
    ...
    
    REPEAT UNTIL KEYPRESSED;
    
    ...
    
    case {коза} с of:
    ...
    
    
    /* FILE NAME   : IMAGE.C
     * PURPOSE     : Fig it knows.
    ...
    */
    
      BYTE *buf = 0L;
      if (!(buf += malloc(WWW * HHH)))
      {
        printf(" У меня склероз ...\n Press Ctrl-Alt-Del.");
        return;
      }
    
    for(int C=0;C<n;/*Borland*/C++)
    ...

    Петросянство в школокоде :-\

    (+= - чтобы избавиться от варнинга.)

    Steve_Brown, 31 Августа 2012

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

    +32

    1. 1
    static_cast<SomeOtherClass>(this)->SomeMethod();

    Чуваки лучше знают, что у них в this

    bazhenovc, 31 Августа 2012

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

    +139

    1. 1
    <span style="display: block">

    div? не, не слышал

    dead_star, 31 Августа 2012

    Комментарии (11)
  4. Си / Говнокод #11685

    +103

    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
    void str2ip_s_Before( unsigned char* ptrIP, unsigned short* ptrPort, const wchar_t* src, size_t count )
    {
        int i;
        if( !ptrIP )
            return;
    
        while( src && count && !iswdigit( *src ) )//skip separators and spaces
            ++src, --count;
    
        for( i = 0; i < 4 && count; ++i )//IP address
        {
            ptrIP[ i ] = ( unsigned char )_wtoi( src );
    
            while( src && count && iswdigit( *src ) )//skip current number
                ++src, --count;
    
            while( src && count && !iswdigit( *src ) )//skip separators and spaces
                ++src, --count;
        }
    
        if( ptrPort && src && count )
            *ptrPort = ( unsigned short )_wtoi( src );
    }
    
    int str2ip_sAfter( unsigned char* ptrIP, unsigned short* ptrPort, const wchar_t* src, size_t count )
    {
        int i, iRadix;
        wchar_t* endptr;
    
        if( !ptrIP || !src || 0 == count )
            return 0;
    
        for( i = 0; i < 4; ++i )
            ptrIP[ i ] = 0;
        if( ptrPort )
            *ptrPort = 0;
    
        while( 0 != count && !iswdigit( *src ) ) //skip separators and spaces
            ++src, --count;
    
        for( i = 0; i < 4 && 0 != count; ++i ) //IP address
        {
            if( count > 1 && src[ 0 ] == L'0' )
            {
                if( src[ 1 ] != L'x' && src[ 1 ] != L'X' )
                    iRadix = 8;
                else
                    iRadix = 16;
            }
            else
                iRadix = 10;
    
            ptrIP[ i ] = ( unsigned char )wcstol( src, &endptr, iRadix );
            if( src == endptr )
                return 0;
            count -= endptr - src;
            src = endptr;
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
    
            if( i < 3 )
            {
                if( L'.' == *src ) //skip point
                    ++src, --count;
                else
                    return 0;
            }
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
        }
    
        if( i < 4 )
            return 0;
    
        if( ptrPort )
        {
            if( 0 == count || L':' != *src ) //skip point
                return 0;
            ++src, --count;
    
            while( 0 != count && iswspace( *src ) ) //skip spaces
                ++src, --count;
    
            *ptrPort = ( unsigned short )wcstol( src, &endptr, 10 );
            if( src == endptr )
                return 0;
            else
                return 1;
        }
        else
            return 1;
    }

    Пуресишник зарефакторил

    sokol, 31 Августа 2012

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

    −157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    class SomeModel < ActiveRecord::Base
      after_save :some_method
    
      def some_method
        self.save
      end
    
    end

    Рекурсивная рекурсия рекурсивна.

    mr.The, 31 Августа 2012

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

    +57

    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
    function GetOrderSkidka(&$arrData)
        	{
    	    	if($this->flag_opt){
    	    	 	$arrData['skidka']  = ($this->admin_mode) ? $arrData['skidka'] : 0;
    	    	 	$arrData['allsum']  = $arrData['sum'] - $arrData['skidka'];
    	    	 	return;
    	        }
    	    	if(!$this->flag_in_action){
    	    		$arrData['cnt_s_prod'] = $arrData['cnt'];
    	    	}elseif(in_array($this->flag_action_type,array(2,3))){
    	    		$this->calcCntProd($arrData);
    	    	}else{
    	    		$arrData['cnt_s_prod'] = 0;
    	    	}
    	    	$this->discount->GetOrderSkidka($arrData);
        	}

    Работаю с сайтом, в котором все методы классов работают со своими параметрами таким образом.
    Метод может ничего не возвращать, а вызывать другие методы (которые также могут вызывать какие-то методы),
    которые в зависимости от множества условий меняют переданные по ссылке параметры.
    Итог работы модифицированный параметр- массив. Только XDebug выручает.

    minramilka, 31 Августа 2012

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

    +121

    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
    try {
    	repository.saveAll(entities);
    } catch (final ConstraintViolationException e) {
    	throw new SettingsServiceException(ErrorFormatter.formatValidationErrors(
    			"Errors have been detected when saving", e));
    } catch (final PersistenceException e) {
    	for (val t: Throwables.getCausalChain(e)) {
    		if (t instanceof EntityExistsException) {
    			val failedObject = (IEntity) ((ExceptionInfo) t).getFailedObject();
    			
    			// failedObject is returned with the state in which it is in the database.
    			// Let's find the version that we tried to save, instead.
    			for (val entity: entities) {
    				if (entity.getId() != null && entity.getId().equals(failedObject.getId())) {
    					throw new SettingsServiceException("Attempted to save duplicate value: " + entity);
    				}
    			}
    		}
    	}
    	
    	throw e;
    }

    Попытка вернуть пользователю человеко-читаемое сообщение о том, где, собственно, дубликат.

    Костыли вы мои, костыли...

    someone, 31 Августа 2012

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

    +54

    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
    <?php
    
    class SimpleController extends Zend_Controller_Action
    {
        public function init()
        {
            $action = $this->_request->getActionName();
            $is_action_available = in_array($action, explode(',', 'terms,privacy,about,copyright,support,legal,features,help,refund'));
            $is_incorrect_action = CR_Settings::siteIsFree() && $action == 'refund';
            if (!$is_action_available || $is_incorrect_action)
                $this->_helper->redirector->setGotoRoute(array('action' => 'index'), 'default', true);
        }
        
        public function termsAction(){
        }
        
        public function privacyAction(){
        }
        
        public function aboutAction(){
        }
        
        public function copyrightAction(){
        }
        
        public function supportAction(){
        }
        
        public function legalAction(){
        }
        
        public function featuresAction(){
        }
        
        public function helpAction(){
        }
        
        public function refundAction(){
        }
    }

    Zend Framework проверка на существование action :)

    arkasha, 31 Августа 2012

    Комментарии (4)
  9. C++ / Говнокод #11680

    +26

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    result.push_back(TVector<2>
    				(
    					(A-√(D))/C,
    					(E-Line.K()*√(D))/C
    				));
    				result.push_back(TVector<2>
    				(
    					(A+√(D))/C,
    					(E+Line.K()*√(D))/C
    				));

    LispGovno, 31 Августа 2012

    Комментарии (55)
  10. Куча / Говнокод #11679

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (http_status_code == 200 || http_status_code == 500) {
      .... //success!!
    } else {
      .... // error!!
    }

    Было замечено в одном андроид приложении.

    mr.The, 30 Августа 2012

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