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

    В номинации:
    За время:
  2. Куча / Говнокод #20128

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    //Сегодня у меня вопрос по говнокоду.
    //Как у нас на говнокодике реализовано сколько непросмотренных комментариев в каждом треде?
    //Неужели на каждого юзера заводится счётчик и инкрементится при добавлении в каждой теме?
    //Неужели на каждого юзера на каждый комментарий заводится флаг, сообщающий какой комментарий прочитан, а какой нет?

    LispGovno, 03 Июня 2016

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    template<typename T>
    T gcd(T a, T b) {
    #pragma python(gcd)
        while b != 0:
            a, b = b, a % b
        return a
    }

    всех с праздником, посоны
    http://codeforces.com/blog/entry/44124

    3_dar, 01 Апреля 2016

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

    +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
    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
    template <size_t capacity, bool is_signed>
    class fixed_int
    {	
        // Описание ошибки компиляции в случае использования не поддерживаемой размерности 
        template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
        template <> struct unsupported_capacity<1> {};
        template <> struct unsupported_capacity<2> {};
        template <> struct unsupported_capacity<4> {};
        template <> struct unsupported_capacity<8> {};
    
        // Свойства базовых типов, необходимые для перебора
        template<typename type> struct type_traits;
        template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
        template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
        template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
        template<> struct type_traits <unsigned long> {	typedef unsigned long current_type; typedef unsigned long long next_type; };
        template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type;  typedef unsupported_capacity<capacity> next_type; };
        template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
        template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
        template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
        template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
        template<> struct type_traits <long long int> { typedef long long int current_type;  typedef unsupported_capacity<capacity> next_type;};
    
        // Алгоритм выбора типа
        template<typename type, bool> 
        struct type_choice 
        { 
            typedef typename type_traits<type>::current_type std_type; 
        };
        template<typename type> 
        struct type_choice<type, false> 
        { 
            typedef typename type_traits<type>::next_type next_type; 
            typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type; 
        };
    
        // Базовый тип для начала подбора
        template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
        template <> struct base_type_selector<false> { typedef unsigned char base_type; };
    
    public:
    
        typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
    
    };

    "Зачем мне нужен stdint.h?
    У меня нет времени, чтобы ебаться с ним!
    Лучше я высру ещё десяток-другой шаблонов!"
    https://habrahabr.ru/post/280542/

    PS,
    Пятая строка - вообще угар.

    gost, 31 Марта 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    const int MOD = 1000000007;
    
    int pow(int a, int b) {
    	if (!b) return 1;
    	if (b & 1) return (pow(a, b - 1) * 1LL * a) % MOD;
    	return pow((a * 1LL * a) % MOD, b / 2);
    }

    http://ideone.com/JlfNxZ

    Там ещё куча всякого говна есть
    http://acm.math.spbu.ru/~kunyavskiy/cpp/

    3_dar, 08 Марта 2016

    Комментарии (38)
  6. Assembler / Говнокод #19395

    +76

    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
    .global	shit
    	.type	shit, @function
    shit:
    /* prologue: function */
    /* frame size = 0 */
    /* stack size = 0 */
    .L__stack_usage = 0
    	mov r30,r24
    	mov r31,r25
    	ldd r18,Z+1
    	ldd r22,Z+2
    	mov r24,r22
    	ldi r25,0
    	ldi r26,0
    	ldi r27,0
    	mov r26,r24
    	mov r27,r25
    	clr r25
    	clr r24
    	or r25,r18
    	ld r18,Z
    	or r24,r18
    	ldd r18,Z+3
    	mov r22,r24
    	mov r23,r25
    	mov r24,r26
    	mov r25,r27
    	or r25,r18
    	ret
    	.size	shit, .-shit

    Вот такое ГЛОБАЛЬНОЕ ГОВНО мне делает GCC под AVR
    Код разворота байтиков:

    unsigned long int shit(unsigned char *a)
    {
    return
    ( unsigned long int)a[0] << 0 |
    ((unsigned long int)a[1] << 8 ) |
    ((unsigned long int)a[2] << 16) |
    ((unsigned long int)a[3] << 24);
    }

    Вот другие попытки это сделать, чтоб компилятор сделал более оптимально http://goo.gl/3D2Lri - ссылка на gcc.godbolt.org

    У меня есть собранный через crosstools-ng более новый gcc под AVR, вот выхлоп с него для тех же примеров, что и в godbolt https://paste.debian.net/378491/

    Там __builtin_bswap32() становится rcall __bswapsi2, но этот __bswapsi2 состоит из двух сраных инструкций
    gcc/libgcc/config/avr/lib1funcs.S
    #if defined (L_bswapsi2)
    ;; swap bytes
    ;; r25:r22 = bswap32 (r25:r22)
    DEFUN __bswapsi2
    bswap r22, r25
    bswap r23, r24
    ret
    ENDF __bswapsi2
    #endif /* defined (L_bswapsi2) */

    ТАК ПОЧЕМУ Б ТУПО НЕ ЗАИНЛАЙНИТЬ ЭТО?

    j123123, 04 Февраля 2016

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int main () {
      constexpr int a = f ();
      constexpr int b = f ();
    
      static_assert (a != b, "fail");
    }

    Можно ли это успешно скомпилировать?
    http://b.atch.se/posts/non-constant-constant-expressions/
    Можно, лал.

    LispGovno, 29 Апреля 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #include <stdio.h>
    int main () {
    char c;
    int result=0;
    while(scanf("%c",&c) ) {
    if( (c<'0') || (c > '1') ) break;
    result«=1;
    result+=c-'0';
    };
    printf("%d",result);
    return 0;
    }

    Этот код переводит число из двоичной системы в десятичную. Зачем-то основано на работе с символами.

    alexmir, 29 Января 2015

    Комментарии (38)
  9. PHP / Говнокод #17413

    +155

    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
    <?php
    
    function load ($file) {
    	static $files = null;
    	$files or $files = [];
    	
    	if (!isset($files[$file])) {
    		require($file);
    		$files[$file] = true;
    	}
    }
    
    $times = 1000000;
    $time1 = microtime(true);
    
    for ($i = 0; $i < $times; $i ++) {
    	require_once('inc.php');
    }
    
    $end1 = microtime(true) - $time1;
    
    $time2 = microtime(true);
    
    for ($i = 0; $i < $times; $i ++) {
    	load('inc.php');
    }
    
    $end2 = microtime(true) - $time2;
    
    echo "require_once = $end1 vs \nload = $end2";

    Вот это да... require_once работает в ~8 раз медленнее чем функция load. Вывод:
    require_once = 16.962311029434 vs
    load = 2.6861710548401

    Содежания файла inc.php:

    <?php echo 'Hello, world!';

    volter9, 06 Января 2015

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

    +52

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int QTabBarPrivate::indexAtPos(const QPoint &p) const
    {
        Q_Q(const QTabBar);
        if (q->tabRect(currentIndex).contains(p))
            return currentIndex;
        for (int i = 0; i < tabList.count(); ++i)
            if (tabList.at(i).enabled && q->tabRect(i).contains(p))
                return i;
        return -1;
    }

    currentIndex - видимо откат заплатил

    PS
    Cкоро всю Qt на говнокод заливать придется.
    Плохое настроение или хотите поржать - открывайте исходники Qt в случайном месте - поднимаете себе настроение идиотскими решениями - профит

    fsmoke, 23 Ноября 2014

    Комментарии (38)
  11. Си / Говнокод #17096

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static enum rc (*request_functions[])(void) = {
        ko,
        koko,
        kokoko,
        illegal_request
    };
    static inline enum rc illegal_request(void) { return ILLEGAL_REQUEST; }
    
    reply.rc = request_functions[cmd.opcode < NKEYS(request_functions) ? cmd.opcode : ILLEGAL_REQUEST]();

    Вызываем функцию по опкоду с абортом в случае index_out_of_bounds.

    codemonkey, 12 Ноября 2014

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