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

    В номинации:
    За время:
  2. Куча / Говнокод #14547

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Переустановил я, значит, Шиндоус 7 (лицуха), ставлю VS 2012
    
    Все встало без проблем, предупреждений и криков о помощи.
    
    При запуске ВНЕЗАПНО всплыло окошко
    
    "Внимание! Данная программа имеет известные проблемы совместимости с данной версией Windows"
    
    Visual Studio  2012 несовместим с семеркой? Ну охуеть теперь.

    kegdan, 12 Февраля 2014

    Комментарии (68)
  3. Си / Говнокод #13590

    +125

    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
    static U64 mulU64byU64(U64 a, U64 b, U64 * high)
    {
        U64 b_high = 0;
        U64 r_high = 0, r_low = 0;
        U64 bit;
    	
        for (bit = 1; bit; bit <<= 1) {
            if (a & bit) {
                if (r_low + b < r_low)
                    r_high++;
                r_low += b;
                r_high += b_high;
            }
            b_high <<= 1;
            b_high |= (b & (1ULL << 63)) >> 63;
            b <<= 1;
        }
    	
        if (high)
            *high = r_high;
        return r_low;
    }

    Угадай зачем %D

    Stealth, 09 Августа 2013

    Комментарии (68)
  4. Куча / Говнокод #12192

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    splitOn :: (a -> Bool) -> [a] -> [[a]]
    splitOn _ [] = []
    splitOn f xs = removeEmpty $ takeWhile (not . f) xs: splitOn f (dropWhile (f) $ dropWhile (not . f) xs) where
    	removeEmpty [] 	= []
    	removeEmpty (x:xs) 
    		| null x 	= removeEmpty xs 
    		| otherwise = x: removeEmpty xs
    
    words' :: String -> [String]
    words' = splitOn (flip elem " \n\r\f\t\v\160")

    Еще один words'

    Fai, 25 Ноября 2012

    Комментарии (68)
  5. Python / Говнокод #12089

    −106

    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
    >>> class Foo():
    ...     pass
    ... 
    >>> try:
    ...     raise Foo()
    ... except ExceptionBase as foo:
    ...     print 'foo %s' % foo
    ... except:
    ...     print 'not an exception'
    ... else:
    ...     print 'it\'s all good'
    ... 
    not an exception
    >>>

    Чет я как-то призадумался... Питон 2.7. Что делать-та?

    wvxvw, 10 Ноября 2012

    Комментарии (68)
  6. Java / Говнокод #11246

    +124

    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
    BufferedReader file = null;
        boolean moreData = true;
        //set the parameters
        this.textureDir = textureDir;
    
        //open a file
        try{
          file = new BufferedReader(
              new InputStreamReader(
              (new FileInputStream(filename))), 50000);
        } catch (Exception e) {System.err.println("kan model niet laden"); moreData = false;}
    
        //read shapes until no more data
        while(moreData)
        {
          Shape3D shape = readShape(file);
          if(shape != null)
          {
            tg.addChild(shape);
    
          }
          else
          {
            moreData = false;
          }
        }
    
        try{
          file.close();
          file=null;
        } catch (IOException e)
        {
          System.err.println("file " + filename + " could not be closed!");
        }

    Интересный способ обработки ошибок ввода-вывода.

    Естественно, при неудачном открытии файла вываливается по NullPointerException.

    someone, 20 Июня 2012

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

    +64

    1. 1
    2. 2
    3. 3
    4. 4
    $res = mysql_query(...);
    if($res == 'true'){
        .....
    }

    Может кому то покажутся знакомы эти строки, но те, кто не знают Е. Попова могут над ним поржать.

    BioMan, 15 Июня 2012

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

    +133

    1. 1
    2. 2
    3. 3
    fib 1 = 1
    fib 2 = 1
    fib n = fib(n-1) + fib (n-2)

    Хаскель это вам не математика, тут надо и вычислительную сложность учитывать.

    kipar, 27 Июня 2011

    Комментарии (68)
  9. C++ / Говнокод #6736

    +166

    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
    94. 94
    95. 95
    96. 96
    97. 97
    #include <dir.h>//ДЛЯ ОПРЕДЕЛЕНИЯ mkdir(ИМЯ ПАПКИ)
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <alloc.h>
    #include <string.h>
    #include <iostream.h>
     int ndig(char x)
    {if('0'<=x&&x<='9')return 0;else return 1;}
    // СТРОКА ВЕДОМОСТИ ДЛЯ ОДНОГО СТУДЕНТА
     struct stud
    {char fio[122];int b[9],ns
    static int nc
    ,nd;
     void out(FILE*fo);stud(){fio[121]=0;}
    stud(FILE*fi);
    stud(stud&s){*this=s;}
    }; //end of stud body
     int stud::nc=44;
     int stud::nd=5;
     stud::stud(FILE *fi)
    {fscanf(fi,"%i ",&ns); fgets(fio,nc,fi);
    for(int j=1;j<=nd;++j)fscanf(fi,"%i",&b[j]);}
    
     void stud::out(FILE*fo=stdout)
    {fprintf(fo,"%3i ",ns);
    fputs(fio,fo); for(int j=1;j<=nd;++j)
    {if(b[j]>=0&&b[j]<6) fprintf(fo,"%3i",b[j]);
    else fprintf(fo,"   ");}
    fprintf(fo,"\n"); if ( fo==stdout) getch();
    }//end of stud
    
    //ВЕДОМОСТЬ ОДНОЙ ГРУППЫ
    //("МАССИВ СТРОК" ДЛЯ ОТДЕЛЬНЫХ СТУДЕНТОВ)
    
     struct grup{ stud**st;//"МАССИВ СТУДЕНТОВ"
    FILE*fi;char title[3][122]//"ШАПКА" ВЕДОМОСТИ
    ,sf[77];
    
    int ms;//ЧИСЛО СТУДЕНТОВ
    void nw();//ПАМЯТЬ ДЛЯ СТУДЕНТОВ
    void out(char*sf); void out(FILE*fo);
    grup(grup&g);grup(int fms){ms=fms; nw();}
    grup(char*sf); grup&operator=(const grup&g);
    void deg();~grup(){deg();} grup(); };
    //end of grup body
     grup::grup(){ms=0;st=0;fi=0;
    for(int j=0;j<3;++j)memset(title[j],0,122);}
    
     void grup::nw()
    {st=new stud*[ms+1];
    if(!st){cout<<"\nst=0  grup::nw()\n";exit(1);}
    for(int j=0;j<=ms;++j)
    {st[j]=new stud;
    if(!st){cout<<"\nst[j]=0\n";exit(1);}
    }}
     grup::grup(char*fsf)
    {strcpy(sf,fsf); char s[77]="\n"; int j;
    fi=fopen(sf,"rt");
    if(!fi)
    {cout<<"\n0)fi=0,sf="<<sf;getch();exit(1);}
    ms=0; while(!feof(fi)){fgets(s,77,fi);++ms;}
    ms-=3; fclose(fi); fi=fopen(sf,"rt");
    if(!fi){cout<<"\nfi\n";exit(1);}
    for(j=0;j<3;++j) fgets((title[j]),77,fi);
    
    //ВВОД "СТУДЕНТОВ" ИЗ ФАЙЛА sf
    nw();for(j=1;j<=ms;++j){stud stj(fi);*st[j]=stj;}
    fclose(fi);
    }
     grup&grup::operator=(const grup&g)
    {if(this==&g)return*this; int j; this->deg();
    fi=g.fi; strcpy(sf,g.sf); ms=g.ms;
    nw(); for(j=0;j<=ms;++j)*st[j]=*g.st[j];
    for(j=0;j<3;++j)strcpy(title[j],g.title[j]);
    return*this;
    }
     grup::grup(grup&g)
    {for(int j=0;j<3;++j)strcpy(title[j],g.title[j]);
    ms=g.ms; strcpy(sf,g.sf);
    nw(); for(j=0;j<=ms;++j)*st[j]=*g.st[j];
    }
     void grup::deg()
    {if(st) {for(int j=0;j<=ms;++j)
    if(st[j]){delete st[j];st[j]=0;}delete[]st;st=0;}
    }
     void grup::out(FILE*fo=stdout)
    {if(fo==stdout)cout<<'\n'; int j=0;
    for(;j<3;j++) fputs(title[j],fo);
    
    for(j=1;j<=ms;j++) st[j]->out(fo);
    }
     void grup::out(char*sf)
    {FILE*fo=fopen(sf,"wt");
    if(!fo){cout<<"\nfo=0\n";exit(1);}
    out(fo); fclose(fo);
    } //end of grup

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

    CTRSpirit, 23 Мая 2011

    Комментарии (68)
  10. Си / Говнокод #6720

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    temp = (NODE *)malloc(sizeof(NODE));
          if (temp == NULL)
          {
            Free(temp);
            Free(task);
            return NULL;
          }

    Курсовик ночью по пьяни. Подстраховался блин.

    Enelar, 20 Мая 2011

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

    +124

    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
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
    
    ;;; Copyright (C) 2011, Dmitry Ignatiev <[email protected]>
    
    ;;; Permission is hereby granted, free of charge, to any person
    ;;; obtaining a copy of this software and associated documentation
    ;;; files (the "Software"), to deal in the Software without
    ;;; restriction, including without limitation the rights to use, copy,
    ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
    ;;; of the Software, and to permit persons to whom the Software is
    ;;; furnished to do so, subject to the following conditions:
    
    ;;; The above copyright notice and this permission notice shall be
    ;;; included in all copies or substantial portions of the Software.
    
    ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    ;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    ;;; DEALINGS IN THE SOFTWARE
    
    (in-package #:neural-flow)
    
    ;; Stolen from `trivial-garbage'
    
    #+openmcl
    (defvar *weak-pointers* (cl:make-hash-table :test 'eq :weak :value))
    
    #+(or allegro openmcl lispworks)
    (defstruct (weak-pointer (:constructor %make-weak-pointer))
      #-openmcl pointer)
    
    (declaim (inline make-weak-pointer))
    (defun make-weak-pointer (object)
      #+sbcl (sb-ext:make-weak-pointer object)
      #+(or cmu scl) (ext:make-weak-pointer object)
      #+clisp (ext:make-weak-pointer object)
      #+ecl (ext:make-weak-pointer object)
      #+allegro
      (let ((wv (excl:weak-vector 1)))
        (setf (svref wv 0) object)
        (%make-weak-pointer :pointer wv))
      #+openmcl
      (let ((wp (%make-weak-pointer)))
        (setf (gethash wp *weak-pointers*) object)
        wp)
      #+corman (ccl:make-weak-pointer object)
      #+lispworks
      (let ((array (make-array 1)))
        (hcl:set-array-weak array t)
        (setf (svref array 0) object)
        (%make-weak-pointer :pointer array)))
    
    (declaim (inline weak-pointer-value))
    (defun weak-pointer-value (weak-pointer)
      "If WEAK-POINTER is valid, returns its value. Otherwise, returns NIL."
      #+sbcl (values (sb-ext:weak-pointer-value weak-pointer))
      #+(or cmu scl) (values (ext:weak-pointer-value weak-pointer))
      #+clisp (values (ext:weak-pointer-value weak-pointer))
      #+ecl (values (ext:weak-pointer-value weak-pointer))
      #+allegro (svref (weak-pointer-pointer weak-pointer) 0)
      #+openmcl (values (gethash weak-pointer *weak-pointers*))
      #+corman (ccl:weak-pointer-obj weak-pointer)
      #+lispworks (svref (weak-pointer-pointer weak-pointer) 0))
    
    ;;Red-black tree
    
    (declaim (inline %node %nleft %nright %nparent %nred %ndata %ncode
                     (setf %nleft) (setf %nright) (setf %nparent)
                     (setf %nred) (setf %ndata) (setf %ncode)))
    (defstruct (%node (:constructor %node (data code parent red))
                      (:conc-name %n))
      (left nil :type (or null %node))
      (right nil :type (or null %node))
      (parent nil :type (or null %node))
      (red nil)
      data
      (code 0 :type (integer 0 #.most-positive-fixnum)))
    
    (declaim (inline %tree %tree-root (setf %tree-root)))
    (defstruct (%tree (:constructor %tree ())
                      (:copier %copy-tree))
      (root nil :type (or null %node)))
    
    (declaim (inline rotate-left))
    (defun %rotate-left (tree node)
      (declare (type %tree tree) (type %node node)
               (optimize (speed 3) (safety 0)))
      (let ((right (%nright node)))
        (when (setf (%nright node) (%nleft right))
          (setf (%nparent (%nleft right)) node))
        (if (setf (%nparent right) (%nparent node))
          (if (eq node (%nleft (%nparent node)))
            (setf (%nleft (%nparent node)) right)
            (setf (%nright (%nparent node)) right))
          (setf (%tree-root tree) right))

    Вылезли глаза! Как на этом можно писать?

    vertexua, 10 Февраля 2011

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