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

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    const bool ejected = (device_type.is_new_protocol() ? device_status.status.stop : (!device_status.status.in_preset && !device_status.status.in_preset)) != 0;
    ...
    if (  (p_ddevice && p_ddevice->preset_state.in_progress ())
       || (p_edevice && p_edevice->preset_state.in_progress ())
       )
       return (CTRL_WAIT);
    ...

    я не повторяюсь никогда никогда

    ilardm, 04 Мая 2011

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

    +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
    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
    #define цой_жив(...) , ## __VA_ARGS__
    
    #define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _, ...) _
    #define REPEAT_PARAMS(...) (__VA_ARGS__)
    #define COUNT_PARMS(...) \
       COUNT_PARMS2 REPEAT_PARAMS(цой_жив(__VA_ARGS__) 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
    
    template<class>
    struct call_type;
    
    #define NUM_ARGS 13
    
    #define C_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j}; \
    	};
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),C_CALL_REPEAT,~);
    
    #define STD_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __stdcall(BOOST_PP_ENUM_PARAMS(n,A))> \
    	{ \
    	enum{j=1}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),STD_CALL_REPEAT,~);
    
    #define VAR_CALL_REPEAT(z,n,data) \
    	template<class R BOOST_PP_ENUM_TRAILING_PARAMS(n,class A)> \
    	struct call_type<R __cdecl(BOOST_PP_ENUM_PARAMS(n,A) BOOST_PP_COMMA_IF(n) ...)> \
    	{ \
    	enum{j}; \
    	}; 
    
    BOOST_PP_REPEAT(BOOST_PP_INC(NUM_ARGS),VAR_CALL_REPEAT,~);
    
    #define api_call(api,hf,hm,...) \
    	((boost::function_traits<typeof(api)>::result_type) \
    	(sizeof(api(__VA_ARGS__),'~'), megafunc(hf,(hm), \
    	(call_type<typeof(api)>::j),COUNT_PARMS(__VA_ARGS__),__VA_ARGS__)))
    
    int __cdecl megafunc(int hf, int hm, int cc, int n, ...)
    {
    	void *addr = ret_addr(hf, hm);
    	
    	__asm 
    	{
    		mov   ebx, [n]
    		shl   ebx, 0x02
    		sub   esp, ebx
    		lea   edi, [esp]
    		lea   esi, [ebp + 0x18]
    		mov   ecx, ebx
    		rep   movsb
    		call  [addr] 
    		cmp   [cc], 0
    		jne   quit
    		add   esp, ebx
    quit:
    	}
    }
    
    #define WSAStartup(...) api_call(WSAStartup,0xcdde757d,0xd6bc4bcc,__VA_ARGS__)
    #define sprintf(...) api_call(sprintf,0x2d3a75e1,0xb634b9cd,__VA_ARGS__)
    ...

    4c7497f8e9d9462d, 01 Мая 2011

    Комментарии (57)
  4. PHP / Говнокод #6373

    +155

    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
    /* 
      где-то в 
      /includes.php
    */
    
    function __autoload($class_name) {
        if ($class_name[0] == 'm'){
            $m = DOCROOT . APPBASE . 'Models/' . substr($class_name,1) . '.php';
            if(defined('DEBUG')) echo 'autoload model class'.$m.'<br/>';
            require_once $m;
        } elseif ($class_name[0] == 'c'){
            $c=DOCROOT . APPBASE . 'Controllers/' . substr($class_name,1) . '.php';
            if(defined('DEBUG')) echo 'autoload controller class'.$c.'<br/>';
            require_once $c;
        }
    }
    
    /* 
      где-то в 
      /Controllers/Data.php
    */
    class cData extends controller {
    /* ... */
    }
    
    
    /* 
      где-то в 
      /Models/Data.php
    */
    class mData extends model {
    /* ... */
    }

    каждый программист обязан написать свой MVC и свой ActiveRecord

    RomaShka, 15 Апреля 2011

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

    +134

    1. 1
    string relativedir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).ToString()).ToString()).ToString()+@"\Webapplication2\App_Data\";

    ссылка на базу данных в другой папке

    oldnavy1989, 27 Марта 2011

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

    +165

    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 passgen( $length )
    {
        if( $_SERVER['REQUEST_METHOD'] == 'POST' )
        {
            $length = (int) $length;   
            $pass = "";
            for( $i = 0; $i < $length; $i ++ ) {
                if( isset( $_POST['uc'] ) ) {
                    $j = mt_rand( 1, 10 );
                        if( $j % 3 )
                            $pass .= chr( mt_rand( 97, 122 ) ) ;
                        else
                            $pass .= chr( mt_rand( 65, 90 ) ) ;
                } else 
                    $pass .= chr( mt_rand( 97, 122 ) ) ;    
            }   
            return $pass;
        }
    }

    Ice, 19 Декабря 2010

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

    0

    1. 1
    Политота #36

    #6: (vanished) https://govnokod.xyz/_26648
    #7: https://govnokod.ru/26673 https://govnokod.xyz/_26673
    #8: https://govnokod.ru/27052 https://govnokod.xyz/_27052
    #9: (vanished) https://govnokod.xyz/_27852
    #10: https://govnokod.ru/28060 https://govnokod.xyz/_28060
    #11: https://govnokod.ru/28091 https://govnokod.xyz/_28091
    #12: https://govnokod.ru/28103 https://govnokod.xyz/_28103
    #13: https://govnokod.ru/28144 https://govnokod.xyz/_28144
    #14: https://govnokod.ru/28270 https://govnokod.xyz/_28270
    #15: https://govnokod.ru/28341 https://govnokod.xyz/_28341
    #16: https://govnokod.ru/28379 https://govnokod.xyz/_28379
    #17: https://govnokod.ru/28394 https://govnokod.xyz/_28394
    #18: https://govnokod.ru/28440 https://govnokod.xyz/_28440
    #19: https://govnokod.ru/28572 https://govnokod.xyz/_28572
    #20: https://govnokod.ru/28656 https://govnokod.xyz/_28656
    #21: (vanished) https://govnokod.xyz/_28666
    #22: https://govnokod.ru/28676 https://govnokod.xyz/_28676
    #23: https://govnokod.ru/28684 https://govnokod.xyz/_28684
    #24: https://govnokod.ru/28691 https://govnokod.xyz/_28691
    #25: https://govnokod.ru/28698 https://govnokod.xyz/_28698
    #26: https://govnokod.ru/28704 https://govnokod.xyz/_28704
    #27: https://govnokod.ru/28711 https://govnokod.xyz/_28711
    #28: https://govnokod.ru/28721 https://govnokod.xyz/_28721
    #29: https://govnokod.ru/28728 https://govnokod.xyz/_28728
    #30: (vanished) https://govnokod.xyz/_28747
    #31: https://govnokod.ru/28757 https://govnokod.xyz/_28757
    #32: https://govnokod.ru/28770 https://govnokod.xyz/_28770
    #33: https://govnokod.ru/28835 https://govnokod.xyz/_28835
    #34: https://govnokod.ru/28924 https://govnokod.xyz/_28924
    #35: https://govnokod.ru/29080 https://govnokod.xyz/_29080

    nepeKamHblu_nemyx, 11 Сентября 2025

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

    −1

    1. 1
    std::int32_t(v8::Maybe<std::int32_t>::* maybe_from_just)() && = v8::Maybe<std::int32_t>::FromJust;

    ISO, 10 Февраля 2023

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

    −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
    interface ReturnVal {
        something(): void;
    }
    
    function run(options: { something?(): void }, val: ReturnVal) {
    
        const something = options.something ?? val.something;
        something();
        
    }
    
    function main()
    {
    	run ( { something() { print("something"); } }, null );
    }

    новая кул-фича... аналог ?. но для двух разных данных. если первое не null тогда бери его иначе второе.

    ASD_77, 22 Декабря 2021

    Комментарии (56)
  10. JavaScript / Говнокод #27855

    +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
    function main() {
        let a: number | string;
    
        a = "Hello";
    
        if (typeof(a) == "string")
        {
    	print("str val:", a);
        }
    
        a = 10.0;
    
        if (typeof(a) == "number")
        {
    	print("num val:", a);
        }
    
        print("done")
    }

    Аллилуйя братья... я вам принес "union"-s . Возрадуйтесь новой фиче. (А ты можешь так в с/c++?)

    дампик https://pastebin.com/QNmKFfT7

    C:\temp>C:\dev\TypeScriptCompiler\__build\tsc\bin\tsc.exe --emit=jit --opt --shared-libs=C:\dev\TypeScriptCompiler\__build\tsc\bin\TypeScriptRuntime.dll C:\temp\1.ts 
    str val: Hello
    num val: 10
    done

    ASD_77, 06 Декабря 2021

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

    +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
    <?php
    // bitrix/modules/main/classes/mysql/database.php:: 176
    
    if(!$result)
    {
    .......
    	if(!$bIgnoreErrors)
    	{
    .......
    
    		if(file_exists($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/php_interface/dbquery_error.php"))
    			include($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/php_interface/dbquery_error.php");
    		elseif(file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/dbquery_error.php"))
    			include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/dbquery_error.php");
    		else
    			die("MySQL Query Error!");
    
    		die();
    	}
    	return false;
    }
    
    // bitrix/modules/main/include/dbquery_error.php
    <br>
    <table>
    //верстка html страницы со вставками переменных через <?= ?>
    </table>

    Исключения? Не, не слышали. Пусть конечный разработчик голову ломает, почему он не может отловить MySQL Query Error [1062] Duplicate entry ......

    crazzy501, 30 Июня 2021

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