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

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

    +31

    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
    #include <string>
    #include <iostream>
    #include <functional>
     
    using namespace std;
    
    template<class L, class... Ls>
    struct OL: L, OL<Ls...>{
       OL(const L& l, const Ls&... ls): L(l), OL<Ls...>(ls...){}
       using L::operator();
       using OL<Ls...>::operator();
    };
    
    template<class L1, class L2>
    struct OL<L1, L2>: L1, L2{
       OL(const L1& l1, const L2& l2): L1(l1), L2(l2){}
       using L1::operator();
       using L2::operator();
    };
    
    
    template<class... Ls>
    OL<Ls...> OverloadLambda(const Ls&... l){
       return OL<Ls...>(l...);
    }
    
    template<class L>
    L OverloadLambda(const L& l){
       return l;
    }
    
    void OverloadLambda(void) = delete;
    
    int main() {
       int i=5;
       auto lambda=OverloadLambda(  [=](int v){cout<<__func__<<" "<<i<<" "<<v<<" int"<<endl;},
                                    [=](string v){cout<<__func__<<" "<<i<<" "<<v<<" string"<<endl;},
                                    [=](float v){cout<<__func__<<" "<<i<<" "<<v<<" float"<<endl;});
       lambda(0);
       lambda("Hello");
       lambda(1.0f);
       i=600;
       auto lambda1=OverloadLambda( [=](int v){cout<<__func__<<" "<<i<<" "<<v<<" int"<<endl;});
       lambda1(4);
       ///*auto lambda0 =*/ OverloadLambda();
       return 0;
    }

    Специальная олимпиада объявляется открытой!
    http://ideone.com/y14z5Y
    Там много другого кода и какой-то из старых тем, а мне лень весь облазить.

    LispGovno, 03 Февраля 2014

    Комментарии (181)
  3. Lua / Говнокод #8651

    −340

    1. 1
    2. 2
    -- All scripts should begin at line
    null, Null, NULL = nil

    Lua

    istem, 26 Ноября 2011

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

    +128

    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
    static readonly Regex binary = new Regex("^[01]{1,32}$", RegexOptions.Compiled);
    static void Main() {
        Test("");
        Test("01101");
        Test("123");
        Test("0110101101010110101010101010001010100011010100101010");
    }
    static void Test(string s) {
        if (binary.IsMatch(s)) {
            Console.WriteLine(Convert.ToInt32(s, 2));
        } else {
            Console.WriteLine("invalid: " + s);
        }
    }

    http://stackoverflow.com/questions/1271562/binary-string-to-integer
    Мучает вопрос. Зачем ставить регулярку? Почему бы просто не словить FormatExeption?

    neeedle, 09 Июля 2013

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

    0

    1. 1
    Электрика / электроника #8

    #1: https://govnokod.ru/25437 https://govnokod.xyz/_25437
    #2: https://govnokod.ru/25820 https://govnokod.xyz/_25820
    #3: https://govnokod.ru/26570 https://govnokod.xyz/_26570
    #4: https://govnokod.ru/27622 https://govnokod.xyz/_27622
    #5: https://govnokod.ru/27741 https://govnokod.xyz/_27741
    #6: https://govnokod.ru/28191 https://govnokod.xyz/_28191
    #7: https://govnokod.ru/28630 https://govnokod.xyz/_28630

    nepeKamHblu_nemyx, 26 Июня 2023

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

    +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
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    #include <iostream>
    
    template<typename T>
    struct CrtpBase {
        static float base_func()
        {
            std::cout << "CrtpBase::base_func(), " << typeid(T).name() << "::int_field == "
                << T::int_field << std::endl;
            return 16.0f;
        }
    
        static inline float x = base_func();
    };
    
    struct A: public CrtpBase<A> {
        void func_a()
        {
            base_func();
        }
    
        static inline int int_field = 16;
    };
    
    struct B : public CrtpBase<B> {
        void func_b()
        {
            std::cout << "B::func_b(), no CrtpBase<B>::base_func() call" << std::endl;
        }
    };
    
    
    int main()
    {
        A a;
        a.func_a();
    
        B b;
        b.func_b();
    }

    [temp.inst]/2:
    Unless a class template specialization is a declared specialization,
    the class template specialization is implicitly instantiated when
    the specialization is referenced in a context that requires a
    completely-defined object type or when the completeness of the
    class type affects the semantics of the program.

    [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.

    [temp.inst]/4:
    Unless a member of a templated class is a declared specialization, the specialization
    of the member is implicitly instantiated when the specialization is referenced in a
    context that requires the member definition to exist or if the existence of the definition
    of the member affects the semantics of the program; in particular, the initialization
    (and any associated side effects) of a static data member does not occur unless the
    static data member is itself used in a way that requires the definition of the static
    data member to exist.


    Таким образом, по стандарту CrtpBase<B>::x не должен быть инициализирован, поскольку он нигде не used in a way that requires the definition of the static data member to exist. Правильные компиляторы (gcc и clang) это понимают и компилируют код, а вот Visual Studio зачем-то пытается инициализировать CrtpBase<B>::x и нон-конформно ломается.

    PolinaAksenova, 24 Марта 2021

    Комментарии (179)
  7. Си / Говнокод #26034

    +2

    1. 1
    2. 2
    Comparing structs with, let's say, memcmp, does not work,
     as you end up comparing the "unspecified" padding bytes as well — you must compare member-by-member.

    While writing this post, the author observed that some verions of GCC (experimentally, >= 4.7, < 8.0) do not zero padding if an empty intializer list is passed, under certain a certain code pattern; if an entire struct (i.e. sizeof(STRUCTNAME)) is subsequently memcpy'd after assigment of its members, and this intermediate buffer is what is used by the code going forward. This appears to be based on how optimization passes interact with GCC's built-in memcpy, since passing -fno-builtin-memcpy returns the behavior to the expected.
    https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2019/october/padding-the-struct-how-a-compiler-optimization-can-disclose-stack-memory/

    3.14159265, 18 Ноября 2019

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

    0

    1. 1
    2. 2
    Товарищ главный петух,
    Военный петух к проведению парада готов.

    BoeHHblu_nemyx, 08 Мая 2019

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

    +13

    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
    <?php
      $lines = file('quest.txt');
      if($_POST['Quest'] == "") {
        echo "<HTML>";
        echo "<HEAD>";
        echo "<TITLE>Тестер</TITLE>";
        echo "<script language=JavaScript type=text/javascript>";
        echo "<!-- " . "\n";
        echo "var differ = 90*60;";
        echo "function timer() {";
        echo "var hours, minutes, seconds;";
        echo "differ = differ - 1;";
        echo "document.forms['vopros'].TimeLeft.value=differ;";
        echo "hours = Math.floor(differ/(60*60));";
        echo "hours = (hours >= 60) ? hours%60 : hours;";
        echo "hours = (hours < 10) ? \"0\" + hours : hours;";
        echo "minutes = Math.floor(differ/(60));";
        echo "minutes = (minutes >= 60) ? minutes%60 : minutes;";
        echo "minutes = (minutes < 10) ? \"0\" + minutes : minutes;";
        echo "seconds = differ;";
        echo "seconds = (seconds >= 60) ? seconds%60 : seconds;";
        echo "seconds = (seconds < 10) ? \"0\" + seconds : seconds;";
        echo "var strDate =  hours + \":\" + minutes + \":\" + seconds;";
        echo "document.forms['timerForm'].timerBox.value=strDate;";
        echo "if (differ<=0) {";
        echo "  document.forms['vopros'].Quest.value=100;";
        echo "  vopros.submit();";
    ... (и так далее)

    Отличный кодец из дипломной работы студента!

    RigFox, 13 Ноября 2015

    Комментарии (179)
  10. Куча / Говнокод #14307

    +126

    1. 1
    shop_manager.WarnCurrentStoreNotTracked = Current store is not tracked. Please <a href="#" onclick="company.load_page(\'analytics/activate.html\', '{'\'{0}\': \'{1}\''}');">activate here</a> to start tracking.

    Файл properties в какой-то спринг-эм-вэ-цэ херне.

    wvxvw, 01 Января 2014

    Комментарии (179)
  11. Куча / Говнокод #14293

    +113

    1. 1
    2. 2
    Стартовал форум работы еще много,  тестить уже можно 
    http://gvforum.ru/

    Vasiliy, 28 Декабря 2013

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