1. C# / Говнокод #12486

    +113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private int GenerateRandom(int MaxValue)
    {
        var mas = Guid.NewGuid().ToByteArray();
        return BitConverter.ToInt32(mas, 4) % MaxValue;
    }

    ....

    roman-kashitsyn, 28 Января 2013

    Комментарии (28)
  2. PHP / Говнокод #12485

    +41

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static function getById( $id )
    {
      $model = new self;
      $data  = $model->load();
      foreach( $data AS $item ){
        if( $item->id == $id ){
          return $item;
        }
      }
      return null;
    }

    Нашел в текущем проекте.

    grdExh, 28 Января 2013

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

    +142

    1. 1
    2. 2
    if ($options->get('registrationSetup', 'requireDob')) {
    	// dob required

    Без ДОБ-а не пущу.

    DropWorld, 28 Января 2013

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

    +22

    1. 1
    2. 2
    3. 3
    4. 4
    list<int> list;
    ...
    for(auto i=0;i<list.size();i++){
        auto item = *next(list.begin(), i);

    Вчера у меня появился каллега.
    http://liveworkspace.org/code/1AWg24$5
    Кажется я знаю, кто следующий будет сидеть на табуретке. Думаете стоит сказать ему?

    LispGovno, 27 Января 2013

    Комментарии (108)
  5. Куча / Говнокод #12482

    +130

    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
    import std.stdio; 
    class Parent{ } 
    class Another{ } 
    class Child: Parent
    {
      Another data;
      alias data this;  
      this()
      {
      data = new Another;
      }
    }
     void test(Parent t){writeln("Parent: ", t);}
     void test(Another t){writeln("Another: ", t);}
     void main() { 
        auto Me = new Child();    
        test(Me);
    }

    Интуитивного свежачка вам.
    http://ideone.com/qEDzz
    http://ideone.com/9mB8S

    LispGovno, 27 Января 2013

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

    +18

    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
    template <typename Derived>
    class Base {
    public:
    	void doSmth() {
    		// ...
    		static_cast<Derived*>(this)->OnParseAndHandle();
    		//...
    	}
    };
    
    class MyClass: public Base<MyClass> {
    public:
    	void OnParseAndHandle() {
    		// ...
    	}
    };

    Если Вы не верите в виртуальные методы, то шаблоны Вам в помощь.

    А может я идиот и чего-то не понял?

    benderlog, 26 Января 2013

    Комментарии (31)
  7. C++ / Говнокод #12480

    +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
    // *.h
    class MyClass {
    
    public:
    	MyClass ();
    	~MyClass ();
    	// ..etc
    
    };
    
    // *.cpp
    #include "*.h"
    
    MyClass *mycl;
    
    MyClass::MyClass ()
    {
    	mycl=this; // эту строчку не удалять без нее не работает, точнее не всегда работает иногда сбоит
    }
    
    MyClass::~MyClass ()
    {
    }

    Простите меня пожалуйста. Я уныл чуть мене чем полностью, но почему человек которые это написал хороший программист. Это писал не я. Извините пожалуйста за беспокойство :( ..

    neudachnik, 25 Января 2013

    Комментарии (87)
  8. Pascal / Говнокод #12478

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var
          sMem: String;
    .......
    case Byte(sMem[len]) of
          Word('k'): { Что то делаем };
          Word('m'): { Что то делаем };
          Word('g'): { Что то делаем };
    end;

    Вот такой вот гавнокод

    haker, 25 Января 2013

    Комментарии (10)
  9. PHP / Говнокод #12477

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function accuire($array = array()) {
            return $this->acquire($array);
        }
    
        public function acquire($array = array()) {

    Spell-master

    jfhs, 25 Января 2013

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

    +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
    buildTree sentence graph =
        (M.lookup (0, length sentence - 1, DirLeft) finalGraph, finalGraph)
        where finalGraph = execState runEisner (M.fromList elementaryPathes)
              elementaryPathes =
                 map (\(i, word) -> ((i, i, DirLeft), elementaryPath DirLeft word)) indexed ++
                 map (\(i, word) -> ((i, i, DirRight), elementaryPath DirRight word)) indexed
              indexed = zip [0..] sentence
    
              runEisner = do
                  let len = length sentence
                  forM_ [1 .. len - 1] $ \l -> do
                      forM [0 .. len - 1 - l] $ \i -> do
                          matrix <- get
                          let j = i + l
                          let w1 = sentence !! i
                          let w2 = sentence !! j
    
                          let buildConcat dir = (catMaybes $ (zipWith (\p1 p2 -> join $ (liftM2 concatenatePath) p1 p2)
                                                [M.lookup (i, k, dir) matrix | k <- [i + 1 .. j - 1]]
                                                [M.lookup (k, j, dir) matrix | k <- [i + 1 .. j - 1]])) :: [Path]
    
                          let buildJoin dir key = fromMaybe [] $ M.lookup key graph >>= \link ->
                                                  return (catMaybes (zipWith (\p1 p2 -> join $ (liftM2 (\f c -> joinPath f c link)) p1 p2)
                                                  [M.lookup (i, k, dir) matrix | k <- [i .. j - 1]]
                                                  [M.lookup (k, j, rev dir) matrix | k <- [i + 1 .. j]]))
    
                          let posR = (buildConcat DirRight ++ buildJoin DirRight (w1, w2)) :: [Path]
    
                          let newMatrix = if (not . null) posR
                                              then M.insert (i, j, DirRight) (minimumBy compWeight posR) matrix
                                              else matrix
    
                          let posL = buildConcat DirLeft ++ buildJoin DirRight (w2, w1)
    
                          let newMatrix' = if (not . null) posL
                                               then M.insert (i, j, DirLeft) (minimumBy compWeight posL) matrix
                                               else newMatrix
    
                          put newMatrix'

    Кусок из диплома по NLP. Yuuri неделю как познал монаду State и сделал двумерный императивный цыкл.

    Yuuri, 25 Января 2013

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