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

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public string ValidationTitle
    {
        get { return this.Title; }
        set { }
    }

    ArtemASP, 03 Марта 2014

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

    +129

    1. 1
    2. 2
    Margin="0"
    mc:Ignorable="d" Margin="0,0,-191,-31" d:DesignHeight="477.612" d:DesignWidth="671.642" >

    Это кусочек XAML (WPF). Даже не знаю что сказать, наверное мысли были такие: "Мне нужно именно туда и именно так"

    Smekalisty, 27 Сентября 2013

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

    +8

    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
    if (dequeueBuffer_) {
        delete dequeueBuffer_;
        dequeueBuffer_ = NULL;
      }
    
      if (enqueueBuffer_) {
        delete enqueueBuffer_;
        enqueueBuffer_ = NULL;
      }
    
      if (readBuff_) {
        delete[] readBuff_;
        readBuff_ = NULL;
      }
    
      if (currentEvent_) {
        delete currentEvent_;
        currentEvent_ = NULL;
      }

    Apache Thrift 0.9.1, made in Facebook
    Код в деструкторе:

    Fogbit, 19 Сентября 2013

    Комментарии (28)
  5. Perl / Говнокод #13665

    −167

    1. 1
    2. 2
    3. 3
    4. 4
    foreach my $ex (@excluded)
    {
            .....
    }

    О чем думал, когда имя переменной давал?

    Alexandris, 25 Августа 2013

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

    +68

    1. 1
    2. 2
    3. 3
    StringBuffer serialNum = new StringBuffer ();
    for (int i = 0; i < 0; i++)
           serialNum = serialNum.append (Byte.toString (serial[ i ]));

    john812, 02 Августа 2013

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var bl = ['Stertor'];
    $('li.hentry').each(function(){
        var elem = $(this),
            against = elem.find('p.vote > a.vote-against'),
            who = elem.find('p.author a:nth-child(2)').text();
        if(bl.indexOf(who) != -1) {
            if(against.length) against.click();
            elem.hide();
        }
    });

    "не поленись, пройдись по всем постам, и поставь каждому участнику по минусу;"
    Like this?

    russling, 11 Июля 2013

    Комментарии (28)
  8. C++ / Говнокод #13224

    +34

    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
    class A
    {
    public:
        unsigned int m_value;
    
        inline bool operator != ( const A & value )
        {
            unsigned int temp;
            temp = 0 != ( m_value != value.m_value );
            return 0 == temp;
        }
    
        inline bool operator == ( const A & value )
        {
            unsigned int temp;
            temp = 0 != ( m_value == value.m_value );
            return 0 != temp;
        }
    };

    Фрагмент кода одной коммерческой библиотеки. Имя класса изменено, 100500 прочих методов вырезано, но они похожи на эти.
    Я не буду акцентировать внимание на том, что операторы невозможно использовать для константных объектов, даже не буду говорить о странном способе сравнения целых чисел... Но я упомяну о том, что 'operator !=' работает немножко не так, как руссо-индусы ожидали.

    Little-Horny, 24 Июня 2013

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

    +12

    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
    namespace predicate {
    
    using ...;
    
    typedef boost::function<bool (const object &obj)> bool_func;
    typedef boost::function<int (const object &obj)> int_func;
    
    // ... скучные реализации операторов ...
    
    template <class I, class S> struct predicate_grammar :
        qi::grammar<I, bool_func(), S>
    {
        predicate_grammar() : predicate_grammar::base_type(bool_expr)
        {
            identifier = char_("a-z") >> *(char_("a-z_0-9"));
            bool_prop = identifier [ _val = bind(&make_bool_prop_reader, _1, _pass) ];
            bool_expr = (bool_expr2 >> "||" >> bool_expr) [ _val = bind(&make_logic_op, &op_or, _1, _2) ]
                      | bool_expr2 [ _val = _1 ];
            bool_expr2 = (bool_expr3 >> "&&" >> bool_expr2) [ _val = bind(&make_logic_op, &op_and, _1, _2) ]
                       | bool_expr3 [ _val = _1 ];
            bool_expr3 = ('(' >> bool_expr >> ')') [ _val = _1 ]
                       | ('!' >> bool_expr3) [ _val = bind(&make_not, _1) ]
                       | int_comp [ _val = _1 ]
                       | bool_prop [ _val = _1];
            int_comp = (int_expr >> "<" >> int_expr) [ _val = bind(&make_cmp_op, &op_less, _1, _2) ]
                     | (int_expr >> "<=" >> int_expr) [ _val = bind(&make_cmp_op, &op_less_eq, _1, _2) ]
                     | (int_expr >> ">" >> int_expr) [ _val = bind(&make_cmp_op, &op_greater, _1, _2) ]
                     | (int_expr >> ">=" >> int_expr) [ _val = bind(&make_cmp_op, &op_greater_eq, _1, _2) ]
                     | (int_expr >> "==" >> int_expr) [ _val = bind(&make_cmp_op, &op_eq, _1, _2) ]
                     | (int_expr >> "!=" >> int_expr) [ _val = bind(&make_cmp_op, &op_not_eq, _1, _2) ];
            int_expr = int_prop [ _val = _1 ]
                     | int_const [ _val = bind(&make_int_const, _1) ];
            int_const = int_ [ _val = _1 ];
            int_prop = identifier [ _val = bind(&make_int_prop_reader, _1, _pass) ];
        }
    
        qi::rule<I, std::string(), S> identifier;
        qi::rule<I, int(), S> int_const;
        qi::rule<I, int_func(), S> int_expr, int_prop;
        qi::rule<I, bool_func(), S> bool_expr, bool_expr2, bool_expr3, int_comp, bool_prop;
    };
    
    boost::function<bool (const object &)> parse(const std::string &src) {
        if (src.empty())
            return make_bool_const(true);
        bool_func p;
        std::string::const_iterator b = src.begin(), e = src.end();
        predicate_grammar<std::string::const_iterator, boost::spirit::ascii::space_type> grammar;
        if (!phrase_parse(b, e, grammar, boost::spirit::ascii::space, p) || b != e) {
            std::stringstream s;
            s << "Predicate parsing failed at " << (b - src.begin()) << " in \"" << src << "\"";
            throw std::runtime_error(s.str());
        }
        return p;
    }

    Обещанный в http://govnokod.ru/12936#comment175980 говнокодец с использованием бусто-духа.

    bormand, 26 Апреля 2013

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

    +143

    1. 1
    2. 2
    3. 3
    $('table.list th').each(function () {
    			$(this).attr('class', $('> div', this).remove().text()); // хе-хе
    		});

    берем див на первом уровне, удаляем его, читаем с него текст (работает, не ругайтесь) и подставляем его в класс текущему элементу

    Serabas, 08 Апреля 2013

    Комментарии (28)
  11. PHP / Говнокод #12719

    +153

    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
    $statement = $pdo->prepare(
         "if not exists
          (select daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability_rules
          where
            (daily_serving_start = :start0 or
             (daily_serving_start is null and :start1 is null)) and
            (daily_serving_end = :end0 or
             (daily_serving_end is null and :end1 is null)) and
            (weekly_service_off = :weekly0 or
             (weekly_service_off is null and :weekly1 is null)) and
            (one_time_service_off = :once0 or
             (one_time_service_off is null and :once1 is null)))
          begin
            insert into menu_availability_rules
             (daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:start2, :end2, :weekly2, :once2)
          end
    
          if not exists
          (select menu_id, daily_serving_start, daily_serving_end,
                  weekly_service_off, one_time_service_off
          from menu_availability
          where
           menu_id = :menu_id0 and
           (daily_serving_start = :start3 or
             (daily_serving_start is null and :start4 is null)) and
            (daily_serving_end = :end3 or
             (daily_serving_end is null and :end4 is null)) and
            (weekly_service_off = :weekly3 or
             (weekly_service_off is null and :weekly4 is null)) and
            (one_time_service_off = :once3 or
             (one_time_service_off is null and :once4 is null)))
          begin
            insert into menu_availability
             (menu_id, daily_serving_start, daily_serving_end,
              weekly_service_off, one_time_service_off)
            values (:menu_id1, :start5, :end5, :weekly5, :once5)
          end");

    Мое :( А что делать?

    wvxvw, 10 Марта 2013

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