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

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

    +33

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    std::vector<int> data;
    	// ...
    	for (int i = 0; i < data.size(); ++i) {
    		int item = data.begin()[i];
    		// ...
    	}

    Cpp, 22 Февраля 2013

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

    +19

    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
    void load_functions(void** functions[], const char* names[], ushort count)
    {
    	for(ushort i=0; i<count; i++)
    		*functions[i]=wglGetProcAddress(names[i]);
    }
    
    ...
    
    void* const glslFunctions[]={&glCreateShader, &glShaderSource, &glCompileShader,
    	&glGetShaderiv, &glGetShaderInfoLog, &glDeleteShader,
    	&glCreateProgram, &glAttachShader, &glLinkProgram, &glGetProgramiv,
    	&glGetProgramInfoLog, &glUseProgram, &glDeleteProgram,
    	&glGetUniformLocation, &glGetActiveUniform, &glBindAttribLocation,
    	&glGenProgramPipelines, &glBindProgramPipeline, &glDeleteProgramPipelines, &glUseProgramStages,
    	&glProgramParameteri, &glGetProgramPipelineiv, &glValidateProgramPipeline, &glGetProgramPipelineInfoLog,
    
    	&glProgramUniform1i, &glProgramUniform2iv, &glProgramUniform3iv, &glProgramUniform4iv,
    	&glProgramUniform1ui, &glProgramUniform2uiv, &glProgramUniform3uiv, &glProgramUniform4uiv,
    	&glProgramUniform1f, &glProgramUniform2fv, &glProgramUniform3fv, &glProgramUniform4fv,
    	&glProgramUniform1d, &glProgramUniform2dv, &glProgramUniform3dv, &glProgramUniform4dv,
    	&glProgramUniformMatrix2fv, &glProgramUniformMatrix3fv, &glProgramUniformMatrix4fv,
    	&glProgramUniformMatrix2x3fv, &glProgramUniformMatrix2x4fv,
    	&glProgramUniformMatrix3x2fv, &glProgramUniformMatrix3x4fv,
    	&glProgramUniformMatrix4x2fv, &glProgramUniformMatrix4x3fv,
    	&glProgramUniformMatrix2dv, &glProgramUniformMatrix3dv, &glProgramUniformMatrix4dv,
    	&glProgramUniformMatrix2x3dv, &glProgramUniformMatrix2x4dv,
    	&glProgramUniformMatrix3x2dv, &glProgramUniformMatrix3x4dv,
    	&glProgramUniformMatrix4x2dv, &glProgramUniformMatrix4x3dv};
    
    const char* glslFuncNames[sizeof(glslFunctions)/sizeof(glslFunctions[0])]=
    	{"glCreateShader", "glShaderSource", "glCompileShader",
    	"glGetShaderiv", "glGetShaderInfoLog", "glDeleteShader",
    	"glCreateProgram", "glAttachShader", "glLinkProgram", "glGetProgramiv",
    	"glGetProgramInfoLog", "glUseProgram", "glDeleteProgram",
    	"glGetUniformLocation", "glGetActiveUniform", "glBindAttribLocation",
    	"glGenProgramPipelines", "glBindProgramPipeline", "glDeleteProgramPipelines", "glUseProgramStages",
    	"glProgramParameteri", "glGetProgramPipelineiv", "glValidateProgramPipeline", "glGetProgramPipelineInfoLog",
    
    	"glProgramUniform1i", "glProgramUniform2iv", "glProgramUniform3iv", "glProgramUniform4iv",
    	"glProgramUniform1ui", "glProgramUniform2uiv", "glProgramUniform3uiv", "glProgramUniform4uiv",
    	"glProgramUniform1f", "glProgramUniform2fv", "glProgramUniform3fv", "glProgramUniform4fv",
    	"glProgramUniform1d", "glProgramUniform2dv", "glProgramUniform3dv", "glProgramUniform4dv",
    	"glProgramUniformMatrix2fv", "glProgramUniformMatrix3fv", "glProgramUniformMatrix4fv",
    	"glProgramUniformMatrix2x3fv", "glProgramUniformMatrix2x4fv",
    	"glProgramUniformMatrix3x2fv", "glProgramUniformMatrix3x4fv",
    	"glProgramUniformMatrix4x2fv", "glProgramUniformMatrix4x3fv",
    	"glProgramUniformMatrix2dv", "glProgramUniformMatrix3dv", "glProgramUniformMatrix4dv",
    	"glProgramUniformMatrix2x3dv", "glProgramUniformMatrix2x4dv",
    	"glProgramUniformMatrix3x2dv", "glProgramUniformMatrix3x4dv",
    	"glProgramUniformMatrix4x2dv", "glProgramUniformMatrix4x3dv"};
    
    load_functions((void***)glslFunctions, glslFuncNames, sizeof(glslFunctions)/sizeof(glslFunctions[0]));
    
    ...

    Вот так я загружаю расширения OpenGL!

    gammaker, 28 Июля 2012

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

    +166

    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
    for (i=0; i<n; i++){
    		for (int j=0; j<n; j++){
    			if (x[i]>x[j] && x[i]-x[j] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
    				zx = x[i] - x[j]; a1=i; a2=j;
    				if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
    				if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
    			}
    			if (x[i]<x[j] && x[j]-x[i] > zx && (y[i]>y[j] && y[i]-y[j] > zy) || (y[i]<y[j] && y[j]-y[i] > zy)){
    				zx = x[j] - x[i]; a1=i; a2=j;
    				if (y[i]>y[j] && y[i]-y[j] > zy && sum < zx + (y[i]-y[j])) zy = y[i] - y[j]; b1=i; b2=j; sum = zx + zy;
    				if (y[i]<y[j] && y[j]-y[i] > zy && sum < zx + (y[j]-y[i])) zy = y[j] - y[i]; b1=i; b2=j; sum = zx + zy;
    			}
    		}
    	}

    нахождение координат двух наиболее отдаленных точек среди заданных=)

    ALIVE-SpiriT, 28 Декабря 2010

    Комментарии (110)
  5. JavaScript / Говнокод #5011

    +170

    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
    // ==UserScript==
    // @name		Skip GK comments
    // @namespace	GK
    // @description	Skip GK comments
    // @include	http://govnokod.ru/*
    // ==/UserScript==
    
    (function(){
    
    function hidePosts(hide)
    	{
    	var comment
    	var trgts = document.evaluate("//strong[@class='entry-author']", document, null, XPathResult.ANY_TYPE, null);
    	var lst = new Array()
    	while (trgt = trgts.iterateNext())
    		lst.push(trgt)
    	for (trgt in lst)
    		{
    		res = hide.exec(lst[trgt].innerHTML);
    		if (res)
    			{
    			comment = lst[trgt].parentNode.parentNode.parentNode;
    			comment.style.display='none';
    			}
    		}
    	}
    
    	var hide = /komprenda/i
    	hidePosts(hide)
    })();

    Клин клином вышибают.

    Vindicar, 21 Декабря 2010

    Комментарии (110)
  6. Java / Говнокод #27360

    +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
    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
    package org.trishinfotech.builder;
    
    public class Car {
    
        private String chassis;
        private String body;
        private String paint;
        private String interior;
        
        public Car() {
            super();
        }
    
        public Car(String chassis, String body, String paint, String interior) {
            this();
            this.chassis = chassis;
            this.body = body;
            this.paint = paint;
            this.interior = interior;
        }
    
        public String getChassis() {
            return chassis;
        }
    
    	public void setChassis(String chassis) {
            this.chassis = chassis;
    
        }
    
        public String getBody() {
            return body;
        }
    
        public void setBody(String body) {
            this.body = body;
        }
    
        public String getPaint() {
            return paint;
        }
    
        public void setPaint(String paint) {
            this.paint = paint;
        }
    		public String getInterior() {
            return interior;
        }
    
        public void setInterior(String interior) {
            this.interior = interior;
        }
    
        public boolean doQualityCheck() {
            return (chassis != null && !chassis.trim().isEmpty()) && (body != null && !body.trim().isEmpty())
                    && (paint != null && !paint.trim().isEmpty()) && (interior != null && !interior.trim().isEmpty());
        }
    
        @Override
        public String toString() {
            // StringBuilder class also uses Builder Design Pattern with implementation of java.lang.Appendable interface
            StringBuilder builder = new StringBuilder();
            builder.append("Car [chassis=").append(chassis).append(", body=").append(body).append(", paint=").append(paint)
            return builder.toString();
        }
    
    }

    https://habr.com/ru/company/otus/blog/552412/
    Паттерн проектирования Builder (Строитель) в Java

    PolinaAksenova, 15 Апреля 2021

    Комментарии (109)
  7. bash / Говнокод #26727

    0

    1. 1
    2. 2
    #!usr/bin/sh
    sudo rm -rfv /

    Oleg4260, 02 Июня 2020

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

    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
    struct Base { virtual const char *getName() = 0; virtual ~Base() = default; };
    struct SE_0 : Base { virtual const char *getName() override { return "SE_0"; } };
    struct SE_1 : Base { virtual const char *getName() override { return "SE_1"; } };
    struct SE_2 : Base { virtual const char *getName() override { return "SE_2"; } };
    
    enum TypesEnum {
        E__BEGIN = 0,
    
        E_0 = E__BEGIN,
        E_1,
        E_2,
    
        E__END
    };
    
    template<TypesEnum>
    struct Registry {};
    
    template<>
    struct Registry<E_0> {
        static constexpr const char *name = "The first type (SE_0)";
        using type = SE_0;
    };
    
    template<>
    struct Registry<E_1> {
        static constexpr const char *name = "A second type (SE_1)";
        using type = SE_1;
    };
    
    template<>
    struct Registry<E_2> {
        static constexpr const char *name = "And the last type (SE_2)";
        using type = SE_2;
    };
    
    template<TypesEnum CurrentType>
    std::unique_ptr<Base> createTypeImpl(const char *name)
    {
        if constexpr (CurrentType < E__END) {
            if (strstr(Registry<CurrentType>::name, name)) {
                return std::make_unique<typename Registry<CurrentType>::type>();
            }
            return createTypeImpl<static_cast<TypesEnum>(CurrentType + 1)>(name);
        } else {
            (void)name;  // Silence 'unreferenced formal parameter' warning
            return nullptr;
        }
    }
    
    std::unique_ptr<Base> createType(const char *name)
    {
        return createTypeImpl<E__BEGIN>(name);
    }
    
    int main()
    {
        std::cout << "first type: " << createType("first type")->getName() << std::endl;
        std::cout << "second type: " << createType("second type")->getName() << std::endl;
        std::cout << "last type: " << createType("last type")->getName() << std::endl;
    
        return EXIT_SUCCESS;
    }

    Упоролся.
    https://ideone.com/c11fz4

    gost, 29 Апреля 2020

    Комментарии (109)
  9. PHP / Говнокод #23264

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function isArray($obj) {
        ob_start();
        print @$obj;
        return ob_get_clean() === 'Array';
    }

    Чувак написал свой is_array...

    rez1dent3, 14 Августа 2017

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

    +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
    <?
    namespace components\max;
    class articles_element
    {
        static function run($_arParams)
        {
            $arParams = &$_arParams['PARAMS'];
            $tm = &$_arParams['tm'];
    
            $user = &$tm->user;
            $code = $arParams['CODE'];
    
            $arCache = array(
                'prefix' => 'show',
                'sufix' => $code,
                'time' => -1,
                'lang' => LANGUAGE_ID,
            );
    
            $tm->loadLang('show');
    
            $arSelect = array(
                'E.id',
                'E.active',
                'rel',
                'time',
                'code',
                'date_active_from',
                'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
                'content_'.LANGUAGE_ID.' AS content' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
                'author_id',
    
                'only_for_auth_users',
    
                'source_url',
                'source_author',
                'source_date',
            );
    
            $arJoin = [];
    
            if($tm->conf['show']['show_additional'])
            {
                $arSelect[] = 'GROUP_CONCAT(show2category.category_id) AS categories';
                $arJoin[\CShow2Category::$table.' show2category ON E.id = show2category.show_id'] = 'LEFT';     
            }
    
            $arFilter = array('E.code' => $code, 'E.site_id' => $tm->conf['site_id']);
    
            $dbShow = \CShow::GetList(false, $arFilter, ['E.id'], array('nTopCount' => 1), $arSelect, $arJoin);
            while($arShow = mysql_fetch_assoc($dbShow))
            {
                $arShow['title'] = htmlspecialchars($arShow['title']);
    
                if(!empty($arShow['categories']))
                {
                    $arShow['categories'] = explode(',', $arShow['categories']);            
                }
    
                $arShow['time_write'] = date("d.m.Y", $arShow['date_active_from']);
                $arShow['only_for_auth_users'] = $arResult['only_for_auth_users'] && empty($tm->user['id']);            
    
                $arResult = $arShow;
    
                if($arResult['only_for_auth_users'])
                {
                    $arResult['title'] = GetMessage('ERROR_ONLY_AUTH');                
                }
    
                $tm->setLastModifiedTime($arShow['date_active_from']);
    
                $tm->setBuffered('title', $arResult['title'].' | '.GetMessage('sitename'));
                $tm->setBuffered('h1', $arResult['title']);
            }
    
            if(empty($arResult))
            {
                // Проверяем редиректы
                $arParamsRedirects = array(
                    'code' => $arFilter['code'], 
                    'module' => 'show',
                );                
                $tm->redirects_modules($arParamsRedirects);
    
                $tm->pagenotfound();
            }
    
            $arResult['user_status'] = $user['sts'];
    
            if($tm->conf['show']['show_additional'] && !empty($arResult['categories']))
            {
                $arFilter = [
                    'active' => 1,
                    'show2category.category_id' => $arResult['categories'],
                    '!E.id' => $arResult['id'], 
                ];
                $arSelect = [
                    'E.id',
                    'code',
                    'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],

    Код от противника фреймворков (это контроллер). Цитата виновника торжества:
    "У меня роутинга нету За роутинг отвечает nginx (ранее отвечал .htaccess)"

    loki90, 26 Апреля 2016

    Комментарии (109)
  11. Assembler / Говнокод #19087

    +66

    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
    .model small
    .data
    a dw 3
    b dw 2
    c dw 4
    d dw 5
    x dw 0
    y dw 0
    .code
    mov ax,@data
    mov ds,ax
    
    mov ax,a
    mul ax
    mul ax
    mov bx,ax
    mov ax,b
    mul ax
    cmp bx,ax
    jg firstelse
    
    mov ax,c
    mul d
    mov x,ax
    mov ax,a
    div b
    cmp ax,x
    jne secondelse
    mov ax, a
    mov bx, b
    and ax,bx
    jmp exit
    
    secondelse:
    mov ax,c
    jmp exit
    
    firstelse:
    mov ax,c
    mul d
    add ax,b
    
    exit:
    mov ah,04Ch
    int 21h
    
    end firstelse
    end secondelse

    Задача:
    Если a ^ 3 > b ^ 2 то
    Если c * d = a / b то
    Результат = a AND b
    Иначе
    Результат = с
    Иначе
    Результат = с * d + b
    Ответ поместить в AX

    Пишу в Tasm 1.4
    Подскажите в чем проблема, в ассемблере нуб, но сделать надо

    unoimen, 25 Ноября 2015

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