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

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

    +1

    1. 1
    http://pragmaticperl.com/issues/26/pragmaticperl-26-грамматики-в-perl-6.html

    :3
    Где еще такое может быть то?

    OlegUP, 10 Апреля 2019

    Комментарии (10)
  3. Си / Говнокод #25526

    +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
    #include <stdio.h>
    #include <stdlib.h>
    
    void myfree(void *ptr)
    {
      printf("%p\n", *(void **)ptr);
      free(*(void **)ptr);
      printf("freed!\n");
    }
    
    int main(void) {
      char *x __attribute__ (( cleanup (myfree)  )) = malloc(1);
      printf("%p\n", x);
      return 0;
    }

    https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

    cleanup (cleanup_function)

    The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.

    If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally.

    j123123, 09 Апреля 2019

    Комментарии (28)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. Куча / Говнокод #25479

    +1

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

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

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

    syoma, 26 Марта 2019

    Комментарии (23)
  10. 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)
  11. Куча / Говнокод #25462

    +1

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

    gost, 21 Марта 2019

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