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

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

    +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
    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
    // A registrator class.
    // To register a Parents <- Child relation user must derive their type from
    // the correct specialization of this class
    template<typename Child, typename... Parents>
    struct registrator {
    private:
        // The registerRelation() function would be called during dynamic initialization of this
        // static storage duration variable.
        static volatile inline detail::registratorType _registrator
            = RelationManager::registerRelation<Child, Parents...>();
    
    protected:
        /*
        [basic.start.dynamic]/6:
            It is implementation-defined whether the dynamic initialization of a non-block inline variable
            with static storage duration is sequenced before the first statement of main or is deferred.
            If it is deferred, it strongly happens before any non-initialization odr-use of that variable.
        [basic.start.dynamic]/4:
            A non-initialization odr-use is an odr-use ([basic.def.odr]) not caused directly or indirectly
            by the initialization of a non-block static or thread storage duration variable.
        By odr-using the _registrator here we are making sure that any Child constructor is odr-using it as well,
        thus guaranteeing that the compiler would call registerRelation() strongly before the Child constructor
        */
        constexpr registrator() noexcept
        {
            // Taking an address of a variable, even in a discarded statement, is an odr-use
            (void)&_registrator;
        }
    
    private:
        /*
        If registrator() constructor is never 'non-initialization odr-used'
        (no Child objects are created besides non-local static ones), then the only
        instantiation of the registrator class is an implicit instantiation caused by deriving Child;
    
        [temp.inst]/3:
            The implicit instantiation of a class template specialization causes
            (3.1) -- the implicit instantiation of the declarations, but not of the definitions, of
                the non-deleted class member functions, member classes, scoped member enumerations,
                static data members, member templates, and friends; and
            (3.2) -- the implicit instantiation of the definitions of deleted member functions,
                unscoped member enumerations, and member anonymous unions.
    
        [basic.def.odr]/8:
            [...] A constructor for a class is odr-used as specified in [dcl.init].
        (In other words, "A constructor (including default constructors) for a class
         is odr-used by the initialization that selects it.")
    
        The problem is that if there is no Child() constructor calls, then the compiler is not required to
        even DEFINE our registrator() constructor, and since there is only one odr-use of the static inline
        variable _registrator, the compiler is not required to generate a definition for it as well. And since
        it is not generating a definition, the initialization is also not generated.
    
        But [temp.inst]/3.2 requires that any implicit instantiation of a class template also
        causes the DEFINITION instantiation of an unscoped member enumerations. Next,
        [dcl.spec.auto.general]/12:
            Return type deduction for a templated entity that is a function or function template
            with a placeholder in its declared type occurs when the definition is instantiated
            even if the function body contains a return statement with a non-type-dependent operand
        Thus, using sizeof(*_force_registrator_instantiation()) causes the implicit instantiation
        of definition of _force_registrator_instantiation(), and since this function is odr-using _registrator,
        its definition (and initialization) is also generated.
    
        The only problem is that by [basic.start.dynamic]/6 the implementation MAY defer the dynamic
        initialization of _registrator to the point where it is 'non-initialization odr-used', and since without
        the Child() constructor call we don't have any way to non-initialization odr-use it, we also have no way to
        make sure that the compiler invokes registerRelation() before main() or before any other point of execution.
        The good news, though, is that all three modern compilers obediently initializes _registrator before the first
        statement of main().
        */
        static auto _force_registrator_instantiation()
        {
            return &_registrator;
        }
    
        enum {
            _ROTARTSIGER_ETAITNATSNI = sizeof(*_force_registrator_instantiation()),
        };
    };

    PolinaAksenova, 23 Марта 2021

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

    +1

    1. 1
    if (tableOfVariables[i].Name == "replace".ToUpper())

    )))00

    neonmystery, 19 Ноября 2019

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

    0

    1. 1
    Зачем "\r", если достаточно "\n"?

    SteadfastTinCock, 09 Июля 2019

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

    0

    1. 1
    Я забыл теорию графов, но вот недавно читал про магазинный автомат, а вы?

    OlegUP, 17 Апреля 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    if (!isset($this->parent->parent->CONFIG['DIR'])) {
                    $this->parent->parent->CONFIG['DIR'] = $this->parent->CONFIG['DIR'];
                    $this->parent->parent->CONFIG['fqdn'] = $this->parent->CONFIG['fqdn'];
    }

    посадил дед репку...

    Arris, 01 Апреля 2019

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

    −10

    1. 1
    https://i.imgur.com/2GTA40l.png

    j123123, 07 Октября 2018

    Комментарии (51)
  8. Си / Говнокод #24840

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    #include <stdio.h>
    #include <math.h>
    char s[6];
    main(){
    	puts(gets(s)[2]==45&8u>*s-65&8u>s[1]-49&8u>s[3]-65&8u>s[4]-49?abs((*s-s[3])*(s[1]-s[4]))-2?"NO":"YES":"ERROR");
    }

    666_N33D135, 01 Октября 2018

    Комментарии (51)
  9. bash / Говнокод #23589

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #!/bin/sh
    while true; do
        date "+Time is %H %M. Stop lurking and get the fuck to work" | say
        sleep 1800
    done

    Я наконец нашёл применение встроенному в OS X TTS-движку.

    CHayT, 15 Декабря 2017

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public do(action: 'un' | 're'): void {
        const result = (<any>this._appApi.app.documentManager.current)[action + 'do']();
        if (!result.success) this._toastService.error(result.errorMessage, `Ошибка ${action}do`);
    }
    
     <button (click)="do('un')" title="Отменить"><i class="material-icons md-36">undo</i></button>
     <button (click)="do('re')" title="Повторить"><i class="material-icons md-36">redo</i></button>

    mazhuravlev, 01 Ноября 2017

    Комментарии (51)
  11. C++ / Говнокод #19588

    +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
    switch (a) {
    	case 12345:
    		return 0;
    	case 14523:
    		return 1;
    	case 102543:
    		return 2;
    	case 104325:
    		return 3;
    	case 243051:
    		return 4;
    	case 245130:
    		return 5;
    	case 350214:
    		return 6;
    	case 351402:
    		return 7;
    	case 423150:
    		return 8;
    	case 425031:
    		return 9;
    	case 530412:
    		return 10;
    	case 531204:
    		return 11;
    	}
    	return -1;

    Ekke, 07 Марта 2016

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