1. Список говнокодов пользователя j123123

    Всего: 331

  2. JavaScript / Говнокод #23701

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    https://github.com/SeleniumHQ/selenium/commit/388793a775aea41533fb5816aabe710e1b42ff61
    
    +        if (Math.random() > 0.8) {
    +            throw new SeleniumError("Selenium 1.0 (Core, RC, etc) is going away; update to WebDriver now.");
    +        }
    +

    j123123, 02 Февраля 2018

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

    0

    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
    /*
     * Returns 1 if filename has .zip extension.
     */
    static int
    str_zipext(char *name)
    {
    	int i;
    
    	i = strlen(name) - 1;
    	if (i < 0 || name[i] != 'p' && name[i] != 'P') return 0;
    	i--;
    	if (i < 0 || name[i] != 'i' && name[i] != 'I') return 0;
    	i--;
    	if (i < 0 || name[i] != 'z' && name[i] != 'Z') return 0;
    	i--;
    	if (i < 0 || name[i] != '.') return 0;
    	i--;
    	if (i < 0) return 0;
    	return 1;
    }

    https://github.com/fabiensanglard/xrick/blob/239d213f01be8d0086c449080ce61bde8dcad7b4/src/data.c#L189

    j123123, 25 Января 2018

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

    +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
    template < typename T >
    T shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
    // Почему дедукция аргумента шаблона в данном случае не работает?
      return crap;
    }
    
    //-------------------------------------
    
    int shit (void)
    {
      return 0;
    }
    
    // Почему functions that differ only in their return type cannot be overloaded 
    double shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
      return crap;
    }

    Почему плюсы такое говно?

    j123123, 22 Января 2018

    Комментарии (59)
  5. C++ / Говнокод #23656

    0

    1. 1
    2. 2
    3. 3
    4. 4
    https://www.reddit.com/r/cpp/comments/75gohf/i_just_found_a_use_for_the_poop_emoji_in_c/
    запостить этот говнокод непосредственно сюда не представляется возможным из-за юникодного символа говна:
    Application was halted by an exception.
    Debug-mode is off.

    I just found a use for the poop emoji in C++
    This actually detects whether the Visual Studio project has the proper UTF-8 flags set to compile it correctly.

    j123123, 16 Января 2018

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

    0

    1. 1
    http://shitcode.net/

    У говнокода появился конкурент

    j123123, 15 Декабря 2017

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

    +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
    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
    #include <experimental/coroutine>
    #include <iostream>
    #include <optional>
    #include <utility>
    
    template<typename T>
    class Maybe
    {
        std::shared_ptr<std::optional<T>> m_maybe = std::make_shared<std::optional<T>>();
    public:
        Maybe() = default;
        
        Maybe(const T& t)
        : m_maybe { std::make_shared<std::optional<T>>(t) }
        {
        }
    
        explicit operator bool() const { return static_cast<bool>(*m_maybe); }
        T& operator* () { return **m_maybe; }
        const T& operator*() const { return **m_maybe; }
        
        void reset() { m_maybe->reset(); }
        
        template<typename U>
        void emplace(U&& u) { m_maybe->emplace(std::forward<U>(u)); }
    };
    
    template<typename T>
    void printMaybe(const Maybe<T>& opt)
    {
        if (opt)
            std::cout << *opt << std::endl;
        else
            std::cout << "<empty>" << std::endl;
    }
    
    template<typename T, typename... Args>
    struct std::experimental::coroutine_traits<Maybe<T>, Args...>
    {
        struct promise_type
        {
            Maybe<T> m_maybe;
            
            auto get_return_object() { return m_maybe; }
            
            std::experimental::suspend_never initial_suspend() { return {}; }
            std::experimental::suspend_never final_suspend() { return {}; }
            
            void unhandled_exception() { m_maybe.reset(); }
            
            template<typename U>
            void return_value(U&& u) { m_maybe.emplace(std::forward<U>(u)); }
        };
    };
    
    template<typename T>
    auto operator co_await(const Maybe<T>& maybe)
    {
        struct Awaiter
        {
            const Maybe<T>& input;
    
            bool await_ready() { return static_cast<bool>(input); }
            auto await_resume() { return *input; }
            void await_suspend(std::experimental::coroutine_handle<> coro) { coro.destroy(); }
        };
    
        return Awaiter { maybe };
    }
    
    Maybe<int> maybeAdd(const Maybe<int>& maybeA, const Maybe<int>& maybeB)
    {
        auto a = co_await maybeA;
        auto b = co_await maybeB;
        co_return a + b;
    }
    
    int main()
    {
      /*
        printMaybe(maybeAdd({ 1 }, { 2 }));
        printMaybe(maybeAdd({}, { 2 }));
        printMaybe(maybeAdd({ 1 }, {}));
        */
        const auto res = maybeAdd({ 1 }, { 2 });
        return res ? *res : 0;
    }

    do-нотация в плюсах

    j123123, 07 Декабря 2017

    Комментарии (85)
  8. Си / Говнокод #23566

    −2

    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
    #define POLY 0x8408
    /*
    //                                      16   12   5
    // this is the CCITT CRC 16 polynomial X  + X  + X  + 1.
    // This works out to be 0x1021, but the way the algorithm works
    // lets us use 0x8408 (the reverse of the bit pattern).  The high
    // bit is always assumed to be set, thus we only use 16 bits to
    // represent the 17 bit value.
    */
    
    unsigned short crc16(unsigned char *data_p, size_t length)
    {
      unsigned char i;
      unsigned int data;
    
      if ( length == 0 ) return 0;
      unsigned int crc = 0xFFFF;
      do
      {
        data = *data_p++;
        for ( i=0; i < 8; i++ )
        {
          if ( (crc ^ data) & 1 )
            crc = (crc >> 1) ^ POLY;
          else
            crc >>= 1;
          data >>= 1;
        }
      } while ( --length != 0 );
    
      crc = ~crc;
      data = crc;
      crc = (crc << 8) | ((data >> 8) & 0xff);
      return (unsigned short)(crc);
    }

    Типичный пример непортабельной хуйни на Си.

    j123123, 07 Декабря 2017

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

    +2

    1. 1
    https://shmat-razum.blogspot.com/2012/12/blog-post.html

    Есть такое правило, к которому все привыкли: если в программе записано логическое выражение с and, и первое подвыражение оказалось равно false, то второе не вычисляется. Аналогично с or: если первое подвыражение равно true, второе не вычисляется. Это позволяет удобно записывать вещи вида

    if (index < 0 || array[index] == NULL)
    ...

    или
    if (index >= 0 && array[index] == ptr)
    ...


    Это правило действует во всех широко используемых языках программирования: C/C++, Java, C#, Javascript, Python, а также в многочисленных представителях семейств лиспов и смолтоков. И даже в Хаскеле. И даже в PL/SQL. У правила есть название: закорачивание логических связок (short-circuit evaluation). Казалось, оно само собой разумеется, и есть во всех языках.

    При столкновении с языком Fortran автора ждал сильный удар. Закорачивание в этом языке не просто не действует, а может действовать или не действовать в зависимости от воли компилятора. Эта неопределённость закреплена в стандарте. При этом, в интеловском компиляторе, например, просто нет ключа, чтобы этим управлять. Программист не может быть уверен, что выполнится лишь одна ветвь; в то же время, он не может быть уверен, что выполнятся обе. Поведение может зависеть от номера версии компилятора и настроек оптимизации.

    j123123, 15 Ноября 2017

    Комментарии (29)
  10. C++ / Говнокод #23515

    0

    1. 1
    https://webhamster.ru/mytetrashare/index/mtb0/1480776952mrczr7xk44

    Какие изменения предлагает инициативная группа стандарта C++!!, чтобы сделать язык C++ красивым, мощным и востребованным средством современной разработки?

    j123123, 10 Ноября 2017

    Комментарии (18)
  11. C++ / Говнокод #23498

    +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
    // https://github.com/telegramdesktop/tdesktop/blob/5f5770dd46491133b135a71fc2d4f92d13107ade/Telegram/SourceFiles/history.cpp#L1455
    
    int History::countUnread(MsgId upTo) {
    	int result = 0;
    	for (auto i = blocks.cend(), e = blocks.cbegin(); i != e;) {
    		--i;
    		for (auto j = (*i)->items.cend(), en = (*i)->items.cbegin(); j != en;) {
    			--j;
    			if ((*j)->id > 0 && (*j)->id <= upTo) {
    				break;
    			} else if (!(*j)->out() && (*j)->unread() && (*j)->id > upTo) {
    				++result;
    			}
    		}
    	}
    	return result;
    }
    
    void History::updateShowFrom() {
    	if (showFrom) return;
    
    	for (auto i = blocks.cend(); i != blocks.cbegin();) {
    		--i;
    		for (auto j = (*i)->items.cend(); j != (*i)->items.cbegin();) {
    			--j;
    			if ((*j)->id > 0 && (!(*j)->out() || !showFrom)) {
    				if ((*j)->id >= inboxReadBefore) {
    					showFrom = *j;
    				} else {
    					return;
    				}
    			}
    		}
    	}
    }

    очередная порция говнеца из телесрамного клиента

    j123123, 07 Ноября 2017

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