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

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

    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
    public static int index(string word, char comp)
            {
                int k = -1;
                for (int i = 0; i < word.Length; i++)
                    if (word[i] == comp)
                    {
                        k = i;
                        break;
                    }
                return k;
            }
    
            public static char[] strtocharr(string str)
            {
                char[] tmp = new char[str.Length];
                for (int i = 0; i < tmp.Length; i++)
                    tmp[i] = str[i];
                return tmp;
            }
    
            public static string charrtostr(char[] charr)
            {
                string tmp = null;
                for (int i = 0; i < charr.Length; i++)
                    tmp = String.Format("{0}{1}", tmp, charr[i]);
                return tmp;
            }
    
            public static char maskfromword(string word)
            {
                return word[word.Length - 1];
            }
    
            public static string maskfromword(string word, int n)
            {
                string mask = null;
                for (int i = 0; i < n; i++)
                    mask = String.Format("{0}{1}", mask, word[word.Length - 1]);
                return mask;
            }
    
            public static char Counter(char crnt, string word)
            {
                if (crnt != maskfromword(word))
                    crnt = word[index(word, crnt) + 1];
                else
                    crnt = word[0];
                return crnt;
            }
    
            public static string Counter(string prev, string word, int k)
            {
                char[] tmp = strtocharr(prev);
                if (k >= prev.Length - 1)
                    k = prev.Length - 1;
                else
                    for (int i = k + 1; i < prev.Length; i++)
                        tmp[i] = word[0];
                if (tmp[k] == maskfromword(word))
                    return MultiCounter(prev, word, k - 1);
                else
                    tmp[k] = Counter(tmp[k], word);
                return charrtostr(tmp);
            }

    Список методов, позволяющие сделать счетчик по словарю (полезно для генераторов словарей) на любое количество символов.

    Vero92, 18 Августа 2017

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

    +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
    #include <iostream>
     
    class A
    {
    public:
        virtual void print(int val = 10) { std::cout << "A" << val; }
    };
     
    class B : public A
    {
    public:
        virtual void print(int val = 20) { std::cout << "B" << val; }
    };
     
    int main()
    {
        B b;
        A& a = b;
        a.print();
        return 0;
    }

    when you see it, you’ll shit bricks

    Tonghost, 26 Июля 2016

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

    +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
    static public function createFromStr($string)
            {
                $arr = explode('|', trim($string));
                if (!empty($arr)) {
                    $object = new Fingerprint();
                    for($i = 0, $stop = count($arr); $i < $stop; $i++) {
                        $value = trim($arr[$i]);
                        switch($i) {
                            case 0:
                                $object->fingerprint = $value;
                                break;
                            case 1:
                                $object->ctrlV = (int)$value;
                                break;
                            case 2:
                                $object->printableKey = (int)$value;
                                break;
                        }
                    }
    
                    return $object;
                } else {
                    return null;
                }
            }

    создание объекта класса FingerPrint c помощью статического метода; facepalm

    bykovski, 19 Января 2016

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

    +9

    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
    int turn = m_mapObject->getTurnSpeed();
    //НЕ НАДО ТУТ ОПТИМИЗИРОВАТЬ /= 45 !!!!
    if (turn != 0) {
        if (turn > 0) {
        //                    qDebug() << "Turn plus";
            turn /= 45;
            if (turn < 4) turn = 4;
            if (turn > 8) turn = 8;
        } else {
        //                    qDebug() << "Turn minus";
            turn /= 45;
            if (turn > -4) turn = -4;
            if (turn < -8) turn = -8;
        }
        paint.drawLine(QPoint(0,-speed),QPoint(turn,-speed));
    }

    Вы б знали, как руки чешутся...

    Antervis, 05 Октября 2015

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

    +4

    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
    using System;
    namespace project5
    {
        class Program
        {
            static void Main(string[] args)
            {
             
            }
    
            class Petux
            {
                private int petux = "kukareku!";
                
                public Petux():this(5)
                {
                    
                }
    
                public Petux(int i):this()
                {
                    
                }
            }
    
        }
    }

    обратите внимание на строку 13

    При всем при этом код компилится!

    http://ideone.com/XIQDfK

    Внимание вопрос - уважаемые знатоки, почему?

    kegdan, 06 Августа 2015

    Комментарии (36)
  7. JavaScript / Говнокод #18533

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    /* ... */
    
    alert(event.target.parentElement.parentElement.parentElement.id);
    
    /* ... */

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

    CMTV, 26 Июля 2015

    Комментарии (36)
  8. Java / Говнокод #17680

    +102

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public class Permuter                                {
        private static void permute(int n, char[] a)     {
            if (n == 0)                                  {
                System.out.println(String.valueOf(a))    ;}
            else                                         {
                for (int i = 0; i <= n; i++)             {
                    permute(n-1, a)                      ;
                    swap(a, n % 2 == 0 ? i : 0, n)       ;}}}
        private static void swap(char[] a, int i, int j) {
            char saved = a[i]                            ;
            a[i] = a[j]                                  ;
            a[j] = saved                                 ;}}

    "I finally figured out how to get those pesky semicolons and curly braces out of my Java code"

    Xom94ok, 22 Февраля 2015

    Комментарии (36)
  9. Си / Говнокод #17566

    +124

    1. 1
    value += (0<<17);   // PARK bit

    codemonkey, 03 Февраля 2015

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

    −97

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    def constant_time_compare(val1, val2):
        """
        Returns True if the two strings are equal, False otherwise.
    
        The time taken is independent of the number of characters that match.
        """
        if len(val1) != len(val2):
            return False
        result = 0
        for x, y in zip(val1, val2):
            result |= ord(x) ^ ord(y)
        return result == 0

    Django.utils.crypto в Django 1.4

    american_idiot, 24 Октября 2014

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

    +101

    1. 1
    удалено

    Кто делает выгрузка в таком формате???
    xml? json? так лучше, епта

    Cascader, 21 Августа 2014

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