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

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

    +14

    1. 1
    2. 2
    3. 3
    4. 4
    std::string buf_str = str;
    buf_str.erase( 0, strBlobFsParam.size() + 1 );
    buf_str.erase( buf_str.begin(), find_if(buf_str.begin(), buf_str.end(), not1( ptr_fun<int, int>(isspace) ) ) );
    buf_str.erase( find_if( buf_str.rbegin(), buf_str.rend(), not1( ptr_fun<int, int>(isspace) ) ).base(), buf_str.end() );

    trim головного мозга

    roman-kashitsyn, 26 Июля 2013

    Комментарии (7)
  3. Objective C / Говнокод #13427

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //написали и нам на кодревью сказали что это Оо
    if (([someobj1.index isEqualToNumber:someobj2.index] ? YES : NO)) {...}
    //рефакторим в:
    BOOL *check;
    [someobj1.index isEqualToNumber:someobj2.index] ? (check=YES) : (check = NO)
    if (check) {...}
    //видим что среда ругается и наконец рождаем
    if ([someobj1.index isEqualToNumber:someobj2.index]) {...}

    перлы все тогоже джуна

    torip3ng, 15 Июля 2013

    Комментарии (7)
  4. Pascal / Говнокод #13363

    +133

    1. 1
    2. 2
    3. 3
    Прокси-граббер
    
    http://rghost.ru/47337858

    Наш ответ ансикльным петушкам)

    Stertor, 11 Июля 2013

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

    +132

    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
    $error = "Всё хорошо";
     
    if (!$_POST['mail'] || !checkEmail($_POST['mail'])) {
        $error .= "Не верный E-mail";
    }
     
    ...
     
    if ($error == "Всё хорошо") {
        $db->query("INSERT...
    } else {
     
    ...

    PragramistOtBoga, 09 Июля 2013

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

    −95

    1. 1
    2. 2
    3. 3
    4. 4
    obj.serialized_data = str(serialized_data).replace(
                        " u'", " '").replace("{u'", "{'").replace(" '", ' "').replace("':", '":').replace(
                        "{'", '{"').replace("', ", '", ').replace("'}", '"}').replace(' True,', ' true,').replace(
                        'None', 'null').replace(' False,', 'false,')

    Сериализация словаря

    Crazyzubr, 05 Июля 2013

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

    +150

    1. 1
    2. 2
    3. 3
    if (!empty ($src) && !array_key_exists($src, $this->loadedjscripts)) {
                if (isset ($this->loadedjscripts[$src]))
                    return;

    Если ключа нет, то проверяем не null ли значение в массиве по этому индексу.

    Agel_Nash, 22 Июня 2013

    Комментарии (7)
  8. JavaScript / Говнокод #13167

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    /* ----------------------- */
    function stopLevel()
    {
        //clean
        context2D.clearRect(...);
        ...
    }
    
    /* ----------------------- */
    /* ----------------------- */
    /* ----------------------- */
    function nextStep() { ... }

    В коде все комментарии написаны исключительно азбукой Морзе :|

    wvxvw, 13 Июня 2013

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

    +70

    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
    @OnEvent("search")
    	@ReportGritter(title = "message:error", text = "message:database_error")
    	Results search() {
    		final List<Result> results = new ArrayList<Result>();
    		int count = 0;
    		final List<?> search1 = this.bands.search(this.query);
    		final String group1 = HSSearch.GROUP_BANDS;
    		if (!search1.isEmpty()) {
    			results.addAll(this.transform(search1, group1));
    			count += search1.size();
    		}
    		final List<?> search2 = this.albums.search(this.query);
    		final String group2 = HSSearch.GROUP_ALBUMS;
    		if (!search2.isEmpty()) {
    			results.addAll(this.transform(search2, group2));
    			count += search2.size();
    		}
    		final List<?> search3 = this.tracks.search(this.query);
    		final String group3 = HSSearch.GROUP_TRACKS;
    		if (!search3.isEmpty()) {
    			results.addAll(this.transform(search3, group3));
    			count += search3.size();
    		}
    		this.results.setResults(results);
    		this.results.setCount(count);
    		return this.results;
    	}
    
    	private <E> String toTitle(final E item) {
    		if (item instanceof BandEntity) {
    			return ((BandEntity) item).getTitle();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return String.format("%s (%d)", aitem.getTitle(), Integer.valueOf(aitem.getYear()));
    		}
    		if (item instanceof TrackEntity) {
    			return ((TrackEntity) item).getTitle();
    		}
    		return item.toString();
    	}
    
    	private <E> String toUrl(final E item) {
    		if (item instanceof BandEntity) {
    			final BandEntity bitem = (BandEntity) item;
    			return this.links.createPageRenderLinkWithContext(Band.class, bitem.getLetter(), bitem.getAlias())
    					.toAbsoluteURI();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, aitem.getBand().getLetter(),
    					aitem.getBand().getAlias(), aitem.getAlias()).toAbsoluteURI();
    		}
    		if (item instanceof TrackEntity) {
    			final TrackEntity titem = (TrackEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, titem.getAlbum().getBand().getLetter(),
    					titem.getAlbum().getBand().getAlias(), titem.getAlbum().getAlias()).toAbsoluteURI();
    		}
    		return this.links.createPageRenderLinkWithContext("").toAbsoluteURI();
    	}
    
    	private <E> List<Result> transform(final List<E> search, final String groupName) {
    		final ArrayList<Result> res = new ArrayList<Result>();
    		if (!search.isEmpty()) {
    			final String group = this.messages.get(groupName);
    			res.add(new Result(group));
    			for (final E item : search) {
    				res.add(new Result(group, this.toTitle(item), this.toUrl(item)));
    			}
    		}
    		return res;
    	}

    DRY in Action.
    мое домашнее творчество.

    Lure Of Chaos, 06 Июня 2013

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

    +152

    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
    function CreatePriceListArray($result_array)//TODO:Формирует древовидную форму прайс листа
    {
    		//print_r($result_array);
        $price_list=array();//Жилая недвижимость
        $current_object_name="";
        $current_section_name="none";
        $current_section_id=0;
        $current_object_array=null;
        $current_section_array=null;
        $current_kvartira_type=null;
        $current_kvartira_type_name="";
        $current_kvartira=null;
        $current_kvartira_area="";
        
        foreach($result_array as $value)
        {
            if($current_object_name != $value['object'])
            {
                if($current_object_array !=null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                    $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
                }
                $current_object_array=array();
                $current_object_name=$value['object'];
                $current_section_name="none";
                $current_section_id=0;
                $current_section_array=null;
            }
    
            if($current_section_name != $value['section_name'])
            {
                   // echo $current_kvartira_type['name']; echo ' | ';
                //if($current_kvartira_type['name'] != '') 
                {
                    
                    foreach ($current_kvartira_type as $value)
                    
                    //print_r($current_kvartira_type);
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);                
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                }
                $current_section_array=array();
                $current_section_name = $value['section_name'];
                $current_section_id=$value['section_id'];
               // $current_kvartira_type=null;
                $current_kvartira_type_name="";
            }
    
            if($current_kvartira_type_name != $value['kvartira_name'])
            {
               // if($current_kvartira_type != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                }
                $current_kvartira_type=array();
                $current_kvartira_type_name = $value['kvartira_name'];
                $current_kvartira=null;
                $current_kvartira_area="";
            }
    
            if($current_kvartira_area != $value['area'])
            {
               // if($current_kvartira != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                }
                $current_kvartira=array();
                $current_kvartira_area = $value['area'];
            }
            
            $current_kvartira[]=$value['floor'];
        }
    		
    			
           $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
           $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
           $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
    //echo $current_object_name;        
    if($current_object_name!='') $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
    
    echo '<!--';
    print_r($price_list);
    echo '-->';
        return $price_list;    
    }

    Пытаюсь тут что-то найти... Идет второй час.

    ghz, 04 Июня 2013

    Комментарии (7)
  11. Objective C / Говнокод #13096

    −89

    1. 1
    2. 2
    const char *aPositionCString = [@"a_position" cStringUsingEncoding:NSUTF8StringEncoding];
    GLuint aPosition = glGetAttribLocation(program, aPositionCString);

    Вместо того, чтобы написать так:
    GLuint aPosition = glGetAttribLocation(program, "a_position");

    zummenix, 03 Июня 2013

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