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

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

    +57

    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
    #include <iostream>
    #include <stdexcept>
    
    template<std::size_t N>
    static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
      return 
        (i + 2 + (last ? 0 : 1) >= N) 
            ? throw std::logic_error("Too short date string") :
        (!last && s[i + 2] != ':') 
            ? throw std::logic_error("Cannot find delimiter") :
        (s[i] < '0' || s[i] > '9' ||  s[i + 1] < '0' || s[i + 1] > '9') 
            ? throw std::logic_error("Not a number") :
        ((s[i] - '0') * 10 + (s[i + 1] - '0') > max) 
            ? throw std::logic_error("Too large number") :
                (s[i] - '0') * 10 + (s[i + 1] - '0');
    }
    
    struct time { 
        int hour; int minute; int second; 
        
        template<std::size_t N>
        constexpr time(const char (&datestr)[N]) :
            hour(date_component(datestr, 0, false, 24)), 
            minute(date_component(datestr, 3, false, 60)),
            second(date_component(datestr, 6, true, 60)) 
        {}
    };
    
    struct time constexpr midnight("00:00:00");
    struct time constexpr afternoon("12:00:00");
    
    int main(int argc, char* argv[]) {
        std::cout << "Midnight hour is " << midnight.hour << std::endl;
        std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
    }

    C++ и даты времени компиляции

    myaut, 03 Апреля 2015

    Комментарии (21)
  3. PHP / Говнокод #17869

    +164

    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
    function addnews($str1="", $str2="", $str3="", $str4="", $str5=""){
      $num = 0;
      $done = 0;
      while ($done == 0){
        $num++;
        $s = "";
        if ($num<10000000) {$s="0".$s;}
        if ($num<1000000)  {$s="0".$s;}
        if ($num<100000)   {$s="0".$s;}
        if ($num<10000)    {$s="0".$s;}
        if ($num<1000)     {$s="0".$s;}
        if ($num<100)      {$s="0".$s;}
        if ($num<10)       {$s="0".$s;}
    	$done = 1;
    	if (file_exists("news/".$s.$num.".txt")){$done=0;}
      }
      $fh1 =fopen("news/".$s.$num.".txt","w");
      fwrite($fh1, $str1."\r\n");
      fwrite($fh1, $str2."\r\n");
      fwrite($fh1, $str3."\r\n");
      fwrite($fh1, $str4."\r\n");
      fwrite($fh1, $str5);
      fclose($fh1);
    }

    Предложили доработать корпоративную тикет-систему. Движок абсолютно всё хранит в txt-файлах. Да, и пароли пользователей тоже - в открытом виде. БД? Нет, не слышали :(
    Но это еще не так страшно...

    Arris, 26 Марта 2015

    Комментарии (21)
  4. C++ / Говнокод #17750

    +54

    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
    void Game::initialize()
    {
        if (SDL_Init(SDL_INIT_VIDEO))
            exit(1);
        
        window = new Window("Game", 640, 480);
        try
        {
            window->create();
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete window;
            exit(1);
        }
        
        canvas = new Canvas();
        try
        {
            canvas->initialize(window->getWindow());
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete canvas;
            exit(1);
        }
    }

    jangolare, 09 Марта 2015

    Комментарии (21)
  5. PHP / Говнокод #17667

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function getMinQueueOrdering()
      {
        $sql="SELECT MAX(ordering)
              FROM priceloaddata_queue";
      .........
      }

    нет слов.

    Vasiliy, 19 Февраля 2015

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

    +64

    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
    import java.util.HashMap;
    import java.util.Map;
    import java.util.StringTokenizer;
    
    public class PolynomialParser {
    	
    	public Polynomial parse(String rawPolynomial) {
    		String source = normalizeSourceString(rawPolynomial);
    		Map<Integer, Integer> result = new HashMap<>();
    		
    		StringTokenizer tokenizer = new StringTokenizer(source, "[+-]", true);
    		boolean isCurrentNegative = false;
    		int currentDegree;
    		int currentCoefficient;
    		while (tokenizer.hasMoreTokens()) {
    			String currentToken = tokenizer.nextToken();
    			if ("-".equals(currentToken)) {
    				isCurrentNegative = true;
    			} else if ("+".equals(currentToken)) {
    				isCurrentNegative = false;
    			} else {
    				if (currentToken.contains("x")) {
    					if (currentToken.contains("^")) {
    						String[] tmp = currentToken.split("x\\^");
    						currentDegree = Integer.parseInt(tmp[1]);
    						int draftCoefficient = Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					} else {
    						currentDegree = 1;
    						String[] tmp = currentToken.split("x");
    						int draftCoefficient = (tmp.length == 0) ? 1 : Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					}
    				} else {
    					currentDegree = 0;
    					int draftCoefficient = Integer.parseInt(currentToken);
    					currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    				}
    				result.put(currentDegree, currentCoefficient);
    			}
    		}
    		return new Polynomial(result);
    	}
    	
    	private String normalizeSourceString(String source) {
    		String result = source.replaceAll("\\s+","");
    		return result.toLowerCase();
    	}
    }

    Из сегодняшнего. Парсинг многочленов.

    itrofan-ebufsehjidov, 01 Февраля 2015

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // classes.php
    return [
      'yii\base\Action' => YII2_PATH . '/base/Action.php',
      'yii\base\ActionEvent' => YII2_PATH . '/base/ActionEvent.php',
      'yii\base\ActionFilter' => YII2_PATH . '/base/ActionFilter.php',
      // еще порядка трех сотен классов
    ];

    https://github.com/yiisoft/yii2/blob/d2b864da84a68d56a96709479af78d203f050451/framework/classes.php

    осень 2014, использующий composer модный фреймворк, "requires PHP 5.4 and embraces the best practices and protocols found in modern Web application development", и, конечно, ебаный стыд.

    Fike, 18 Января 2015

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

    +84

    1. 1
    List selection = new ArrayList((s != null) ? s : new ArrayList());

    Больше мусора для бога сборщика мусора!

    someone, 05 Декабря 2014

    Комментарии (21)
  9. Pascal / Говнокод #17258

    +86

    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
    const n=10;
    
    type
         xfl = record x: double; fl: longint; end;
      ar_xfl = array[1..2*n] of xfl;
    var
      i: longint;
      x,y,r: double;
      a: ar_xfl;
      f: text;
    
    
    procedure qsort(var a: ar_xfl; lo,hi: longint);
        procedure sort(l,r: longint);
        var
          i,j,k: longint;
          tmp: xfl;
        begin
          i:=l;
          j:=r;
          k:=(l+r) div 2;
          repeat
            while a[i].x<a[k].x do inc(i);
            while a[k].x<a[j].x do dec(j);
            if i<=j then
              begin
                tmp:=a[i];
                a[i]:=a[j];
                a[j]:=tmp;
                inc(i);
                dec(j);
              end;
          until i>j;
          if l<j then sort(l,j);
          if i<r then sort(i,r);
        end;
    begin
    sort(lo,hi);
    end;

    За такие названия переменных надо руки завязывать узлом. Да и помимо этого..

    Cynicrus, 05 Декабря 2014

    Комментарии (21)
  10. C++ / Говнокод #17240

    +58

    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
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    struct t_point {
        int i,j;
    };
    #define stack_len 50000000
    long int head, tail;
    t_point *steck;
    
    // long int take_border( short int*arr, int h1, int w1, int deep ){
    long int take_border( short int*arr, int h1, int w1 ){
        long int k=0;
        //int i,j,m,n,ii,jj;
        int i,j,m,ii,n,jj;
        steck = (t_point*) malloc(tail*sizeof(t_point));
        if(! steck ){
            //ui->teDebug->setText("out of Memory");
            return 0;
        }
        {
           QFile file("buffer.dat");
           file.open(QIODevice::ReadOnly);
           unsigned int size = sizeof(t_point)* tail;
           QDataStream in(&file);   // we will serialize the data into the file
           in.readRawData((char*) steck, size );
        }
    // <...>
    }

    Это чувство когда сишник взялся писать на Qt.

    overloop, 02 Декабря 2014

    Комментарии (21)
  11. C++ / Говнокод #17155

    +50

    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
    #include <deque>
    #include <stdint.h>
    #include <iterator>
    #include <algorithm>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    typedef uint32_t bt;
    typedef uint64_t dbt;
    typedef deque<bt> bn;
    #define cat2(b,e) b##e
    #define cat(b,e) cat2(b,e)
    #define fsi(i,s,e) for(size_t i(s), cat(i,_end)(e); i<cat(i,_end); ++(i))
    #define fe(i,c) for(auto i((c).begin()), cat(i,_end)((c).end()); i!=cat(i,_end); ++(i))
    void ml10(bn& n){
      n.push_front(0);
    }
    uint32_t ni(const bn& n, size_t i){
      if(n.size()<=i)
        return 0;
      else
        return n[i];
    }
    size_t ms(const bn& n1, const bn& n2){
      return (max) (n1.size(), n2.size());
    }
    bt gr(dbt tr){
      return tr & (numeric_limits<bt>::max)();
    }
    bt gc(dbt tr){
      return (tr & (~((dbt)(numeric_limits<bt>::max)()))) >> (numeric_limits<bt>::digits);
    }
    void pb(bt b1, bt b2, bt lc, bt& r, bt& c){
      dbt tr = ((uint64_t)b1 + b2 + lc);
      r = gr(tr);
      c = gc(tr);
    }
    void mb(bt b1, bt b2, bt lc, bt& r, bt& c){
      dbt tr = ((uint64_t)b1 * b2 + lc);
      r = gr(tr);
      c = gc(tr);
    }
    bn /*constexpr*/ bi(bn n){
      reverse(n.begin(), n.end());
      return n;
    }
    bn pl(const bn& n1, const bn& n2){
      bn r;
      bt c=0,br=0;
      size_t ms_ = ms(n1, n2);
      //r.reserve(ms_+1);
      fsi(i,0,ms_){
        pb(ni(n1,i),ni(n2,i),c,br,c);
        r.push_back(br);
      }
      if (c)
        r.push_back(c);
      return r;
    }
    bn ml(bn n1, const bn& n2){
      bn lr, r;
      bt c=0;
      //r.reserve(n1.size() + n2.size() + 1);
      fsi(i2,0,n2.size()){
        fsi(i1, 0, n1.size()){
          lr.emplace_back();
          mb(n1[i1], n2[i2], c, lr[i1], c);
        }
        if (c){
          lr.push_back(c);
          c = 0;
        }
        r = pl(r, lr);
        lr.clear();
        ml10(n1);
      }
      return r;
    }
    #define STR1(x) #x
    #define STR(x) STR1(x)
    #define EXPECT_TRUE(expr)\
    do{\
      if(!(expr))\
        cout<<"*****Failed test: \"" STR(expr) "\"" << endl;\
        else\
        cout << "Test OK: \"" STR(expr) "\"" << endl;\
    }while(false)
    #define TEST(expr)\
    do{\
        cout << "Test begined: \"" STR(expr) "\"" << endl;\
        (void)(expr);\
    } while (false)

    И вот мой просмотр аниме закончен.
    http://ideone.com/eRJ7FA
    main смотри в коментах

    LispGovno, 24 Ноября 2014

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