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

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

    +133

    1. 1
    return Training.ContainsKey(typeof(unit)) ? true : false;

    А я ведь говорил ему не рефакторить на ночь глядя.

    RaZeR, 13 Июня 2013

    Комментарии (21)
  3. PHP / Говнокод #13081

    +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
    if (!$left || !$right) return true;
            $sql = "DELETE FROM {$this->_tableName} WHERE `user_id`=$user_id";
            $this->_db->exec($sql);
    
            if (!$this->_isTriggers) {
                if (($right - $left) == 1) {
                    $sql = "UPDATE {$this->_tableName} SET `left`=IF(`left` >= $left,`left`-2,`left`),`right`=`right`-2 WHERE `right` >= $left";
                } else {
                    $sql = "UPDATE {$this->_tableName} SET 
                    `left`=IF(`left` BETWEEN $left AND $right,`left`-1,`left`),
                    `right`=IF(`right` BETWEEN $left AND $right,`right`-1,`right`),
                    `level`=IF(`left` BETWEEN $left AND $right,`level`-1,`level`),
                    `left`=IF(`left`>$right,`left`-2,`left`),
                    `right`=IF(`right`>$right,`right`-2,`right`)
    		WHERE `right` > $left
                    ";
                }
                $this->_db->exec($sql);

    Только ручной сбор запроса. Zend Db

    coderxlsn, 30 Мая 2013

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static bool isLaterThan()
    {
      string hd = DateTime.Now.ToString("tt", new CultureInfo("en-US")).ToLower();
    
      if (hd == "pm")
       return false;
    
       return DateTime.Now.Hour < 1;
    }

    уже есть час ночи?

    taburetka, 30 Мая 2013

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

    +138

    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
    // Преобразует BCD формат в число
    private static int BCDToInt(byte bIn)
    {
        return ((((bIn / 0x10) * 10) + bIn) - ((bIn / 0x10) * 0x10));
    }
    
    // Преобразует число в BCD формат
    private static byte IntToBCD(int value)
    {
        value -= (value / 100) * 100;
        byte bTH = (byte)(value / 10);
        byte bTL = (byte)(value - (bTH * 10));
        return (byte)(bTL + ((byte)(bTH << 4)));
    }

    навеяло сложными запутывающими большими и маленькими индейцами для элитных программистов

    референс-код от партнеров для конверсии binary-coded decimal вперёд и взад
    чтобы как бы верно срослось между ихним с# и нашим сраным с++

    defecate-plusplus, 29 Мая 2013

    Комментарии (21)
  6. ActionScript / Говнокод #12985

    −163

    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
    public function algorithmChanged(arg1:flash.events.Event):*
            {
                var loc1:*;
                loc1 = null;
                if (currentAlgorithm != null)
                    removeChild(currentAlgorithm);
                loc1 = arg1.target.selectedLabel;
                currentAlgorithm = null;
                animationManager.resetAll();
                if (loc1 != "Heap")
                    if (loc1 != "Comparison Sort")
                        if (loc1 != "Counting Sort")
                            if (loc1 != "Bucket Sort")
                                if (loc1 != "Radix Sort")
                                    if (loc1 != "Heap Sort")
                                        if (loc1 != "Binary Search Tree")
                                            if (loc1 != "AVL Tree")
                                                if (loc1 != "Open Hashing")
                                                    if (loc1 != "Closed Hashing")
                                                        if (loc1 != "Graph")
                                                            if (loc1 != "DFS")
                                                                if (loc1 != "BFS")
                                                                    if (loc1 != "Connected Components")
                                                                        if (loc1 != "Dijkstra")
                                                                            if (loc1 != "Prim")
                                                                                if (loc1 != "Kruskal")
                                                                                    if (loc1 != "Topological Sort")
                                                                                        if (loc1 != "Floyd-Warshall")
                                                                                            if (loc1 != "B Tree")
                                                                                                if (loc1 != "Binomial Queue")
                                                                                                    if (loc1 != "Disjoint Sets")
                                                                                                        if (loc1 != "Array Stack")
                                                                                                            if (loc1 != "Array Queue")
                                                                                                                if (loc1 != "Linked List Stack")
                                                                                                                    if (loc1 != "Linked List Queue")
                                                                                                                        if (loc1 != "Red Black Tree")
                                                                                                                            if (loc1 != "Closed Hashing (buckets)")
                                                                                                                                if (loc1 == "B+ Tree")
                                                                                                                                {
                                                                                                                                    currentAlgorithm = new BPlusTree(animationManager);
                                                                                                                                    addChildAt(currentAlgorithm, 0);
                                                                                                                                }
                                                                                                                            else 
                                                                                                                            {
                                                                                                                                currentAlgorithm = new ClosedHash2(animationManager);
                                                                                                                                addChildAt(currentAlgorithm, 0);
                                                                                                                            }
                                                                                                                        else 
                                                                                                                        {
                                                                                                                            currentAlgorithm = new RedBlackTree(animationManager);
                                                                                                                            addChildAt(currentAlgorithm, 0);
                                                                                                                        }
    и т.д. пока не закроются все if'ы

    Визуализатор сортировок университета Сан-Франциско

    alexprey, 12 Мая 2013

    Комментарии (21)
  7. Objective C / Говнокод #12879

    −113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ([_categories count] != 0) {
        for (NSString *item in _categories) {
            [path appendFormat:@"categories/%@/", item];
        }
    }

    Случайно обнаружил у себя :)

    zummenix, 10 Апреля 2013

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

    +36

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #include <iostream>
    int main() 
    { 
        system("calc"); 
    }

    Калькулятор на C++? Да пожалуйста.

    zebraplus, 16 Февраля 2013

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

    +24

    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
    template <typename IdType, class Tag>
    class id {
    public:
        typedef IdType value_type;
    
        explicit id(value_type val)
            : value(val)
        {}
    
        bool operator==(id rhs)
        {
            return rhs.value == value;
        }
    
        bool operator!=(id rhs)
        {
            return rhs.value != value;
        }
    
        value_type value;
    };
    
    #define HASKELL_NEWTYPE(type_name, value_type) struct __##type_name##_tag__ {}; \
        typedef ::id<value_type, __##type_name##_tag__> type_name

    Когда newtype нет, но очень хочется.
    http://ideone.com/VRu56j
    Простите за синтетику

    roman-kashitsyn, 14 Февраля 2013

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

    +15

    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
    /**
     * @brief Serializer generic interface.
     */
    template<typename ValueType>
    struct serializer
    {
        /**
         * @brief Parses value from raw bytes.
         * @param  from byte buffer parse value from
         */
        static ValueType parse(uint8_t *from);
    
        /**
         * @brief Writes value to raw byte buffer.
         * @param  value value to write
         * @param  dest destination buffer
         */
        static void write(ValueType value, uint8_t *dest);
    };
    
    template<>
    struct serializer<uint8_t>
    {
        static uint8_t parse(uint8_t *from)
        {
            return *from;
        }
        static void write(const uint8_t value, uint8_t *to)
        {
            *to = value;
        }
    };
    
    template<>
    struct serializer<uint16_t>
    {
        static uint16_t parse(uint8_t *from)
        {
            return (uint16_t)from[0] << 8 | from[1];
        }
        static void write(const uint16_t value, uint8_t *to)
        {
            to[0] = (value >> 8);
            to[1] = value & 0xff;
        }
    };
    
    template<>
    struct serializer<uint32_t>
    {
        static uint32_t parse(uint8_t *from)
        {
            return from[0] << 24 | from[1] << 16 | from[2] << 8 | from[3];
        }
        static void write(const uint32_t value, uint8_t *to)
        {
            serializer<uint16_t>::write(value >> 16, to);
            serializer<uint16_t>::write(value & 0xffff, to + 2);
        }
    };
    
    template<>
    struct serializer<uint64_t>
    {
        static uint64_t parse(uint8_t *from)
        {
            const uint32_t high = serializer<uint32_t>::parse(from);
            const uint32_t low = serializer<uint32_t>::parse(from + 4);
            return ((uint64_t) high << 32) | low;
        }
        static void write(const uint64_t value, uint8_t *to)
        {
            serializer<uint32_t>::write(value >> 32, to);
            serializer<uint32_t>::write(value & 0xffffffff, to + 4);
        }
    };

    Тут поднялась тема неуместного битолюбства... Решил поделиться одним из моих первых крестОпусов.
    "кроссплатформенный hton(sl)".

    roman-kashitsyn, 22 Января 2013

    Комментарии (21)
  11. PHP / Говнокод #12329

    +43

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function Podergatsya($i)
    {
    	$i++;
    	$i--;
    	return $i;
    }

    Индусская CMS

    kindofbear, 21 Декабря 2012

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