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

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

    +890.7

    1. 1
    #define private public

    guest, 12 Декабря 2008

    Комментарии (32)
  3. Pascal / Говнокод #54

    −5.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
    function IntToMonth(NumberMonth: Integer): string;
    begin
      сase NumberMonth of
        1: Result := 'Январь';
        2: Result := 'Февраль';
        3: Result := 'Март';
        4: Result := 'Апрель';
        5: Result := 'Май';
        6: Result := 'Июнь';
        7: Result := 'Июль';
        8: Result := 'Август';
        9: Result := 'Сентябрь';
        10: Result := 'Октябрь';
        11: Result := 'Ноябрь';
        12: Result := 'Декабрь';
      else
        Result := 'Август';
      end;
    end;

    Думаю, по названию функции все понятно :)

    guest, 04 Декабря 2008

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

    +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
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/alloc/alloc.rs#L376
    pub const fn handle_alloc_error(layout: Layout) -> ! {
        const fn ct_error(_: Layout) -> ! {
            panic!("allocation failed");
        }
    
        fn rt_error(layout: Layout) -> ! {
            unsafe {
                __rust_alloc_error_handler(layout.size(), layout.align());
            }
        }
    
        unsafe { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) }
    }
    
    
    // https://github.com/torvalds/linux/blob/b6dad5178ceaf23f369c3711062ce1f2afc33644/rust/kernel/lib.rs#L96-L103
    fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
        pr_emerg!("{}\n", info);
        // SAFETY: FFI call.
        unsafe { bindings::BUG() };
        // Bindgen currently does not recognize `__noreturn` so `BUG` returns `()`
        // instead of `!`. See <https://github.com/rust-lang/rust-bindgen/issues/2094>.
        loop {}
    }
    
    
    // https://github.com/torvalds/linux/blob/master/include/asm-generic/bug.h#L51-L68
    /*
     * Don't use BUG() or BUG_ON() unless there's really no way out; one
     * example might be detecting data structure corruption in the middle
     * of an operation that can't be backed out of.  If the (sub)system
     * can somehow continue operating, perhaps with reduced functionality,
     * it's probably not BUG-worthy.
     *
     * If you're tempted to BUG(), think again:  is completely giving up
     * really the *only* solution?  There are usually better options, where
     * users don't need to reboot ASAP and can mostly shut down cleanly.
     */
    #ifndef HAVE_ARCH_BUG
    #define BUG() do { \
    	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
    	barrier_before_unreachable(); \
    	panic("BUG!"); \
    } while (0)
    #endif

    О том, как в ядре Linux говнораст обрабатывает ошибку аллокации

    j123123, 19 Июня 2023

    Комментарии (31)
  5. Assembler / Говнокод #28534

    −4

    1. 1
    Зачем простенькие проги, написанные на MASM коннектятся к ip адресу Microsoft 20.99.133.109:443?

    BelCodeMonkey, 01 Января 2023

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

    −2

    1. 1
    2. 2
    cli
    a: jmp a

    DartPower, 02 Июля 2022

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

    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
    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
    int main() {
    
      ifstream input_file;
    
      input_file.open("DATA");
      
      string line;
      while (getline(input_file, line)) {
        size_t i = 0, j = 0;
        string fname, sname;
        float score;
    
        char c = line[0];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        fname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        c = line[i];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        sname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        score = stof(line.substr(i, line.size()));
    
        Data dat;
        dat.fname = fname;
        dat.sname = sname;
        dat.score = score;
    
        vec.push_back(dat);
      }
      
      const auto comp_fname = [](Data a, Data b){return a.fname >= b.fname;};
      const auto comp_sname = [](Data a, Data b){return a.sname >= b.sname;};
      const auto comp_score = [](Data a, Data b){return a.score >= b.score;};
    
      const auto dcomp_fname = [](Data a, Data b){return a.fname < b.fname;};
      const auto dcomp_sname = [](Data a, Data b){return a.sname < b.sname;};
      const auto dcomp_score = [](Data a, Data b){return a.score < b.score;};
    
      print(vec);
      char choice = 0, order = 0;
      cout << "Как сортировать (0 - Fфмилия, 1 - Iмя, 2 - CpegHuu_6aJlJl): ";
      cin >> choice;
      cout << "А в какмо порядке?7? (0 - по убыванию, 1 - по возрастанию)Ж ";
      cin >> order;
      
      if (choice == '0') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_fname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_fname);
        }
      } else if (choice == '1') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_sname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_sname);
        }
      } else if (choice == '2') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_score);
        } else {
          sort(vec.begin(), vec.end(), dcomp_score);
        }
      }
    
    // и т.д. ...

    Как вам? Зачёт? Незачёт? Удовлетворительно?

    JloJle4Ka, 12 Марта 2022

    Комментарии (31)
  8. JavaScript / Говнокод #27950

    −1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    class Node<T> {
        v: T;
        k: string;
        next: Node<T>;
    }
    
    class Map<T> {
        head: Node<T>;
    
        getElt(k: string): T {
            return mapGet(this, k)
        }
    
        setElt(k: string, v: T) {
            mapSet(this, k, v)
        }
    }
    
    function mapSet<T>(m: Map<T>, k: string, v: T) {
        for (let p = m.head; p != null; p = p.next) {
            if (p.k == k) {
                p.v = v
                return
            }
        }
        let n = new Node<T>()
        n.next = m.head
        n.k = k
        n.v = v
        m.head = n
    }
    
    function mapGet<T>(m: Map<T>, k: string): T {
        for (let p = m.head; p != null; p = p.next) {
            if (p.k == k) {
                return p.v
            }
        }
        return null
    }
    
    
    function search_array<T>(a: T[], item: T): number {
        for (let i = 0; i < a.length; i++) {
            if (a[i] == item) {
                return i
            }
        }
        return -1 // NOT FOUND
    }
    
    class MyMap<K, V> {
    
        keys: K[]
        values: V[]
    
        constructor() {
            this.keys = []
            this.values = []
        }
    
        push(key: K, value: V) {
            this.keys.push(key)
            this.values.push(value)
        }
    
        value_for(key: K): V {
            let i = search_array(this.keys, key)
            if (i == -1) {
                return null
            }
            return this.values[i]
        }
    
        key_for(value: V): K {
            let i = search_array(this.values, value)
            if (i == -1) {
                return null
            }
            return this.keys[i]
        }
        set(key: K, value: V): void {
            let i = search_array(this.keys, key)
            if (i == -1) {
                this.keys.push(key)
                this.values.push(value)
            } else {
                this.values[i] = value
            }
        }
    
        has_key(key: K): boolean {
            return search_array(this.keys, key) != -1
        }
    
        has_value(value: V): boolean {
            return search_array(this.values, value) != -1
        }
    
    }

    Срочно нужна помощь... не могу решить что делать с функцией mapGet .. когда T - number я не могу использовать "null" .. должен я хакнуть компилятор или изменить тестовый пример?

    ASD_77, 13 Января 2022

    Комментарии (31)
  9. JavaScript / Говнокод #27929

    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
    class Node<T> {
        v: T;
        k: string;
        next: Node<T>;
    }
    
    function main()
    {
        let n = new Node<number>()
        n.next = n
        n.k = "Hello";
        n.v = 10.0;
        print("done.");
    }

    Вы не поверите как сложно сделать простые вещи в LLVM. встречаем рекурсивные типы :)

    ASD_77, 06 Января 2022

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

    +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
    template<typename T>
    static ALWAYS_INLINE void FormatLogMessageAndPrintW(
                                                 const char* channelName, 
                                                 const char* functionName, 
                                                 LOGLEVEL level,
                                                 const char* message, 
                                                 bool timestamp, 
                                                 bool ansi_color_code,
                                                 bool newline, 
                                                 const T& callback)
    {
      char buf[512];
      char* message_buf = buf;
      int message_len;
      if ((message_len = FormatLogMessageForDisplay(message_buf,
                           sizeof(buf), channelName, functionName,
                           level, 
                           message, timestamp,
                           ansi_color_code, newline)) > (sizeof(buf) - 1))
      {
        message_buf = static_cast<char*>(std::malloc(message_len + 1));
        message_len = FormatLogMessageForDisplay(message_buf, 
                     message_len + 1, channelName, functionName, 
                     level, message, timestamp, ansi_color_code, newline);
      }
      if (message_len <= 0)
        return;
    
      // Convert to UTF-16 first so unicode characters display correctly.
      // NT is going to do it anyway...
      wchar_t wbuf[512];
      wchar_t* wmessage_buf = wbuf;
      int wmessage_buflen = countof(wbuf) - 1;
      if (message_len >= countof(wbuf))
      {
        wmessage_buflen = message_len;
        wmessage_buf = static_cast<wchar_t*>
                   (std::malloc((wmessage_buflen + 1) * sizeof(wchar_t)));
      }
    
      wmessage_buflen = MultiByteToWideChar(CP_UTF8, 0, message_buf,
                        message_len, wmessage_buf, wmessage_buflen);
    
      if (wmessage_buflen <= 0)
        return;
    
      wmessage_buf[wmessage_buflen] = '\0';
      callback(wmessage_buf, wmessage_buflen);
    
      if (wmessage_buf != wbuf)
      {
        std::free(wbuf);                        // <=
      }
    
      if (message_buf != buf)
      {
        std::free(message_buf);
      }
    }

    Отсюда:
    https://pvs-studio.com/ru/blog/posts/cpp/0880/

    HO9I6PbCKuu_neTyx, 03 Ноября 2021

    Комментарии (31)
  11. Java / Говнокод #27313

    +5

    1. 1
    2. 2
    3. 3
    private static String getMargin(final int size) {
            return "                                                                                                                             ".substring(0, 6 * size);
        }

    Как создать пустую строку с заданной длиной...

    nekkiy, 24 Марта 2021

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