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

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

    +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
    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
    #include <iostream>
    #include <memory>
    #include <assert.h>
    using namespace std;
     
    template <class T>
    class megaClass
    {
    public:
     
        void hello()
        {
            assert(dynamic_cast<T*>(this)!=NULL);
            static_cast<T*>(this)->hello();
        }
        virtual ~megaClass() {}
    };
     
    class cleft : public megaClass<cleft>
    {
    public:
     
        void hello()
        {
            std::cout << "left::hello()" << std::endl;
        }
    };
     
    class cright : public megaClass<cright>
    {
    public:
     
        void hello()
        {
            std::cout << "right::hello()" << std::endl;
        }
    };
     
     
    int main()
    {
        scoped_ptr<megaClass<cleft> > a1=new cleft;
        a1->hello();
        scoped_ptr<megaClass<cright> > a2=new cright;
        a2->hello();
        
        return 0;
    }

    Пытался продемонстрировать статический полиморфизм TarasB и получилась такая какашка. Кто действительно крут и может сабдж продемонстрировать? Я где-то видел пример, но не помню где...

    Ещё продемонстрировал статический полиморфизм через стратегии:

    struct Strategy1
    {
    static void do(){printf("Lol1");}
    };
    struct Strategy2
    {
    static void do(){printf("Lol2");}
    };
    template<class Strategy>
    class MegaClass
    {public:
    void do()
    {
    printf("Mega");
    Strategy::do();//Класс Strategy можно было и создать для хранения состояния.
    printf("/n\");
    }
    };
    //...

    Дальше в разных частях кода создаем:
    MegaClass<Strategy1> o;
    o.do();
    //...
    MegaClass<Strategy2> o;
    o.do();
    "Один" класс ведёт себя по разному. Понятно, что это не совсем полиморфизм. Но очень часто именно в таком контексте используют динамический полиморфизм, хотя такого статического здесь достаточно выше крыши.
    Плюсы этого подхода :
    1)Создаётся объект в стеке, значит быстро, а не в куче. Хотя можно и не в стеке.
    2)Используется шаблон, значит компиль будет инлайнить.

    Минус:
    1)Если понадобится резкой перейти от статического полиморфизма к динамическому - придётся переписывать на виртуальные функции или на истинный статический полиморфизм.

    Обсуждения здесь:
    http://govnokod.ru/8025#comment110773


    Сразу исключим детсадовский вариант статического функционального полиморфизма c перегрузкой функций:
    Class1 o1;
    foo(o1);
    Class2 o2;
    foo(o2);

    void foo(Class1 o){/*...*/};
    void foo(Class2 o){/*...*/};



    Кто-нибудь реально умеет can into нормальный статический полиморфизм?

    CPPGovno, 30 Сентября 2011

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    void f_ai(intrusive_ptr<serial> i);
    //...
    static serial ai;
    serial* ii=&ai;
    //...
    f_ai(ii);

    Компилируется, а потом грохается. С++ такой Си...

    CKrestKrestGovno, 25 Сентября 2011

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

    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
    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
    <?php
    error_reporting(0);
    ini_set('display_errors', '0');
    mb_internal_encoding('UTF-8');
    header('Access-Control-Allow-Origin: *');
    function str_replace_first($from, $to, $subject){
    $from='/'.preg_quote($from, '/i').'/';
    return preg_replace($from, $to, $subject, 1);
    }
    require_once('morphy/src/common.php');
    $opts=array(
    'storage'=>PHPMORPHY_STORAGE_MEM,
    'predict_by_suffix'=>true, 
    'predict_by_db'=>true,
    'graminfo_as_text'=>true
    );
    $dir='morphy/dicts';
    $lang='ru_RU';
    try{
    $morphy=new phpMorphy($dir, $lang, $opts);
    }catch(phpMorphy_Exception $e){
    die('Error occurred while creating phpMorphy instance: '.PHP_EOL.$e);
    }
    $morphy->getDefaultGrammemsProvider()->excludeGroups('С', 'род');
    $wanal=array();
    $wanal['p']=explode(' : ', file_get_contents('wanal_p.txt'));
    $wanal['s']=explode(' : ', file_get_contents('wanal_s.txt'));
    $wanal['g']=explode(' : ', file_get_contents('wanal_g.txt'));
    shuffle($wanal['p']);
    shuffle($wanal['s']);
    shuffle($wanal['g']);
    $current_wanal=$wanal;
    $string=trim($_GET['q']);
    $modified_comment=$string;
    preg_match_all('/(\w+)/u', str_replace('_', '', $string), $matches);
    $words=$matches[1];
    foreach($words as $word){
    if(mb_strtoupper($word)=='НАХУЙ' || mb_strtoupper($word)=='ХУЙ' || mb_strtoupper($word)=='ТУТ'){
    continue;
    }
    $info=$morphy->getGramInfo(mb_strtoupper($word));
    $type='';
    if(trim($info[0][0]['pos'])=='П'){
    $type='p';
    }
    if(trim($info[0][0]['pos'])=='С'){
    $type='s';
    }
    if(trim($info[0][0]['pos'])=='Г' || trim($info[0][0]['pos'])=='ИНФИНИТИВ'){
    $type='g';
    }
    if($type!=''){
    $replacement=trim($current_wanal[$type][array_rand($wanal[$type])]);
    if($replacement!=''){
    $casted=$morphy->castFormByPattern(mb_strtoupper($replacement), mb_strtoupper($word), null, true);
    if(count($casted)>0){
    $replacement=reset($casted);
    if(md5(mb_substr($word, 0, 1))==md5(mb_strtolower(mb_substr($word, 0, 1)))){
    $replacement=mb_strtolower($replacement);
    } elseif(md5(mb_strtoupper($word))==md5($word)){
    $replacement=mb_strtoupper($replacement);
    } elseif(md5(mb_substr($word, 0, 1))==md5(mb_strtoupper(mb_substr($word, 0, 1)))){
    $replacement=mb_convert_case(mb_strtolower($replacement), MB_CASE_TITLE);
    }
    $modified_comment=str_replace_first($word, $replacement, $modified_comment);
    $base=$morphy->getBaseForm(mb_strtoupper($word));
    if($base){
    $wanal[$type][]=mb_strtoupper($base[0]);
    $wanal[$type]=array_filter(array_unique($wanal[$type]));
    }
    }
    }
    }
    }
    file_put_contents('wanal_p.txt', implode(' : ', $wanal['p']));
    file_put_contents('wanal_s.txt', implode(' : ', $wanal['s']));
    file_put_contents('wanal_g.txt', implode(' : ', $wanal['g']));
    echo $modified_comment;
    ?>

    Какой-то такой модификатор чужих комментариев на основе ещё более ранних комментариев.

    g0_1494089148657, 14 Февраля 2018

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

    +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
    [0mSaving to: ���jdk-8u131-linux-x64.tar.gz���
    
      2050K .......... .......... .......... .......... ..........  1%  137K 4m16s
      2100K .......... .......... .......... .......... ..........  1% 1.06M 4m14s
      2150K .......... .......... .......... .......... ..........  1%  613K 4m14s
      2200K .......... .......... .......... .......... ..........  1%  318M 4m9s
      2250K .......... .......... .......... .......... ..........  1%  609K 4m10s
      2300K .......... .......... .......... .......... ..........  1%  612K 4m10s
      2350K .......... .......... .......... .......... ..........  1%  610K 4m11s
      2400K .......... .......... .......... .......... ..........  1%  612K 4m12s
      2450K .......... .......... .......... .......... ..........  1%  612K 4m13s
      2500K .......... .......... .......... .......... ..........  1%  616K 4m13s
      2550K .......... .......... .......... .......... ..........  1%  616K 4m14s
      2600K .......... .......... .......... .......... ..........  1%  614K 4m15s
      2650K .......... .......... .......... .......... ..........  1%  644K 4m15s
      2700K .......... .......... .......... .......... ..........  1% 1.15M 4m13s
      2750K .......... .......... .......... .......... ..........  1% 1.07M 4m11s
      2800K .......... .......... .......... .......... ..........  1%  306K 4m17s
      2850K .......... .......... .......... .......... ..........  1%  181M 4m13s
      2900K .......... .......... .......... .......... ..........  1%  307K 4m18s
      2950K .......... .......... .......... .......... ..........  1%  608K 4m19s
      3000K .......... .......... .......... .......... ..........  1%  421K 4m21s
      3050K .......... .......... .......... .......... ..........  1%  400K 4m24s
      3100K .......... .......... .......... .......... ..........  1%  605K 4m25s
      3150K .......... .......... .......... .......... ..........  1%  613K 4m25s
      3200K .......... .......... .......... .......... ..........  1%  611K 4m25s
      3250K .......... .......... .......... .......... ..........  1%  303K 4m30s
      3300K .......... .......... .......... .......... ..........  1% 1.34M 4m28s
      3350K .......... .......... .......... .......... ..........  1%  306K 4m32s
      3400K .......... .......... .......... .......... ..........  1%  394K 4m35s
      3450K .......... .......... .......... .......... ..........  1%  416K 4m37s
      3500K .......... .......... .......... .......... ..........  1%  401K 4m39s
      3550K .......... .......... .......... .......... ..........  1%  413K 4m41s
      3600K .......... .......... .......... .......... ..........  2%  421K 4m43s
      3650K .......... .......... .......... .......... ..........  2%  611K 4m43s
      3700K .......... .......... .......... .......... ..........  2%  610K 4m43s
      3750K .......... .......... .......... .......... ..........  2%  574K 4m43s
      3800K .......... .......... .......... .......... ..........  2%  610K 4m43s
      3850K .......... .......... .......... .......... ..........  2%  610K 4m43s
      3900K .......... .......... .......... .......... ..........  2%  611K 4m43s
      3950K .......... .......... .......... .......... ..........  2%  651K 4m43s
      4000K .......... .......... .......... .......... ..........  2%  613K 4m43s
      4050K .......... .......... .......... .......... ..........  2%  612K 4m43s
      4100K .......... .......... .......... .......... ..........  2% 1.08M 4m42s

    Дженкинс прислал телеграму: девопс потрудился наславу.
    (это только 0.5% от всего сообщения)

    wvxvw, 08 Ноября 2017

    Комментарии (115)
  6. bash / Говнокод #18124

    −79

    1. 1
    alias ffcp='perl -e '"'"'exec "ffmpeg","-i",$ARGV[0],"-sn","-vcodec","copy","-acodec","copy",$ARGV[1]'"'"

    Так и не придумал, как сделать что-то подобное на голом пердобаше, не плодя говноскрипты в файловой системе. -_-

    Stallman, 06 Мая 2015

    Комментарии (115)
  7. SQL / Говнокод #5979

    −851

    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
    select distinct bk.ID, bk.URL, bk.Date, bk.Name, bk.Description, bk.UserCreatorID from bookmarking_bookmark as bk 
    where bk.Tenant=@Tenant and bk.ID in 
    (select *  from (select b.ID  from bookmarking_bookmark as b  left join  bookmarking_bookmarktag as bt on b.ID=bt.BookmarkID left join bookmarking_tag as t  on bt.TagID=t.TagID 
    left join (select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName,ub.Description as UserBookmarkDescription, t.Name as TagName  
    from (select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub 
    left join bookmarking_userbookmarktag as ubt  on ub.UserBookmarkID=ubt.UserBookmarkID  
    left join bookmarking_tag as t  on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID 
    where  ( ( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash0) )  
    or (lower(b.Name) like lower(@tagName0) or lower(b.Name) like lower(@tagNameWithSpace0)) 
    or (lower(b.Description) like lower(@tagName0) or lower(b.Description) like lower(@tagNameWithSpace0))    
    or (lower(t.Name) like lower(@tagName0)) or (lower(t.Name)  like lower(@tagNameWithSpace0)) 
    or (lower(TagName) like lower(@tagName0)) or (lower(TagName) like lower(@tagNameWithSpace0))    
    or (lower(UserBookmarkName) like lower(@tagName0) or lower(UserBookmarkName) like lower(@tagNameWithSpace0))    
    or (lower(UserBookmarkDescription) like lower(@tagName0) or lower(UserBookmarkDescription) like lower(@tagNameWithSpace0)))  
    and b.ID in (
    select b.ID   from bookmarking_bookmark as b  left join  bookmarking_bookmarktag as bt  on b.ID=bt.BookmarkID
    left join bookmarking_tag as t    on bt.TagID=t.TagID 
    left join  (
    select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName, ub.Description as UserBookmarkDescription, t.Name as TagName from 
    (select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub  
    left join bookmarking_userbookmarktag as ubt on ub.UserBookmarkID=ubt.UserBookmarkID
    left join bookmarking_tag as t on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID
    where  (( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash1) ) or (lower(b.Name) like lower(@tagName1) or lower(b.Name) like lower(@tagNameWithSpace1)) 
    or (lower(b.Description) like lower(@tagName1) or lower(b.Description) like lower(@tagNameWithSpace1)) or (lower(t.Name) like lower(@tagName1)) 
    or (lower(t.Name)  like lower(@tagNameWithSpace1)) or (lower(TagName) like lower(@tagName1)) or (lower(TagName) like lower(@tagNameWithSpace1))  
    or (lower(UserBookmarkName) like lower(@tagName1) or lower(UserBookmarkName) like lower(@tagNameWithSpace1)) or (lower(UserBookmarkDescription)
    like lower(@tagName1) or lower(UserBookmarkDescription) like lower(@tagNameWithSpace1))) and b.ID in (
    select b.ID from bookmarking_bookmark as b left join bookmarking_bookmarktag as bt on b.ID=bt.BookmarkID left join bookmarking_tag as t on bt.TagID=t.TagID left join
    (select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName,  ub.Description as UserBookmarkDescription, t.Name as TagName 
    from (select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub 
    left join bookmarking_userbookmarktag as ubt on ub.UserBookmarkID=ubt.UserBookmarkID  left join bookmarking_tag as t on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID
    where (( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash2) ) or (lower(b.Name) like lower(@tagName2) or lower(b.Name) like lower(@tagNameWithSpace2))
    or (lower(b.Description) like lower(@tagName2) or lower(b.Description) like lower(@tagNameWithSpace2)) or (lower(t.Name) like lower(@tagName2)) or (lower(t.Name)
    like lower(@tagNameWithSpace2)) or....

    среднее время выполнения 30 секунд

    arusanov, 14 Марта 2011

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    В связи с минусаторной атакой в говнокоде 5186, просьба.
    Страйкер, заблокируй пользователей с номерами
    http://govnokod.ru/user/2689 - 
    http://govnokod.ru/user/2703
    
    (весь диапазон оккупировали тролли-виртуалы)
    
    И ИП-адрес, с которого эти пользователи логинились.

    TarasB, 09 Января 2011

    Комментарии (115)
  9. Куча / Говнокод #27388

    +2

    1. 1
    Мир! Труд! Май!

    С праздником, питухи!

    MAuCKuu_nemyx, 01 Мая 2021

    Комментарии (114)
  10. Python / Говнокод #27060

    −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
    number = input("Введите цифру от 1000, до 20000: >")
    if int(number) < 1000 or int(number) > 20_000:
        print("Неправильное число")
        exit(0)
     
    j = ''  # сделать стринг
     
    i = 0  # for
     
    maximum = []  # поиск максимального числа
     
    count = 0  # ошибка
     
    while i < int(number):
        i += 1  # ++
        i_string = str(i)
        j = i_string[::-1]
        if int(i) + int(j) == int(number):
            maximum.append(int(i))
            count += 1  # ошибка
    if count == 0:
        print(0)
        exit(0)
    print(max(maximum))

    Цель кода была в том, чтобы найти максимальный x, по формуле X+F(x) = N, где N число, которое ввели, а F(X) перевёрнутый X
    x = 1234 f(x) = 4321

    warzon131, 26 Октября 2020

    Комментарии (114)
  11. 1C / Говнокод #25984

    −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
    ВЫБОР КОГДА ПОДСТРОКА(Поле, 1, 1) <> ""-"" ТОГДА
      ПОДСТРОКА(Поле, 1, 1)
    ИНАЧЕ """"
    КОНЕЦ
    +
    ВЫБОР КОГДА ПОДСТРОКА(Поле, 2, 1) <> ""-"" ТОГДА
      ПОДСТРОКА(Поле, 2, 1)
    ИНАЧЕ """"
    КОНЕЦ
    +
    ...
    +
    ВЫБОР КОГДА ПОДСТРОКА(Поле, 100, 1) <> ""-"" ТОГДА
      ПОДСТРОКА(Поле, 100, 1)
    ИНАЧЕ """"
    КОНЕЦ

    Реализация СтрЗаменить() в запросе

    DioSoset, 22 Октября 2019

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