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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. Java / Говнокод #17259

    +84

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

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

    someone, 05 Декабря 2014

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    
    $data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
    $name = 'myphoto.jpg';
    
    force_download($name, $data);

    Я знаю конечно что это не говнокод, но последствия будут ужасными если не передать сразу же в функцию данные (т.к. PHP будет копировать содержимое дважды), представьте себе файл в 2МБ и много запросов, сервер капут в два раза быстрее.
    - https://ellislab.com/codeigniter/user-guide/helpers/download_helper.html

    volter9, 15 Сентября 2014

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private void gv3_HiddenEditor(object sender, EventArgs e)
    {
    	if (cloneDt != null)
    	{
    		cloneDt = null;
    	}
    	if (cloneCt != null)
    	{
    		cloneCt = null;
    	}
    }

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

    Smekalisty, 12 Сентября 2014

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

    +144

    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
    public static void main(String[] args) {
        int temp = 0;
        out: // label
        for (int i = 0; i < 3; ++i) {
            System.out.println("I am here");
            for (int j = 0; j < 20; ++j) {
               if(temp==0) {
                   System.out.println("j: " + j);
                    if (j == 1) {
                        temp = j;
                        continue out; // goto label "out"
                    }
                }
            }
        }
        System.out.println("temp = " + temp);
    }

    Оригинал: http://stackoverflow.com/questions/2545103/is-there-a-goto-statement-in-java

    Помнится, кто-то недавно упомянул именнованные циклы.
    Вот они и нашлись.

    Получается, что по "continue out" мы пойдём на следующую итерацию внешнего цикла, а при "break out", выйдем из внешнего цикла.
    Странно, что M$ не утянули себе такую фичу...

    TauSigma, 26 Августа 2014

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