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

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

    −10

    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
    static bool IsPalindrome( int value ) { 
    int reverseValue = 0; 
    if(value < 0) value = -value; 
    int tempValue = value; 
    int reverseValueTens = 1; 
    while(tempValue > 0) { 
    reverseValueTens *= 10; 
    tempValue /= 10; 
    } 
    reverseValueTens /= 10; 
    tempValue = value; 
    while(tempValue > 0) { 
    //Alert( reverseAbsValueAddition ); 
    reverseValue += (tempValue - (tempValue/10)*10) * reverseValueTens; 
    reverseValueTens /= 10; 
    tempValue /= 10; 
    } 
    //Alert( reverseAbsValue ); 
    return reverseValue == value; 
    }

    d_fomenok, 17 Апреля 2016

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

    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
    static void Main(string[] args)
    {
    	try
    	{
    		watcher.Path = TargetPath;
    		watcher.Created += Watcher_Created;
    		watcher.Renamed += Watcher_Created;
    		watcher.EnableRaisingEvents = true;
    		logger.Info("Сервис запущен.");
    		System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
    	}
    	catch(Exception ex)
    	{
    		logger.Error(ex, "Global error", null);
    		Main(null);
    	}
    }

    хуита, 15 Марта 2016

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

    +3

    1. 1
    Поднял форум.  Запилил чатик.

    Теперь можно грабить корованы чмокать всех в чатике.

    Vasiliy, 16 Января 2016

    Комментарии (63)
  5. JavaScript / Говнокод #17243

    +215

    1. 1
    if (new Boolean(false)) {

    Отвратная вещь этот new.

    3.14159265, 03 Декабря 2014

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

    +131

    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
    double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 };
                double[] numbers2 = { 2.2 };
    
                IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2);
    
                foreach (double number in onlyInFirstSet)
                    Console.WriteLine(number);
    
                /*
                 This code produces the following output:
    
                 2
                 2.1
                 2.3
                 2.4
                 2.5
                */

    Привет с msdn
    http://msdn.microsoft.com/en-us/library/bb300779%28v=vs.110%29.aspx

    LispGovno, 27 Ноября 2014

    Комментарии (63)
  7. Си / Говнокод #16625

    +129

    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
    package main
    
    import "fmt"
    
    type буква string
    
    var (
    	наТрубе буква
    )
    
    func сидели(а, б буква) буква {
    	return а + б
    }
    
    func aпропало(буква буква) буква {
    	return буква[1:]
    }
    
    func бупало(буква буква) буква {
    	return буква[:1]
    }
    
    func main() {
    	наТрубе = сидели(буква("а"), буква("б"))
    	наТрубе = aпропало(наТрубе)
    	наТрубе = бупало(наТрубе)
    	fmt.Printf("на трубе %s\n", наТрубе)
    }

    ya-ukurok, 01 Сентября 2014

    Комментарии (63)
  8. C++ / Говнокод #15363

    +32

    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
    #include <iostream>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <iterator>
    #include <iomanip>
    using namespace std;
    
    vector<string> bracesExpressionExamples = {
    	"({[{}]{}[]})",
    	"({}}{[{}]{}[]})",
    	"({[{}]{}[]}",
    	"({[{}]{}]})",
    	"({[{}{}[]})",
    	"",
    	"{}"
    };
    
    string openBrace = "({[";
    string closeBrace = ")}]";
    
    typedef map<char, char> otc;
    const otc& openToCloseBrace(){
    	static const otc o2c([](){
    		otc o2c;
    		transform(
    			openBrace.begin(), openBrace.end(),
    			closeBrace.begin(),
    			inserter(o2c, o2c.begin()),
    			[](const char open, const char close){return make_pair(open, close);}
    		);
    		return o2c;
    	}());
    	return o2c; 
    }
    
    bool checkBraces (const string& e){
    	vector<char> s;
    	for(const char b: e)
    		if(string::npos!=openBrace.find(b))
    			s.push_back(openToCloseBrace().at(b));
    		else if(string::npos!=closeBrace.find(b) && (!s.empty()) && b==s.back())
    			s.pop_back();
    		else return false;
    	return s.empty();
    }
    
    int main() {
    	cout<<boolalpha;
    	transform(
    		bracesExpressionExamples.begin(),
    		bracesExpressionExamples.end(),
    		ostream_iterator<bool>(cout, "\n"),
    		checkBraces);
    	return 0;
    }

    http://ideone.com/AbO4tw
    Кот с собеседований.
    Проверка правильности расстановки скобок для каждого выражения из bracesExpressionExamples.

    USB, 05 Марта 2014

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    ...
    #define POW2 65536
    #define TRUE 1
    #define FALSE 0
    #define VAL_TEN 20
    #define VAL_TWEN 10
    #define VAL_HUN 100
    ...

    Просто поржать. Пока была в отпуске, получила письмо от коллеги с этим примером того что я слишком сильно прижала индусов за константы и они все цифры в коде поменяли на "слова".

    dariak, 24 Февраля 2014

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

    +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
    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
    void KateQuickOpen::update () {
      // пропущено
      QModelIndex idxToSelect;
      int linecount = 0;
      QMapIterator<qint64, KTextEditor::View *> i2(sortedViews);
      while (i2.hasNext()) {
            i2.next();
    
            KTextEditor::Document *doc = i2.value()->document();
    
            if (alreadySeenDocs.contains(doc))
              continue;
    
            alreadySeenDocs.insert (doc);
    
            QStandardItem *itemName = new QStandardItem(doc->documentName());
    
            itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole);
            itemName->setData(QString("%1: %2").arg(doc->documentName()).arg(doc->url().pathOrUrl()), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(doc->url().pathOrUrl());
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
    
            if (!doc->url().isEmpty() && doc->url().isLocalFile())
              alreadySeenFiles.insert (doc->url().toLocalFile());
    
            // select second document, that is the last used (beside the active one)
            if (linecount == 2)
              idxToSelect = itemName->index();
        }
    
      // get all open documents
      QList<KTextEditor::Document*> docs = Kate::application()->documentManager()->documents();
        foreach(KTextEditor::Document *doc, docs) {
            // skip docs already open
            if (alreadySeenDocs.contains (doc))
              continue;
    
            QStandardItem *itemName = new QStandardItem(doc->documentName());
    
            itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole);
            itemName->setData(QString("%1: %2").arg(doc->documentName()).arg(doc->url().pathOrUrl()), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(doc->url().pathOrUrl());
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
    
            if (!doc->url().isEmpty() && doc->url().isLocalFile())
              alreadySeenFiles.insert (doc->url().toLocalFile());
        }
    
        // insert all project files, if any project around
        if (Kate::PluginView *projectView = m_mainWindow->mainWindow()->pluginView ("kateprojectplugin")) {
          QStringList projectFiles = projectView->property ("projectFiles").toStringList();
          foreach (const QString &file, projectFiles) {
            // skip files already open
            if (alreadySeenFiles.contains (file))
              continue;
    
            QFileInfo fi (file);
            QStandardItem *itemName = new QStandardItem(fi.fileName());
    
            itemName->setData(qVariantFromValue(KUrl::fromPath (file)), UrlRole);
            itemName->setData(QString("%1: %2").arg(fi.fileName()).arg(file), SortFilterRole);
            itemName->setEditable(false);
            QFont font = itemName->font();
            font.setBold(true);
            itemName->setFont(font);
    
            QStandardItem *itemUrl = new QStandardItem(file);
            itemUrl->setEditable(false);
            base_model->setItem(linecount, 0, itemName);
            base_model->setItem(linecount, 1, itemUrl);
            linecount++;
          }
        }
    
        // swap models and kill old one
        m_model->setSourceModel (base_model);
        delete m_base_model;
        m_base_model = base_model;
    
        // пропущено
    }

    Адская копипаста. У меня мозг сегфолтится при попытке ее формализировать.

    https://projects.kde.org/projects/kde/applications/kate/repository/revisions/master/entry/kate/app/katequickopen.cpp#L135

    Elvenfighter, 16 Февраля 2014

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

    +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
    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
    template <typename T>
    class MySharedPtr{
    public:
      explicit MySharedPtr(T* obj) : _obj(obj){}
      // --> я дописал
      MySharedPtr(const MySharedPtr& other) : _obj(other._obj){ inc_ref_count(_obj);}
      // <-- я дописал
      MySharedPtr& operator=(const MySharedPtr& other) {
        // --> я дописал
        if (this == &other)
          return *this;
        // <-- я дописал
        _obj = other._obj;
        inc_ref_count(_obj);
      }
      ~MySharedPtr(){
        dec_ref_count(_obj);
      }
    
    private:
      static void inc_ref_count(T* obj){
        std::lock_guard<std::mutex> lock(_mutex);
        _ref_count[obj] ++ ;
      }
    
      static void dec_ref_count(T* obj){
        std::lock_guard<std::mutex> lock(_mutex);
        if (--_ref_count[obj]){
          delete obj;
          _ref_count.erase(_ref_count.find(obj));
        }
      }
    
      T* _obj;
    
      static std::mutex MySharedPtr<T>::_mutex;
      static std::map<T*,int> MySharedPtr<T>::_ref_count;
    };
    
    
    template <typename T>
    std::map<T*,int> MySharedPtr<T>::_ref_count;
    
    
    template <typename T>
    std::mutex MySharedPtr<T>::_mutex;

    сегодня приходил чел-выпускник, написал на листочке shared_ptr, какое ваше мнение?

    LispGovno, 14 Февраля 2014

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