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

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

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    void print_line(char *s){
        for(int i = 0; i < strlen(s); i++) putchar(s[i]);
        putchar('\n');
    }

    Почему C работает медленнее чем JavaScript ?

    o8603054, 17 Января 2019

    Комментарии (120)
  3. JavaScript / Говнокод #20136

    +5

    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
    function insertComment(comment) {
        // todo: optimize this shit
        for (var j = 0; j < $scope.comments.length; ++j) {
            if ($scope.comments[j].thread_id == comment.thread_id) {
                $scope.comments[j] = comment;
                return;
            }
            if ($scope.comments[j].comment_id < comment.comment_id) {
                $scope.comments.splice(j, 0, comment);
                return;
            }
        }
        $scope.comments.push(comment);
    }
    
    for (var i = 0; i < data.length; ++i) {
        comment = data[i];
        comment.text = $sce.trustAsHtml(comment.text);
        comment.postedFuzzy = fuzzyDate(new Date(comment.posted), new Date());
        insertComment(comment);
    }

    Оптимальное набивание комментов в сток за O(n^2).

    http://146.185.130.46/ngk/

    bormand, 06 Июня 2016

    Комментарии (120)
  4. Java / Говнокод #18475

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    List<Integer> positionList = new ArrayList<Integer>(positions.keySet());
    Collections.sort(positionList, new Comparator<Integer>() {
        @Override
        public int compare(Integer lhs, Integer rhs) {
            if (lhs > rhs) {
                return 1;
            } else if (lhs < rhs) {
                return -1;
            }
            return 0;
        }
    });

    Видать разработчику за кол-во написанных строк платили...

    tony777, 13 Июля 2015

    Комментарии (120)
  5. Java / Говнокод #27938

    −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
    45. 45
    import java.util.Scanner;
    
    public class JavaApplication5 {
    
        public static void main(String[] args) {
            Scanner sw = new Scanner(System.in);
            System.out.print("Введите число: ");
            int week = sw.nextInt();
            System.out.println("The day is "+day);
        
    }
    
    class Month{
        
            String day;
            switch (int week) {
                case 1:
                    day = "Monday";
                    break;
                case 2:
                    day = "Tuesday";
                    break;
                case 3:
                    day = "Wednesday";
                    break;
                // match the value of week
                case 4:
                    day = "Thursday";
                    break;
                case 5:
                    day = "Friday";
                    break;
                case 6:
                    day = "Saturday";
                    break;
                case 7:
                    day = "Sunday";
                    break;
                default:
                    day = "---";
                    break;
            }
            
        }
    }

    Нужно чтобы от пользователя запрашивался номер дня недели, а получалось название. Не пойму, что не так. Помогите, пожалуйста, Добрые Люди

    123AAAANNNAAA, 08 Января 2022

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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
    
    // The Curiously Recurring Template Pattern (CRTP)
    template<class T>
    class Base
    {
        // methods within Base can use template to access members of Derived
    };
    class Derived : public Base<Derived>
    {
        // ...
    };

    > The Microsoft Implementation of CRTP in Active Template Library (ATL) was independently discovered, also in 1995 by Jan Falkin who accidentally derived a base class from a derived class. Christian Beaumont, first saw Jan's code and initially thought it couldn't possibly compile in the Microsoft compiler available at the time. Following this revelation that it did indeed work, Christian based the entire ATL and Windows Template Library (WTL) design on this mistake.

    А какая ошибка по-вашему положена в основу всего дизайна языка C++?

    j123123, 06 Февраля 2019

    Комментарии (119)
  7. 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)
  8. 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)
  9. PHP / Говнокод #13569

    +162

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

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

    shitcoder, 08 Августа 2013

    Комментарии (119)
  10. 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)
  11. 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)