1. Куча / Говнокод #26963

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    Иногда вижу такие "вложенные списки" в Markdown:
    
    1. text
        1.1. text
        1.2. text
                1.2.1. text
                1.2.2. text
                1.2.3. text
    
    А потом ещё удивляются, почему списки съезжают или показываются неправильно...

    groser, 19 Сентября 2020

    Комментарии (69)
  2. C++ / Говнокод #26962

    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
    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
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    #include <conio.h>
    const int x_size(20), y_size(10); int x_pos(x_size/2+1); int y_pos(y_size/2+1);
    enum border_types{lineNL, single, singleNL};
    enum directions{UpLeft=1, UpRight, DownLeft, DownRight}dir;
    void draw_border(enum border_types borders) {
    	do{
    		if(borders == single || borders == singleNL) break;
    		for(int i=0; i<x_size+1; i++)
    	  	  putchar('#');
    	}while(false);
    	putchar('#');
    	if(borders == singleNL || borders == lineNL) std::cout << '\n';}
    void display_update() {
    	system("cls");
    	draw_border(lineNL);
    	for(int i=1; i<=y_size; i++)
    	{
    		draw_border(single);
    		for(int j=1; j<=x_size; j++)
    		{
    			if(j == x_pos && i == y_pos)
    			{
    				putchar('x');
    				continue;
    			}
    			putchar(32);
    		}
    		draw_border(singleNL);;
    	}
    	draw_border(lineNL);
    	std::cout << "X: " << x_pos << "\tY: " << y_pos;}
    void logic() {
    	switch(x_pos)
    	{
    		case 1:
    			if(dir == UpLeft) dir = UpRight;
    			if(dir == DownLeft) dir = DownRight;
    			break;
    		case x_size:
    			if(dir == UpRight) dir = UpLeft;
    			if(dir == DownRight) dir = DownLeft;
    	}
    	switch(y_pos)
    	{
    		case 1:
    			if(dir == UpLeft) dir = DownLeft;
    			if(dir == UpRight) dir = DownRight;
    			break;
    		case y_size:
    			if(dir == DownLeft) dir = UpLeft;
    			if(dir == DownRight) dir = UpRight;
    	}}
    void move() {
    	switch(dir)
    	{
    		case UpLeft:
    			x_pos--;
    			y_pos--;
    			break;
    		case UpRight:
    			x_pos++;
    			y_pos--;
    			break;
    		case DownLeft:
    			x_pos--;
    			y_pos++;
    			break;
    		case DownRight:
    			x_pos++;
    			y_pos++;
    	}}
    int main() {
    	srand(time(0));
    	rand();
    	switch(rand()%4+1)
    	{
    		case UpLeft:
    			dir = UpLeft;
    			break;
    		case UpRight:
    			dir = UpRight;
    			break;
    		case DownLeft:
    			dir = DownLeft;
    			break;
    		case DownRight:
    			dir = DownRight;
    	}
    	while(!kbhit())
    	{
    		display_update();
    		logic();
    		move();
    	}
    	return 0;}

    Сорян, пришлось уплотнить фигурные скобки, чтобы код уместился в 100 строк.

    BelCodeMonkey, 18 Сентября 2020

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

    +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
    Top 5 most loved languages:
    
    Rust: 86.1%
    TypeScript: 67.1%
    Python: 66.7%
    Kotlin: 62.9%
    Go: 62.3%
    
    Top 5 most dreaded languages:
    
    VBA: 80.4%
    Objective-C: 76.6%
    Perl: 71.4%
    Assembly: 70.6%
    C: 66.9%
    
    Top 5 most wanted languages:
    
    Python: 30.0%
    JavaScript: 18.5%
    Go: 17.9%
    TypeScript: 17.0%
    Rust: 14.6%

    https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-wanted

    Миллионы мух не могут ошибаться.

    3.14159265, 18 Сентября 2020

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

    +6

    1. 1
    Сракер, не удаляй, пожалуйста, наши оффтопы.

    Pig, 17 Сентября 2020

    Комментарии (76)
  5. Куча / Говнокод #26959

    0

    1. 1
    Тест потерянных комментариев

    Desktop, 17 Сентября 2020

    Комментарии (22)
  6. C++ / Говнокод #26958

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    class UnitedFigure : public Figure {
        Figure &f1;
        Figure &f2;
    
    public:
        UnitedFigure (Figure &_f1, Figure &_f2) : f1(_f1), f2(_f2) {}
    
        double distance_to(const Point &p) const override {
            return std::min(f1.distance_to(p), f2.distance_to(p));
        }
    }

    Завезли ссылочные поля класса, это в каком стандарте?
    Даже тестил когда то такое, наверное на C++03 и получал ошибку компилятора.
    Я и не знал, что добавили такую прекрасную возможность выстрелить себе в ногу.

    YpaHeLI_, 16 Сентября 2020

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

    +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
    Definition read_t key cont : Thread :=
          call tx_context <- get_tx_context;
          call cell <- get_cell key tx_context;
          match cell.(cell_write) with
          | Some v =>
              do _ <- log (read key v);
              cont v
          | None =>
              do v <- read_d key;
              let tx_context' := set tx_cells <[key := cell]> tx_context in
              do _ <- pd_set tx_context';
              do _ <- log (read key v);
              cont v
          end.

    Continuations are like violence, if they don't work then you're not using enough of them.

    CHayT, 16 Сентября 2020

    Комментарии (33)
  8. Куча / Говнокод #26955

    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
    Хрюкни #7
                 ._     __,
                  |\,../'\
                ,'. .     `.
               .--         '`.
              ( `' ,          ;
              ,`--' _,       ,'\
             ,`.____            `.
            /              `,    |
           '                \,   '
           |                /   /`,
           `,  .           ,` ./  |
           ' `.  ,'        |;,'   ,@
     ______|     |      _________,_____jv______
            `.   `.   ,'
             ,'_,','_,
             `'   `'

    #1: (vanished) https://govnokod.xyz/_26863
    #2: (vanished) https://govnokod.xyz/_26868
    #3: https://govnokod.ru/26881 https://govnokod.xyz/_26881
    #4: https://govnokod.ru/26896 https://govnokod.xyz/_26896
    #5: https://govnokod.ru/26928 https://govnokod.xyz/_26928
    #6: (vanished) https://govnokod.xyz/_26952

    nepeKamHblu_nemyx, 16 Сентября 2020

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

    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
    uint64_t stored_msg_id = _container_msg_id.get(ctrl_msg.sequence); // Получаем msg_id из мапы для связки сообщений
    if (stored_msg_id)
        proto_fill(ctrl_msg, stored_msg_id); // если он там был то новому сообщению даем этот msg_id
    else
        proto_fill(ctrl_msg);  // Иначе формируем новый msg_id
    
    // Отсылаем сообщение 
    ...
    
    // Если msg_id не был в _container_msg_id то произойдет попытка вставки msg_id полученного через proto_fill.
    if (!stored_msg_id && !_container_msg_id.insert(ctrl_msg.sequence, ctrl_msg.msg_id))
    {
        DEBUG(L, 0, "[%p] Can't store request's control message id (%llu) in bunch map" \
                    ", response's msg_id will differ", this, msg.msg_id);
    }

    С точки зрения читабельности кода, в последнем ветвлении говнокод?

    OlegUP, 15 Сентября 2020

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

    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
    #include <stdio.h>
    #include <csptr/smart_ptr.h>
    #include <csptr/array.h>
    
    void print_int(void *ptr, void *meta) {
        (void) meta;
        // ptr points to the current element
        // meta points to the array metadata (global to the array), if any.
        printf("%d\n", *(int*) ptr);
    }
    
    int main(void) {
        // Destructors for array types are run on every element of the
        // array before destruction.
        smart int *ints = unique_ptr(int[5], {5, 4, 3, 2, 1}, print_int);
        // ints == {5, 4, 3, 2, 1}
    
        // Smart arrays are length-aware
        for (size_t i = 0; i < array_length(ints); ++i) {
            ints[i] = i + 1;
        }
        // ints == {1, 2, 3, 4, 5}
    
        return 0;
    }

    Allocating a smart array and printing its contents before destruction.

    C Smart Pointers

    What this is
    This project is an attempt to bring smart pointer constructs to the (GNU) C programming language.

    Features: unique_ptr, shared_ptr macros, and smart type attribute

    https://github.com/Snaipe/libcsptr

    3.14159265, 15 Сентября 2020

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