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

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

    +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
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    static inline void set0b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] &= ~(1ULL << (at % 64));
    }
    
    static inline  void set1b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] |= 1ULL << (at % 64);
    }
    
    static inline void inv_b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] ^= 1ULL << (at % 64);
    }
    
    
    static inline uint8_t find_empt_pos (const uint64_t bm[static 4])
    {
      if (bm[0] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[0]) + 64 * 0;  // __builtin_ctzll - https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
      }
      if (bm[1] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[1]) + 64 * 1;
      }
      if (bm[2] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[2]) + 64 * 2;
      }
      if (bm[3] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[3]) + 64 * 3;
      }
      fprintf(stderr, "ERROR! No empty space!\n");
      exit (-1);
    }
    
    static inline uint8_t allocate_ll (uint64_t bm[static 4])
    {
      uint8_t tmp = find_empt_pos (bm);
      set1b (tmp, bm);
      return tmp;
    }
    
    static inline void inject(const uint8_t prev_p, const uint8_t next_p, const uint8_t at, struct ll_data a[static 256])
    {
      a[next_p].ll.prev = at;
      a[prev_p].ll.next = at;
    
      a[at].ll.prev = prev_p;
      a[at].ll.next = next_p;
    }
    
    static inline void remove_betw(const uint8_t prev_p, const uint8_t next_p, struct ll_data a[static 256])
    {
      a[prev_p].ll.next = next_p;
      a[next_p].ll.prev = prev_p;
    }
    
    static inline void remove_at(const uint8_t at, struct ll_data a[static 256], uint64_t bm[static 4])
    {
      uint8_t prev_t = a[at].ll.prev;
      uint8_t next_t = a[at].ll.next;
    
      set0b (at, bm);
    
      a[at].ll.prev = next_t;
      a[at].ll.next = prev_t;
    }
    
    
    void add_elem_next (struct ll_all *a, const uint8_t elm, const int value)
    {
      uint8_t pos = allocate_ll (a->bm);
      inject(elm, a->arr[elm].ll.next, pos, a->arr);
      set_elm (pos, value, a->arr);
    }
    
    void add_elem_prev (struct ll_all *a, const uint8_t elm, const int value)
    {
      uint8_t pos = allocate_ll (a->bm);
      inject(a->arr[elm].ll.prev, elm, pos, a->arr);
      a->arr[pos].data = value;
    }
    
    void rem_elem_next (struct ll_all *a, const uint8_t elm)
    {
      set0b (a->arr[elm].ll.next, a->bm);
      remove_betw (elm, a->arr[a->arr[elm].ll.next].ll.next, a->arr);
    }
    
    void rem_elem_prev (struct ll_all *a, const uint8_t elm)
    {
      set0b (a->arr[elm].ll.next, a->bm);
      remove_betw (a->arr[a->arr[elm].ll.prev].ll.prev, elm, a->arr);
    }

    Тру-царская неанскилльная реализация двусвязного списка внутри массива.
    К сожалению, весь код не помещается, см https://wandbox.org/permlink/Ky8fnuqyE0Ahxftm

    j123123, 18 Августа 2017

    Комментарии (37)
  3. Perl / Говнокод #23249

    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
    21. 21
    22. 22
    if ( $MonitorMode eq \">=\" )
    {
      if ( $NbrProcesses < $ProcNumber )
      {
        $Rule->Status(TRUE);
      }
    }
    elsif ( $MonitorMode eq \"<=\" )
    {
      if ( $NbrProcesses > $ProcNumber )
      {
        $Rule->Status(TRUE);
      }
    }
    else
    {
      if ( $NbrProcesses != $ProcNumber )
      {
        $Session->Value(\"PROCESSMODE\", \"\" );
        $Rule->Status(TRUE);
      }
    };

    Кровавый ентерпрайз. Кусок кода мейд бай ХулетПакард

    rjhdby, 09 Августа 2017

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

    +103

    1. 1
    http://we.easyelectronics.ru/uploads/images/00/40/39/2016/05/16/ad076cf168.jpg

    HaskellGovno, 06 Августа 2016

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

    +9

    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
    int naive_show_int(int x) {
        char buf[32];
        char *p = buf + sizeof(buf);
        *--p = 0;
        int negative = 0;
        if (x < 0) {
            x = -x;
            negative = 1;
        }
        while (x > 0) {
            if (x <= 0)
                return -1;
            int digit = '0' + x % 10;
            if (digit < '0' || digit >= '9')
                return -1;
            *--p = digit;
            x /= 10;
        }
        if (negative)
            *--p = '-';
        puts(p);
        return 0;
    }

    Допустишь один UB - ничто уже не спасёт твою прогу...

    http://ideone.com/EFGoBi

    bormand, 02 Февраля 2016

    Комментарии (37)
  6. JavaScript / Говнокод #19294

    +1

    1. 1
    2. 2
    3. 3
    while ((math == (math = Math)).toString() == "true") {
       ...
    }

    программист-дотер

    mikamika83, 12 Января 2016

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

    −74

    1. 1
    2. 2
    3. 3
    4. 4
    def foreigned(to_db='default', in_db="operator_main_dbs"):
        u""" декоратор для foreign tables """
        
        assert to_db == 'default' and in_db == "operator_main_dbs"

    Вариативность

    parabellum, 30 Июля 2015

    Комментарии (37)
  8. Java / Говнокод #18055

    +144

    1. 1
    Шёл 2015 год, а SQLite на ведре так и не научился сравнивать не ASCII'шные строки без учёта регистра...

    Или это у меня руки из жопы растут?

    bormand, 24 Апреля 2015

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

    +43

    1. 1
    2. 2
    3. 3
    for each (ToolStripMenuItem ^item in пользователиToolStripMenuItem->DropDownItems) {
    	item->Enabled = true;
    }

    Это C++, и это работает!

    hdkeeper, 22 Октября 2014

    Комментарии (37)
  10. Куча / Говнокод #16802

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
    
    VAR = MixedCaseText
    LOWER_VAR = $(call lc,$(VAR))
    
    all:
            @echo $(VAR)
            @echo $(LOWER_VAR)

    как реализовать портабельно lowercase функцию в GNU Make.

    как же я тебя временами лублу, мэйк.

    ЗЫ было случайно найдено в http://stackoverflow.com/questions/664601/in-gnu-make-how-do-i-convert-a-variable-to-lower-case

    Dummy00001, 06 Октября 2014

    Комментарии (37)
  11. ActionScript / Говнокод #16640

    −92

    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
    public class MathAndGeometryUtils
    {
    	public static function roundToHalf(value:Number):Number 
    	{
    		var multiplied:int = Math.round(value * 10);
    		if (multiplied / 5 == Math.round(multiplied / 5))
    		{
    			return multiplied / 10;
    		}
    		else
    		{
    			var noComma:Number = Math.floor(multiplied / 10) * 10;
    			var divaider:int = multiplied - noComma;
    			if (divaider >= 3 && divaider <= 7)
    				return (noComma + 5) / 10;
    			else
    				return Math.round(value);
    		}
    	}
    }

    На сколько я смог понять задумку, человеку хотелось чтобы функция возвращала значения типа 0, 0.5, 1, 1.5 и т.д. и вот он придумал такое самобытное решение.

    wvxvw, 04 Сентября 2014

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