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

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

    +50

    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
    #include <iostream>
    using namespace std;
    
    void f(int i)
    {
    	cout << "----" << endl;
    	void *array[] = { &&foo, &&bar, &&baz };
    	goto *array[i];
    	foo:
    	cout << "Foo" << endl;
    	bar:
    	cout << "Bar" << endl;
    	baz:
    	cout << "Baz" << endl;
    }
    
    int main() {
    	// your code goes here
    	f(0);
    	f(1);
    	f(2);
    	return 0;
    }

    http://ideone.com/63tRls
    gcc extension

    DlangGovno, 10 Ноября 2014

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

    +159

    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
    foreach ($val as $k => $v)
    		{
    			if (!is_array($v))
    			{
    				$val[$k] = htmlspecialcharsbx($v);
    			}
    			else
    			{
    				foreach ($v as $kp => $vp)
    				{
    					foreach ($vp as $kkp => $vvp)
    					{
    						if (!is_array($vvp))
    						{
    							$val[$k][$kp][$kkp] = htmlspecialcharsbx($vvp);
    						}
    						else
    						{
    							foreach ($vvp as $kvvp => $vvvp)
    							{
    								$val[$k][$kp][$kkp][$kvvp] = htmlspecialcharsbx($vvvp);
    							}
    						}
    					}
    				}
    			}
    		}

    clauclauclau, 14 Августа 2014

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

    +22

    1. 1
    2. 2
    3. 3
    4. 4
    list<int> list;
    ...
    for(auto i=0;i<list.size();i++){
        auto item = *next(list.begin(), i);

    Вчера у меня появился каллега.
    http://liveworkspace.org/code/1AWg24$5
    Кажется я знаю, кто следующий будет сидеть на табуретке. Думаете стоит сказать ему?

    LispGovno, 27 Января 2013

    Комментарии (108)
  5. Си / Говнокод #27880

    0

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <stdbool.h>
    
    struct two_val
    {
      const int32_t a[2];
    };
    
    struct two_val_and_status
    {
      const bool is_swap;
      const struct two_val t_v;
    };
    
    struct array
    {
      const int32_t a[10];
    };
    
    struct array_and_status
    {
      const bool is_swap;
      const size_t pos;
      const struct array arr;
    };
    
    // Эта суперфункцональная функция сортировки двух элементов не просто сортирует два элемента
    // но и еще сообщает о том, нужно ли было для этого обменивать два значения
    struct two_val_and_status sort2(const struct two_val a)
    {
      return (a.a[0] > a.a[1]) ? (struct two_val_and_status){true, {{a.a[1], a.a[0]}}} : (struct two_val_and_status){false, a};
    }
    
    struct two_val read_two_val(const struct array arr, const size_t pos)
    {
      return (struct two_val){{arr.a[pos], arr.a[pos+1]}};
    }
    
    struct array store_val(const struct array arr, const int32_t val, size_t pos)
    {
      return (struct array) // Царский анролл
      {{
        pos != 0 ? arr.a[0] : val,
        pos != 1 ? arr.a[1] : val,
        pos != 2 ? arr.a[2] : val,
        pos != 3 ? arr.a[3] : val,
        pos != 4 ? arr.a[4] : val,
        pos != 5 ? arr.a[5] : val,
        pos != 6 ? arr.a[6] : val,
        pos != 7 ? arr.a[7] : val,
        pos != 8 ? arr.a[8] : val,
        pos != 9 ? arr.a[9] : val
      }};
    }
    
    struct array store_two_val(const struct array arr, const struct two_val val, const size_t pos)
    {
      return store_val(store_val(arr,val.a[0],pos),val.a[1],pos+1);
    }
    
    // суперохуительная рекурсивная функция сортировки пузырьком
    struct array_and_status bubble_sort_rec(struct array_and_status state) 
    {
      if (state.pos == 9)
      {
        if (state.is_swap == false) // Ура! Сортировка пузырьком завершена!
        {
          return state;
        }
        else
        { // а иначе нам надо по-новой сортировать!
          return bubble_sort_rec((struct array_and_status){.is_swap = false, .pos=0, .arr = state.arr});
        }
      }
      else
      {
        const struct two_val_and_status tmp = sort2(read_two_val(state.arr, state.pos));
        return bubble_sort_rec(
          (struct array_and_status)
          {
            .is_swap = tmp.is_swap || state.is_swap,
            .pos=state.pos+1,
            .arr = store_two_val(state.arr, tmp.t_v, state.pos)
          }
        );
      }
    }
    
    int main(void)
    {
      const struct array_and_status a = {.is_swap = false, .pos = 0, .arr = {{8,2,4,1,3,5,7,0,6,9}} };
      const struct array_and_status a_sort = bubble_sort_rec(a);
      for(size_t i = 0; i < 10; i++) // ох уж это убогое императивное программирование!!!
      {
        printf("%" PRIu32 ", ", a_sort.arr.a[i]);
      }
      return EXIT_SUCCESS;
    }

    Функциональная сортировка пузырьком
    https://wandbox.org/permlink/dGyvo82lgQGInD0Y

    j123123, 19 Декабря 2021

    Комментарии (107)
  6. Куча / Говнокод #27055

    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
    // Define type
    define bottles_of_beer => type {
    
    	// Define internal data 
    	data private bottles = 99
    
    	// Define private methods
    	private br => '<br/>'
    	private s => .bottles != 1 ? 's' | ''
    	
    	// Generate lyrics when object represented as a string
    	public asstring => {
    
    		local(out = '')
    	
    		// Use Lasso query syntax to generate the lyrics
    	
    
    		with n in 99 to 1 by -1 do {
    			.bottles = #n
    			#out +=  .bottles + ' bottle' + .s + ' of beer on the wall, ' + .br
    			#out +=  .bottles + ' bottle' + .s + ' of beer; ' + .br
    			.bottles--
    			#out += 'Take one down, pass it around, ' + .br
    			#out += .bottles + ' bottle' + .s + ' of beer on the wall. ' + (.br * 2) 
    		}
    
    		// Return result
    		return #out
    	}
    }
    
    bottles_of_beer

    https://en.wikipedia.org/wiki/Lasso_(programming_language)

    MAKAKA, 24 Октября 2020

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

    +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
    #include <array>
    #include <iostream>
    using namespace std;
    
    
    int main() {
        ::array arr {1, 2, 3};
        int a, b, c;
        ::tie(a, b, c) = arr;
        printf("%d %d %d",a,b,c);
        return 0;
    }

    https://godbolt.org/z/RRmruC

    3.14159265, 25 Февраля 2020

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

    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
    public function comments()
        {
            $a = new common_articles($this);
    
            switch ($this->prms[3]) {
                case 'search':
                    {
                        break;
                    }
                default:
                    {
                        $where = array();
                        $itemid = 0;
     // и еще полторы сотни строк кода
                    }
            }
        }

    Параход такой параход...

    Arris, 06 Марта 2019

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Какой есть аналог класса для данных?
    
    class Record():
        pass
    
    r = Record()
    r. asd = 1
    
    Заебало класс объявлять, неужели для такого элементарного случая ничего не придумали?

    syoma, 25 Мая 2018

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

    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
    #include <stddef.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void *govno[300] = {NULL};
    
    size_t govnopoindex = 0;
    
    void chisti_govno(void)
    {
      do
      {
        free(govno[--govnopoindex]);
      } while (govnopoindex != 0);
    }
    
    
    char *concat(char *a, char *b)
    {
      char *ptr = malloc(strlen(a)+strlen(b)+4);
      if (ptr == NULL)
      {
        fprintf(stderr, "Huli ty obosralsya, mudak blyad? Ves' heap zasral\n");
        chisti_govno(); // иди под струю мойся
        exit(-1);
      }
      sprintf(ptr, "(%s*%s)", a, b);
      govno[govnopoindex++] = ptr;
      return ptr;
    }
    
    
    char *pow_gen(size_t n, char *a, char *p)
    {
      if (n == 0)
      {
        return a;
      }
      if (n & 1)
      {
        return pow_gen(n >> 1, concat(a, p), concat(p, p));
      }
      else
      {
        return pow_gen(n >> 1, a, concat(p, p));
      }
    }
    
    char* pow_b2(size_t n) {
      return pow_gen(n, "1", "a");
    }
    
    void printfshit(const size_t pow)
    {
      printf("double pow_%zu(double a) {return %s;}\n\n", pow, pow_b2(pow));
    }
    
    
    int main(void)
    {
      printfshit(255);
      chisti_govno();
      return 0;
    }

    http://govnokod.ru/23246#comment388959 - считаю что это заслуживает отдельного говнокода

    j123123, 10 Августа 2017

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

    +452

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    const CHANGE_TYPE_ADD        = 'add';//add elem in groups
        const CHANGE_TYPE_CHANGE    = 'change';//add elem
        const CHANGE_TYPE_RECHANGE    = 'rechange';//edit elem
        const CHANGE_TYPE_EDIT        = 'edit';//delete element from groups
        const CHANGE_TYPE_DEL        = 'del';//delete element

    Кручу-верчу, запутать хочу

    _dk, 19 Августа 2016

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