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

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

    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
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    export type Maybe<T> = null | undefined | T;
    
    export interface Path {
        readonly prev: Path | undefined;
        readonly key: string | number;
        readonly typename: string | undefined;
    }
    
    /**
     * Given a Path and a key, return a new Path containing the new key.
     */
    export function addPath(
        prev: Readonly<Path> | undefined,
        key: string | number,
        typename: string | undefined,
    ): Path {
        return { prev, key, typename };
    }
    
    /**
     * Given a Path, return an Array of the path keys.
     */
    export function pathToArray(
        path: Maybe<Readonly<Path>>,
    ): Array<string | number> {
        let curr = path;
        let flattened = [];
        while (curr) {
            flattened.push(curr.key);
            curr = curr.prev;
        }
        //flattened.reverse();
        return flattened;
    }
    
    function main() {
        let pathArray = pathToArray({
            key: "path",
            prev: undefined,
            typename: undefined,
        });
        for (let x of pathArray) {
            print(x);
        }
    }

    последний коммит позволяет скомпилить и выполнить данный код. это невиданный прогресс в компиляторе :)

    и уже традиционный вопрос ... а ты там можешь наговнокодить на С/C++?

    ASD_77, 31 Декабря 2021

    Комментарии (26)
  3. Куча / Говнокод #27860

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Можно ли считать говнокодом (говноAPI) правильно работающую, но незадокументированную особенность API?
    Например у вьюхи есть свойство isOpen, которое может быть задано (true/false) а может быть не задано (undefined). 
    Первое нужно для управления видимостью в реактивном стиле, второе предполагает что разработчик будет
    управлять видимостью через хендлы вьюхи. И оно так и работает - если isOpen=undefined, то этот проп просто игнорируется
    при обновлении вьюхи (чтобы не допустить конфликта source truth). Но этого нет в документации, отчего неосторожное 
    использование булеана и значения которое может быть undefined в качестве значения isOpen, приводит к забавному
    косяку - вьюха должна исчезнуть, но она не исчезает! И тут по-началу грешишь на забагованное API. Но в нем нет бага!

    JaneBurt, 06 Декабря 2021

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

    +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
    (** Set of all possible interleaving of two traces is a trace
      ensemble. As we later prove in [interleaving_to_permutation], this
      definition is dual to [Permutation]. *)
      Inductive Interleaving : list TE -> list TE -> TraceEnsemble :=
      | ilv_cons_l : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving (te :: t1) t2 (te :: t)
      | ilv_cons_r : forall te t1 t2 t,
          Interleaving t1 t2 t ->
          Interleaving t1 (te :: t2) (te :: t)
      | ilv_nil : Interleaving [] [] [].
    
    Попытка оптимизации:
    
      (* Left-biased version of [Interleaving] that doesn't make
      distinction between schedulings of commuting elements: *)
      Inductive UniqueInterleaving : list TE -> list TE -> TraceEnsemble :=
      | uilv_cons_l : forall l t1 t2 t,
          UniqueInterleaving t1 t2 t ->
          UniqueInterleaving (l :: t1) t2 (l :: t)
      | uilv_cons_r1 : forall l r t1 t2 t,
          ~trace_elems_commute l r ->
          UniqueInterleaving (l :: t1) t2 (l :: t) ->
          UniqueInterleaving (l :: t1) (r :: t2) (r :: l :: t)
      | uilv_cons_r2 : forall r1 r2 t1 t2 t,
          UniqueInterleaving t1 (r1 :: t2) (r1 :: t) ->
          UniqueInterleaving t1 (r2 :: r1 :: t2) (r2 :: r1 :: t)
      | uilv_nil : forall t, UniqueInterleaving [] t t.

    Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?

    CHayT, 01 Ноября 2021

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

    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
    #define REGISTERS_LIST A, B, C, D, E, SI, BP, SP, IP
    #define LREGISTERS_LIST AH, AL, BH, BL, CH, CL, DH, DL, EH, EL, SIH, SIL, BPH, BPL, SPH, SPL, IPH, IPL
    
    enum RegisterID
    {
    	REGISTERS_LIST,
    	LREGISTERS_LIST
    };
    
    const static std::string registerId2registerName[] = {
    #define _MAP(x) #x
    	MAP_LIST(_MAP, REGISTERS_LIST),
    	MAP_LIST(_MAP, LREGISTERS_LIST)
    };
    #undef _MAP
    
    const static std::map<std::string, RegisterID> registerName2registerId = {
    #define _MAP(x) {#x, x}
    	MAP_LIST(_MAP, REGISTERS_LIST),
    	MAP_LIST(_MAP, LREGISTERS_LIST)
    };
    #undef _MAP

    покруче гомоиконности

    digitalEugene, 30 Октября 2021

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

    −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
    <?php
    
    function is_russian_char($c) {
        return preg_match('/[А-Яа-яЁё]/u', $c);
    }
    
    function nemyxify_char($a) {
        $map = [
            "а" => "a",
            "б" => "6",
            "в" => "B",
            "г" => "r",
            "д" => "g",
            "е" => "e",
            "ё" => "e",
            "ж" => "Jk",
            "з" => "3",
            "и" => "u",
            "й" => "u",
            "к" => "k",
            "л" => "JI",
            "м" => "M",
            "н" => "H",
            "о" => "o",
            "п" => "n",
            "р" => "p",
            "с" => "c",
            "т" => "m",
            "у" => "y",
            "ф" => "qp",
            "х" => "x",
            "ц" => "LL",
            "ч" => "4",
            "ш" => "LLI",
            "щ" => "LLL",
            "ь" => "b",
            "ы" => "bI",
            "ъ" => "b",
            "э" => "3",
            "ю" => "I0",
            "я" => "9I",
    
            "А" => "A",
            "Д" => "D",
            "Е" => "E",
            "Ё" => "E",
            "Ж" => "JK",
            "И" => "U",
            "Й" => "U",
            "К" => "K",
            "О" => "O",
            "Р" => "P",
            "С" => "C",
            "Т" => "T",
            "У" => "Y",
            "Х" => "X",
        ];
        if (isset($map[$a])) {
            return $map[$a];
        }
        return $map[mb_strtolower($a)];
    }
    
    function gk_nemyxify($text) {
        $res = '';
        foreach (preg_split( '//u', $text, null, PREG_SPLIT_NO_EMPTY ) as $c) {
            if (is_russian_char($c)) {
                $res .= nemyxify_char($c);
            } else {
                $res .= $c;
            }
        }
        return $res;
    }

    guest6, 04 Октября 2021

    Комментарии (26)
  7. Куча / Говнокод #27601

    +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
    fn main() {
        println!("Hello World!");
    }
    
    rustc --version --verbose:
    
    rustc 1.52.1 (9bc8c42bb 2021-05-09)
    binary: rustc
    commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
    commit-date: 2021-05-09
    host: powerpc-unknown-linux-gnu
    release: 1.52.1
    LLVM version: 12.0.0
    
    Error output
    
    rustc ./hello.rs
    Illegal instruction (core dumped)

    https://github.com/rust-lang/rust/issues/85238

    Open: clienthax opened this issue on May 12 · 6 comments

    3.14159265, 22 Августа 2021

    Комментарии (26)
  8. PHP / Говнокод #27582

    +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
    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
    if($account['lvl']=="1"){ $exp=round($account['exp']*100/52);}
    if($account['lvl']=="2"){ $exp=round((($account['exp']-52)/(110))*100,2);}
    if($account['lvl']=="3"){ $exp=round((($account['exp']-135)/(832-135))*100,2);}
    if($account['lvl']=="4"){ $exp=round((($account['exp']-832)/(3547-832))*100,2);}
    if($account['lvl']=="5"){ $exp=round((($account['exp']-3547)/(9658-3547))*100,2);}
    if($account['lvl']=="6"){ $exp=round((($account['exp']-9658)/(15478-9658))*100,2);}
    if($account['lvl']=="7"){ $exp=round((($account['exp']-15478)/(18478-15478))*100,2);}
    if($account['lvl']=="8"){ $exp=round((($account['exp']-18478)/(30789-18478))*100,2);}
    if($account['lvl']=="9"){ $exp=round((($account['exp']-30789)/(72394-30789))*100,2);}
    if($account['lvl']=="10"){ $exp=round((($account['exp']-72394)/(138789-72394))*100,2);}
    if($account['lvl']=="11"){ $exp=round((($account['exp']-138789)/(214787-138789))*100,2);}
    if($account['lvl']=="12"){ $exp=round((($account['exp']-214787)/(398747-214787))*100,2);}
    if($account['lvl']=="13"){ $exp=round((($account['exp']-398747)/(587058-398747))*100,2);}
    if($account['lvl']=="14"){ $exp=round((($account['exp']-587058)/(824585-587058))*100,2);}
    if($account['lvl']=="15"){ $exp=round((($account['exp']-824585)/(1247858-824585))*100,2);}
    if($account['lvl']=="16"){ $exp=round((($account['exp']-1247858)/(1558789-1247858))*100,2);}
    if($account['lvl']=="17"){ $exp=round((($account['exp']-1558789)/(1985478-1558789))*100,2);}
    if($account['lvl']=="18"){ $exp=round((($account['exp']-1985478)/(2245857-1985478))*100,2);}
    if($account['lvl']=="19"){ $exp=round((($account['exp']-2245857)/(2785896-2245857))*100,2);}
    if($account['lvl']=="20"){ $exp=round((($account['exp']-2785896)/(3685478-2785896))*100,2);}
    if($account['lvl']=="21"){ $exp=round((($account['exp']-3685478)/(4169875-3685478))*100,2);}
    if($account['lvl']=="22"){ $exp=round((($account['exp']-4169875)/(5125478-4169875))*100,2);}
    if($account['lvl']=="23"){ $exp=round((($account['exp']-5125478)/(5999999-5125478))*100,2);}
    if($account['lvl']=="24"){ $exp=round((($account['exp']-5999999)/(7145877-5999999))*100,2);}
    if($account['lvl']=="25"){ $exp=round((($account['exp']-7145877)/(8791755-7145877))*100,2);}
    if($account['lvl']=="26"){ $exp=round((($account['exp']-8791755)/(10691755-8791755))*100,2);}
    if($account['lvl']=="27"){ $exp=round((($account['exp']-10691755)/(12791755-10691755))*100,2);}
    if($account['lvl']=="28"){ $exp=round((($account['exp']-12791755)/(15191755-12791755))*100,2);}
    if($account['lvl']=="29"){ $exp=round((($account['exp']-15191755)/(18091755-15191755))*100,2);}
    if($account['lvl']=="30"){ $exp=round((($account['exp']-18091755)/(21191755-18091755))*100,2);}
    if($account['lvl']=="31"){ $exp=round((($account['exp']-21191755)/(24491755-21191755))*100,2);}
    if($account['lvl']=="32"){ $exp=round((($account['exp']-24491755)/(27991755-24491755))*100,2);}
    if($account['lvl']=="33"){ $exp=round((($account['exp']-27991755)/(31691755-27991755))*100,2);}
    if($account['lvl']=="34"){ $exp=round((($account['exp']-31691755)/(35791755-31691755))*100,2);}
    if($account['lvl']=="35"){ $exp=round((($account['exp']-35791755)/(40391755-35791755))*100,2);}
    if($account['lvl']=="36"){ $exp=round((($account['exp']-40391755)/(45591755-40391755))*100,2);}
    if($account['lvl']=="37"){ $exp=round((($account['exp']-45591755)/(51491755-45591755))*100,2);}
    if($account['lvl']=="38"){ $exp=round((($account['exp']-51491755)/(58191755-51491755))*100,2);}
    if($account['lvl']=="39"){ $exp=round((($account['exp']-58191755)/(65791755-58191755))*100,2);}
    if($account['lvl']=="40"){ $exp=round((($account['exp']-65791755)/(74391755-65791755))*100,2);}
    if($account['lvl']=="41"){ $exp=round((($account['exp']-74391755)/(83991755-74391755))*100,2);}
    if($account['lvl']=="42"){ $exp=round((($account['exp']-83991755)/(94591755-83991755))*100,2);}
    if($account['lvl']=="43"){ $exp=round((($account['exp']-94591755)/(106191755-94591755))*100,2);}
    if($account['lvl']=="44"){ $exp=round((($account['exp']-106191755)/(118791755-106191755))*100,2);}
    if($account['lvl']=="45"){ $exp=round((($account['exp']-118791755)/(132391755-118791755))*100,2);}
    if($account['lvl']=="46"){ $exp=round((($account['exp']-132391755)/(146991755-132391755))*100,2);}
    if($account['lvl']=="47"){ $exp=round((($account['exp']-146991755)/(162591755-146991755))*100,2);}
    if($account['lvl']=="48"){ $exp=round((($account['exp']-162591755)/(179191755-162591755))*100,2);}
    if($account['lvl']=="49"){ $exp=round((($account['exp']-179191755)/(196791755-179191755))*100,2);}
    if($account['lvl']=="50"){ $exp=round((($account['exp']-196791755)/(215391755-196791755))*100,2);}

    Расчет % заполнения шкалы уровня в зависимости от опыта

    EndoCrinolog, 20 Августа 2021

    Комментарии (26)
  9. Python / Говнокод #27542

    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
    class Bagor:
    	r = []
    	
    	def __init__(self, val):
    		self.r.append(val)
    		
    	def get(self):
    		return self.r[0]
    		
    kakoi = Bagor(1)
    bagor = Bagor(2)
    print([kakoi.get(), bagor.get()])

    https://ideone.com/K7tADi

    3_dar, 29 Июля 2021

    Комментарии (26)
  10. Python / Говнокод #27351

    +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
    """
    A module for printing funny frames.
    Copyright (C) 2021 Ingostnus.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    """
    
    from math import sqrt
    
    _str = "sample"                  # String to be turned into a funny frame.
    _sep = ' '                       # Separator, i.e. a string to be inserted between each letter of the _str.
    _vertical_separator_mode = 'F'   # Determines whether separator should be printed between each row.
                                     # ... 'F' --> off. 'T' --> on.
    
    def get_user_input() -> None:
        """
        This function lets user input desired values and override the defaults.
        """
        global _str; _str = str(input("String: "))
        global _sep; _sep = str(input("Character: "))
        global _vertical_separator_mode; _vertical_separator_mode = str((input("VSM (T/F):")))
        if _vertical_separator_mode == 'T':
            print("VMS is ON!!!")
    
    def print_frame(printer = print) -> list:
        """
        This function is designed for printing a frame. Custom printer function
        may be supplied to process the output in a specific way.
        """
    
        buffer_len = (len(_str) + len(_sep) * (len(_str) - 1))**2
    
        # First line.
        printer(''.join([_str[i] + _sep if i < (len(_str) - 1) else _str[-1] for i in range(len(_str))]))
        
        # Second -- pre last lines.
        empty_space = ' ' * (int(sqrt(buffer_len)) - 2)
        for i in range(1, len(_str) - 1):
            # If vertical separator mode is toggled, print vertical separator.
            if _vertical_separator_mode == 'T':
                printer(_sep + empty_space + _sep)
            printer(_str[i] + empty_space + _str[-(i + 1)])
        
        # Last line.
        printer(''.join([_str[-(i + 1)] + _sep if i < (len(_str) - 1) else _str[0] for i in range(len(_str))]))
    
    # To give the best perfomance and flexibility, this module should be used as
    # an imported library. Though, its basic functionality can be used even if
    # it's executed directly.
    if __name__ == '__main__':
        get_user_input()
        print_frame()

    Переписала код https://govnokod.ru/27348 на питон, добавив чуть-чуть улучшений и немноже4ко документацци.

    KoWe4Ka_l7porpaMMep, 11 Апреля 2021

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

    +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
    using System.Device.Gpio;
    using System;
    using System.Threading;
    
    namespace Blinky
    {
    	public class Program
        {
            private static GpioController s_GpioController;
            public static void Main()
            {
                s_GpioController = new GpioController();
    
                // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
                GpioPin led = s_GpioController.OpenPin(4,PinMode.Output);
                led.Write(PinValue.Low);
    
                while (true)
                {
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(525);
                }
            }        
        }
    }

    https://habr.com/ru/post/549012/: «.NET nanoFramework — платформа для разработки приложений на C# для микроконтроллеров».

    Ну все, последний оплот сишки пал, можно ее закапывать.

    PolinaAksenova, 25 Марта 2021

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