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

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

    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
    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
    /*
    https://habr.com/post/246009/
    
    Это вторая статья в цикле «Теория категорий для программистов».
    
    ...
    
    Я хотел бы сказать вам, что есть шаблон в стандартной библиотеке С++,
    который принимает две функции и возвращает их композицию, но такого
    нет.
    
    Примечание переводчика: но такой не сложно написать на С++14 (я опускаю
    тонны деталей владения и шаблонной магии для проверок, что эти функции
    и тип аргумента действительно можно компоновать):
    */
    
    template <typename T>
    struct function_arg: public function_arg<decltype(&T::operator())> {};
    
    template<typename ReturnType, typename Arg>
    struct function_arg<ReturnType(Arg) const> {
    	using type = Arg;
    };
    
    template<typename ClassType, typename ReturnType, typename Arg>
    struct function_arg<ReturnType(ClassType::*)(Arg) const> {
    	using type = Arg;
    };
    
    template<typename T>
    using function_arg_t = typename function_arg<T>::type;
    
    template<typename F, typename G>
    auto compose(F&& f, G&& g) {
    	return [f = std::forward<F>(f), g = std::forward<G>(g)]
    		(function_arg_t<F>&& a) {return g(f(std::forward<function_arg_t<F>>(a)));};
    }

    Поэтому я за C++

    j123123, 22 Октября 2018

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

    −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
    #include <new>
    
    template <typename Lhs, typename Rhs>
    auto replace(Lhs *lhs, Rhs) {
      return *new (reinterpret_cast<void*>(lhs)) Rhs{};
    }
    
    int main() {
      auto f1 = &add;
      auto f2 = replace(add, [](int a, int b) { return a - b; });
    
      f1(4, 2);
      f2(4, 2);
    }

    Компилируется, не падает при запуске.

    Elvenfighter, 16 Октября 2018

    Комментарии (17)
  4. PHP / Говнокод #24921

    −3

    1. 1
    $keys = array_keys(array_flip($keys));

    Малая доля индусского кода

    kgk, 14 Октября 2018

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

    −9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Процедура тпТоварыПриПолученииДанных(Элемент, ОформленияСтрок)
    	Модифицированность_ = Модифицированность;
    	Для Каждого Стр из ОформленияСтрок Цикл
    		Если НЕ Стр.ДанныеСтроки.Вес = 0 И НЕ Стр.ДанныеСтроки.ПроцентУсушки = 0 Тогда			
    			Стр.ДанныеСтроки.Усушка = (Стр.ДанныеСтроки.Вес * Стр.ДанныеСтроки.ПроцентУсушки / 100) * Стр.ДанныеСтроки.Количество;									
    		КонецЕсли;
    	КонецЦикла;
    	Модифицированность = Модифицированность_;
    КонецПроцедуры

    Данные табличной части модифицируются в процедуре ПриПолученииДанных (видимо, лучшего места для этого не нашлось), что закономерно приводит к отложенному на мгновение вызову ПриПолученииДанных ещё раз, и ещё, и так далее. В результате процессор загружается почти на 100%, значок * в заголовке формы дико мерцает.
    Написано программистом с 6-значной ЗП.

    strashny_programmist, 04 Октября 2018

    Комментарии (17)
  6. PHP / Говнокод #24851

    −3

    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
    98. 98
    99. 99
    require_once $_SERVER['DOCUMENT_ROOT'] . '/models/core/class.Application.php';
    require_once 'class.DatabaseConnect.php';
    require_once 'class.DatabaseResult.php';
    
    class DatabaseQuery extends Application {
    
        private $m_db_connect = NULL; //Соединение с БД
        private $m_query_statment = NULL; //Результат последнего запроса
        private $m_construct_query = NULL; //Строка формирования запроса
    
        public function __construct(DatabaseConnect $db_connect) {
            $this->m_db_connect = $db_connect;
        }
        
        public function __destruct() {
            $this->m_db_connect = null;
        }
    
        //Вставляет данные в таблицу
        public function insert($data) {
            if (count($data) === 0)
                return false;
            $query_list = [];
            //Обход таблиц
            foreach ($data as $t_name => $table) {
    
                //Ассациативный массив даннвх, где ключ массива это имя колонки в БД
                $column_list = [];
                //Копируем данные в отдельный массив	
                foreach ($table as $c_name => $column)
                    $column_list[$c_name] = $column;
                //Строка запроса
                $query = "INSERT INTO {$t_name} (" . implode(', ', array_keys($column_list)) . ') VALUES ';
                //Выпоняем обход
                for ($i = 0; $i < count($column_list[array_keys($column_list)[0]]); $i++) {
                    $query_values = '(';
                    //
                    foreach ($column_list as $c_name => $column)
                        $query_values .= '\'' . $column_list[$c_name][$i] . '\',';
    
                    $query_values = chop($query_values, ',') . '),';
                    $query .= $query_values;
                }
                $query_list[] = chop($query, ',');
            }
    
            try {
                for ($i = 0; $i < count($query_list); $i++) {
                    $result = $this->query($query_list[$i]);
                }
            } catch (PDOException $e) {
                Application::handlerErrorDB($e);
                return false;
            }
    
            return true;
        }
    
        public function setSelect($data = ['*']) {
            $query = 'SELECT ';
            foreach ($data as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setDelete($tables = []) {
            $query = 'DELETE ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setUpdate($tables) {
            $query = 'UPDATE ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query = chop($query, ',') . ' ';
            return $this;
        }
    
        public function setSet($data) {
            $query = 'SET ';
            foreach ($data as $k => $v)
                $query .= "$k = '$v',";
            $this->m_construct_query .= chop($query, ',') . ' ';
            return $this;
        }
    
        public function setFrom($tables) {
            $query = 'FROM ';
            foreach ($tables as $v)
                $query .= $v . ',';
            $this->m_construct_query .= chop($query, ',') . ' ';
            return $this;
        }
    
        ...

    Вот что бывает когда у тебя юношеский максимализм - ты пытаешь написать свой фреймворк, и при этом это твой первый проект на PHP.

    C3-PO, 03 Октября 2018

    Комментарии (17)
  7. JavaScript / Говнокод #24846

    −3

    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
    // ==UserScript==
    // @name           Comment Highlighter
    // @description    Подсвечивает новые комментарии
    // @include        *://govnokod.ru/*
    // @include        *://www.govnokod.ru/*
    // @version        2.1
    // @grant          none
    // ==/UserScript==
    
    (function() {
    
    function updateState(data, lastPID, updater) {
      // use `cid = 0` to enable highlighting comments in unvisited posts
      // use `cid = Infinity` to disable highlighting in unvisited posts
      var out, idx, pid, i = 0, cid = 0; // here
      
      while(i < data.length) {
        idx = i;
        pid = data.charCodeAt(i++);
        if(pid & 0x8000) {
          pid &= 0x7fff;
          pid <<= 16;
          pid |= data.charCodeAt(i++);
        }
        if(pid == lastPID) {
          cid = data.charCodeAt(i++) << 16 | data.charCodeAt(i++);
          break;
        } else {
          i += 2;
        }
      }
      
      data = pid == lastPID ? data.substring(0, idx) + data.substring(i) : data;
      
      var lastCID = updater(cid);
      
      if(isFinite(lastPID) && lastPID >= 0 && lastPID < 0x80000000) {
        data += (lastPID >= 0x8000 ? String.fromCharCode(0x8000 | lastPID >> 16) : '') +
          String.fromCharCode(lastPID & 0xffff) + String.fromCharCode(lastCID >> 16) +
          String.fromCharCode(lastCID & 0xffff);
      }
      
      return data;
    }
    
    function commentID(comment) {
      var commentLink = comment.querySelector('a.comment-link');
      return Number(commentLink.href.match(/comment(\d+)$/)[1]);
    }
    
    function updateComments(prevCID) {
      var comments = document.querySelectorAll('.entry-comment-wrapper');
      var lastCID = prevCID;
    
      for(var i=0; i<comments.length; ++i) {
        var comment = comments[i];
        var cid = commentID(comment);
        if(cid <= prevCID) continue;
        if(cid > lastCID) lastCID = cid;
        comment.classList.add('new');
      }
      
      return lastCID;
    }
    
    var post = location.pathname.match(/^\/(\d+)/);
    if(!post) return;
    
    var PARAM = '8a9bd32e-20bc-42c7-bcdd-b65bb1fc2d0b-visited2';
    var postID = +post[1];
    var oldState = localStorage.getItem(PARAM) || '';
    var newState = updateState(oldState, postID, updateComments);
    localStorage.setItem(PARAM, newState);
    
    })();

    Битоёбство в "JS".
    https://github.com/1024--/govnokod.ru-userscripts/blob/master/highlight-new.user.js

    > use `cid = Infinity` to disable highlighting in unvisited posts
    Не работает.
    При следующем открытии все помечаются как не прочтённые.

    Пофиксил так:

    function updateComments(prevCID, highlightUnvisited=false) {
    var comments = document.querySelectorAll('.entry-comment-wrapper');
    var lastCID = prevCID;

    for(var i=0; i<comments.length; ++i) {
    var comment = comments[i];
    var cid = commentID(comment);
    if(cid <= prevCID) continue;
    if(cid > lastCID) lastCID = cid;
    if (!highlightUnvisited && prevCID === 0) continue;
    comment.classList.add('new');
    }

    return lastCID;
    }

    guestinxo, 02 Октября 2018

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

    −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
    NTSTATUS resize(size_t new_capacity)
    {
        NT_ASSERT(new_capacity >= m_size);
        if constexpr (std::is_pod_v<T>) {
            T *new_array = static_cast<T*>(KReallocate(m_size, new_capacity, sizeof(T), m_array, POOL, TAG));
            if (!new_array) {
                return STATUS_NO_MEMORY;
            }
            m_capacity = new_capacity;
            m_array = new_array;
        } else {
            T *new_array = static_cast<T*>(KAllocate(new_capacity, sizeof(T), POOL, TAG));
            if (!new_array) {
                return STATUS_NO_MEMORY;
            }
             for (size_t i = 0; i < m_size; i++) {
                new (&new_array[i]) T(std::move(m_array[i]));
                m_array[i].~T();
            }
            KmdfDeallocate(m_array, TAG);
            m_capacity = new_capacity;
            m_array = new_array;
        }
    
        return STATUS_SUCCESS;
    }

    gost, 17 Сентября 2018

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

    −1

    1. 1
    2. 2
    Давайте ругать "Windows"
    https://habr.com/post/418087/

    Syoma, это кокраз то, о чем ты писал: https://habr.com/post/418087/#comment_18916563

    guestinxo, 25 Июля 2018

    Комментарии (17)
  10. PHP / Говнокод #24502

    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
    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
    /* Разработчик  http://webkiev.com/  Тарас КТЛ(Кучинский Тарас Леонидович)  г.Киев ул. Заболотного 26 */
    
    if($count_tovar!=0){
     $count_filtr=count($shop_m_tovar[0]);
    $i=0;while ($i < $count_tovar) {$ii=0; while ($ii < $count_filtr){$shop_filtr[$ii][$i]=$shop_m_tovar[$i][$ii];$ii++;}$i++;}
    if($tovar_sort=="1"){/*сортировка по возрастанию по цене*/
    array_multisort(
    $shop_filtr[6],$shop_filtr[7],$shop_filtr[8],$shop_filtr[9],
    $shop_filtr[10],$shop_filtr[11],$shop_filtr[12],$shop_filtr[13],$shop_filtr[14],$shop_filtr[15],$shop_filtr[16],$shop_filtr[17],$shop_filtr[18],$shop_filtr[19],
    $shop_filtr[20],$shop_filtr[21],$shop_filtr[22],$shop_filtr[23],$shop_filtr[24],$shop_filtr[25],$shop_filtr[26],$shop_filtr[27],$shop_filtr[28],$shop_filtr[29],
    $shop_filtr[30],$shop_filtr[31],$shop_filtr[32],$shop_filtr[33],$shop_filtr[34],$shop_filtr[35],$shop_filtr[36],$shop_filtr[37],$shop_filtr[38],$shop_filtr[39],
    $shop_filtr[40],$shop_filtr[41],$shop_filtr[42],$shop_filtr[43],$shop_filtr[44],$shop_filtr[45],$shop_filtr[46],$shop_filtr[47],$shop_filtr[48],
    $shop_filtr[49],
    $shop_filtr[50],$shop_filtr[51],$shop_filtr[52],$shop_filtr[53],$shop_filtr[54],$shop_filtr[55],$shop_filtr[56],$shop_filtr[57],$shop_filtr[58],$shop_filtr[59],
    $shop_filtr[60],$shop_filtr[61],$shop_filtr[62],$shop_filtr[63],$shop_filtr[64],$shop_filtr[65],$shop_filtr[66],$shop_filtr[67],$shop_filtr[68],$shop_filtr[69],
    $shop_filtr[70],
    $shop_filtr[0],$shop_filtr[1],$shop_filtr[2],$shop_filtr[3],$shop_filtr[4],$shop_filtr[5]
    );
    }
    if($tovar_sort=="2"){/*сортировка на убывание по цене*/
    array_multisort(
    $shop_filtr[6],SORT_DESC, $shop_filtr[7],$shop_filtr[8],$shop_filtr[9],
    $shop_filtr[10],$shop_filtr[11],$shop_filtr[12],$shop_filtr[13],$shop_filtr[14],$shop_filtr[15],$shop_filtr[16],$shop_filtr[17],$shop_filtr[18],$shop_filtr[19],
    $shop_filtr[20],$shop_filtr[21],$shop_filtr[22],$shop_filtr[23],$shop_filtr[24],$shop_filtr[25],$shop_filtr[26],$shop_filtr[27],$shop_filtr[28],$shop_filtr[29],
    $shop_filtr[30],$shop_filtr[31],$shop_filtr[32],$shop_filtr[33],$shop_filtr[34],$shop_filtr[35],$shop_filtr[36],$shop_filtr[37],$shop_filtr[38],$shop_filtr[39],
    $shop_filtr[40],$shop_filtr[41],$shop_filtr[42],$shop_filtr[43],$shop_filtr[44],$shop_filtr[45],$shop_filtr[46],$shop_filtr[47],$shop_filtr[48],
    $shop_filtr[49],
    $shop_filtr[50],$shop_filtr[51],$shop_filtr[52],$shop_filtr[53],$shop_filtr[54],$shop_filtr[55],$shop_filtr[56],$shop_filtr[57],$shop_filtr[58],$shop_filtr[59],
    $shop_filtr[60],$shop_filtr[61],$shop_filtr[62],$shop_filtr[63],$shop_filtr[64],$shop_filtr[65],$shop_filtr[66],$shop_filtr[67],$shop_filtr[68],$shop_filtr[69],
    $shop_filtr[70],
    $shop_filtr[0],$shop_filtr[1],$shop_filtr[2],$shop_filtr[3],$shop_filtr[4],$shop_filtr[5]
    );
    }
    $i=0;while ($i < $count_tovar) {$ii=0; while ($ii < $count_filtr) {$shop_m_tovar[$i][$ii]=$shop_filtr[$ii][$i];$ii++;}$i++;}
    }

    Сортировка товаров на чистом коде

    brevis, 16 Июля 2018

    Комментарии (17)
  11. Куча / Говнокод #24438

    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
    23. 23
    <!DOCTYPE html>
    <html>
        <head>
            <title>Why is he always talking about that damm movie?</title>
        </head>
        
    <img src="https://cdn.shopify.com/s/files/1/0064/7532/products/poster-war-games-1983-regular-2_1024x1024.jpg?v=1455775393" width="350" height="250">
    <br>
    <p>Wargames 1983</p>
    <br>
    <p>from: https://en.wikipedia.org/wiki/WarGames</p>
    <p>The film follows David Lightman, a young hacker who unwittingly accesses WOPR (War Operation Plan Response), a United States military supercomputer originally programmed to predict possible outcomes of nuclear war. Lightman gets WOPR to run a nuclear war simulation, believing it to be a computer game. The computer, now tied into the nuclear weapons control system and unable to tell the difference between simulation and reality, attempts to start World War III.
    </p>
    <img src="http://cdn3-www.comingsoon.net/assets/uploads/2015/10/wargames-1.jpg" width="350" height="200">
    <br>
    <p>The computer stages a massive Soviet first strike with hundreds of missiles, submarines, and bombers. Believing the attack to be genuine, NORAD prepares to retaliate. Falken (Inventor/Programmer) and David convince military officials to cancel the second strike and ride out the attack. WOPR tries to launch the missiles itself, however, using a brute-force attack to obtain the launch code. Without humans in the control centers as a safeguard, the computer will trigger a mass launch. All attempts to log in and order to cancel the countdown fail, and all weapons will launch if the computer is disabled.</p>
        
    <br>    
        <img src="http://oliversmith.cc/wp-content/uploads/2014/11/Screen-Shot-2014-11-26-at-14.17.30-e1417011526324-640x469.png" width="350" height="200">
    <p>Falken and David direct the computer to play tic-tac-toe against itself. This results in a long string of draws, forcing the computer to learn the concept of futility and no-win scenarios. WOPR obtains the missile code, but before launching, it cycles through all the nuclear war scenarios it has devised, finding they, too, all result in stalemates. Having discovered the concept of mutual assured destruction ("WINNER: NONE"), the computer tells Falken that it has concluded that nuclear war is "a strange game" in which "the only winning move is not to play." WOPR relinquishes control of NORAD and the missiles and offers to play "a nice game of chess."</p>
        
      </body>  
    </html>

    Ржунимагу. Этот говно код набрал 25 лайков а нормальный мой код калькулятора во вкладке рядом 0. Куда катится мир...

    Arduino, 02 Июля 2018

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