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

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    for i in for i in itertools.count():
        # ...
        if i >= x:
            break

    syoma, 08 Апреля 2019

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

    +1

    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
    #include <iostream>
    #include <functional>
    #include <array>
    #include <iterator>
    
    template <class T>
    class Filter : public std::iterator<
                     std::input_iterator_tag,
                     typename std::iterator_traits<T>::value_type,
                     typename std::iterator_traits<T>::difference_type,
                     typename std::iterator_traits<T>::pointer,
                     typename std::iterator_traits<T>::reference
                   >
    {
    private:
      typedef typename std::iterator_traits<T>::value_type value_type;
      std::function<bool(value_type)> m_predicate;
      T m_begin, m_end;
      value_type m_current;
    
    public:
      Filter(T t_begin, T t_end, std::function<bool(value_type)> t_predicate)
        : m_begin(t_begin), m_end(t_end), m_predicate(t_predicate)
      {
      }
      
      Filter<T>& begin()
      {
        return ++*this;
      }
      
      Filter<T>& end()
      {
        return *this;
      }
      
      value_type operator* ()
      {
        return m_current;
      }
      
      Filter<T>& operator++ ()
      {
        do {
          m_current = *m_begin;
          ++m_begin;
        } while (m_begin != m_end && !m_predicate(m_current));
        return *this;
      }
      
      
      bool operator!= (Filter<T>& t_right)
      {
        return m_begin != t_right.m_end;
      }
    };
    
    
    int main()
    {
      std::array<int, 10> arr{ {4, 35, 0, 23, 0, 0, 5} };
      for (auto i : Filter<typename std::array<int,10>::iterator>(arr.begin(), arr.end(), [](int x){return x != 0;})) {
        std::cout << i << " ";
      }
    }

    Lemming, 07 Апреля 2019

    Комментарии (63)
  4. PHP / Говнокод #25516

    +1

    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
    function getCartMiniViewDisplayString($cart_entries) {
        $count = $cart_entries->getProductCount();
        $suffix = "";
        $remainder = $count % 10;
        switch($remainder) {
            case 1:
                $suffix = " товар";
                break;
            case 2:
            case 3:
            case 4:
                $suffix = " товара";
                break;
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 0:
                $suffix = " товаров";
                break;
        }
        return $count . $suffix;
    }

    Мой, переписывать с if в лень.

    OlegUP, 06 Апреля 2019

    Комментарии (20)
  5. JavaScript / Говнокод #25506

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    else {
            // на всякий случай возвращаем true в случае некоторых экзотических браузеров
            flashinstalled = true;
        }
    return flashinstalled;

    https://csdrop.org/
    main.js
    Просто из за комментария ☺

    GreatMASTERcpp, 04 Апреля 2019

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

    +1

    1. 1
    https://en.cppreference.com/w/cpp/language/lambda

    > Explanation
    > > <tparams>
    > Like in a template declaration, the template parameter list may be followed by an optional requires-clause, which specifies the constraints on the template arguments.
    > optional requires-clause
    небязательные обязательные пункты.

    Переводил почти час.

    OlegUP, 02 Апреля 2019

    Комментарии (26)
  7. Куча / Говнокод #25479

    +1

    1. 1
    Вы такого еще не видали

    https://paste.ubuntu.com/p/gpsMVPnd6T/
    Отформатировано: https://paste.ubuntu.com/p/vF8hCGN6Z3/

    20 уровней индентации, адовый копипаст.

    syoma, 26 Марта 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach ($result->getDataCollection() as $data) {
        if (!$data->getStatus() === Status::PAID)
            continue;
    
        // ACTIONS
    }

    Зачем использовать !== если есть ===

    P/s
    Смотрим на if (

    genkaok, 21 Марта 2019

    Комментарии (4)
  9. Куча / Говнокод #25462

    +1

    1. 1
    2. 2
    3. 3
    Страйкер приде — почту почине!
    
    Грустно без уведомлений из любимой соцсети.

    gost, 21 Марта 2019

    Комментарии (10)
  10. Python / Говнокод #25459

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    with conn:
                cursor = conn.cursor()
                cursor.execute('UPDATE users SET creferals = creferals + 1 WHERE cid = ?', (inviter,))
                cursor.execute('INSERT INTO users VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
                               (datetime.strftime(datetime.now(),"%H:%M:%S %d.%m.%Y"), cid, username, 'main', 0, 0, 0, 0, 0, 0, 0, inviter, 'RUS'))
    conn.commit()

    Aristokraft, 21 Марта 2019

    Комментарии (75)
  11. Куча / Говнокод #25455

    +1

    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
    !DOCTYPE html>
    <html>
    <%c++
        auto para=@@.get<std::map<std::string,std::string>>("parameters");
    %>
    <head>
        <meta charset="UTF-8">
        <title>{{ title }}</title>
    </head>
    <body>
        <%view header %>
        <%c++ if(para.size()>0){%>
        <H1>Parameters</H1>
        <table border="1">
          <tr>
            <th>name</th>
            <th>value</th>
          </tr>
          <%c++ for(auto iter:para){%>
          <tr>
            <td>{%iter.first%}</td>
            <td><%c++ $$<<iter.second;%></td>
          </tr>
          <%c++}%>
        </table>
        <%c++ }else{%>
        <H1>no parameter</H1>
        <%c++}%>
    </body>

    C++ шаблонизатор
    https://github.com/an-tao/drogon/blob/master/examples/simple_example/ListParaView.csp

    HEymHblu_nemyx, 19 Марта 2019

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