1. C++ / Говнокод #11625

    +27

    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
    // до рефакторинга
    if(!y) {
        if(!x) {
            if(grid[pos+1] || grid[pos+fieldWidth])
                ret = true;
        } else if(x == fieldWidth - 1) {
            if(grid[pos - 1] || grid[pos+fieldWidth])
                ret = true;
        } else {
            if(grid[pos-1] || grid[pos+1] || grid[pos+fieldWidth])
                ret = true;
        }
    } else if(y == fieldHeigth - 1) {
        if(!x) {
            if(grid[pos+1] || grid[pos-fieldWidth])
                ret = true;
        } else if(x == fieldWidth - 1) {
            if(grid[pos - 1] || grid[pos-fieldWidth])
                ret = true;
        } else {
            if(grid[pos-1] || grid[pos+1] || grid[pos-fieldWidth])
                ret = true;
        }
    } else {
        if(!x) {
            if(grid[pos+1] || grid[pos+fieldWidth] || grid[pos-fieldWidth])
                ret = true;
        } else if(x == fieldWidth - 1) {
            if(grid[pos - 1] || grid[pos+fieldWidth] || grid[pos+fieldWidth])
                ret = true;
        } else {
            if(grid[pos - 1] || grid[pos+fieldWidth] || grid[pos-fieldWidth] || grid[pos + 1])
                ret = true;
        }
    }
    
    // после рефакторинга
    bool ret = getGridPoint(x-1, y) || getGridPoint(x+1, y) || getGridPoint(x, y-1) || getGridPoint(x, y+1))

    Код одного из моих друзей. Проверяет закрашена ли хотя бы одна клеточка вокруг указанной...

    bormand, 20 Августа 2012

    Комментарии (13)
  2. C++ / Говнокод #11624

    +19

    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
    ??=include <iostream>
     
    template <typename T> class TSingleton: public T
    ??<
       public:
          static T& instance(void)
          ??<
             static T instance;
             return instance;
          ??>;
    ??>;
     
    class TOscillStatisticko
    ??<
       protected:
            TOscillStatisticko(void):_countNewInSmallPool(0), _countDeleteInSmallPool(0) ??<??>;
            
            friend class TSingleton <TOscillStatisticko>;
     
       private:
          int _countNewInSmallPool;
          int _countDeleteInSmallPool;
     
       public:
          void addCountNewInSmallPool(void)
          ??<
             _countNewInSmallPool++;
          ??>
     
          int countNewInSmallPool(void)
          ??<
             return _countNewInSmallPool;
          ??>
    ??>;
     
    typedef TSingleton <TOscillStatisticko> TOscillStatistic;
     
    int main() 
    ??<
        TOscillStatistic::instance().addCountNewInSmallPool();
        std::cout<<TOscillStatistic::instance().countNewInSmallPool()<<std::endl;
        std::cout<<"ko"<<std::endl;
    ??>

    http://ideone.com/dt9L9
    Ладно, раз уж я так палюсь, то придется признаться: у меня просто сломалась клавиатура, потому сегодня пришлось написать немного странно...
    Так вот вопрос:, почему, если закомментировать строку

    friend class TSingleton <TOscillStatisticko>;
    http://ideone.com/4WBGh

    HaskellGovno, 20 Августа 2012

    Комментарии (32)
  3. Куча / Говнокод #11623

    +125

    1. 1
    sed -e 's/^/;;/g;s/$/ /g' -e :a -e '1!x;1h;s/.*\(.\)$/\1/;p;x;s/\(.*\).$/\1/;h;ta' ~/src/find_world.sh |  sed -e :a -e 'N;s/\n//g;ba' | sed -e 's/;;/\n/g' -e 's/^[ ]*//g'

    rev

    AliceGoth, 20 Августа 2012

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

    +38

    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
    const NMath::TLineEquation<> C_E_(C_, E_);
    		const NMath::TLineEquation<> D_A_(D_, A_);
    		const NMath::TVector<2> F_=C_E_.Intersection(D_A_);
    		TSafeFloat lpr=_state._safeDistance->Value()+_state._instrumentRadius->Value();
    		if((F_-B).Length()>lpr)
    		{
    			const NMath::TVector<2> F__=(D_+E_)/2.0;//F
    			//...
    			const NMath::TVector<2> TV=D_-E_;
    			const NMath::TVector<2> F___=PointAtDistance(B,TV,lpr, m90);//F*
    			const NMath::TVector<2> DEDir=rt90(F___-B, m90).Normalize()*10;
    			const NMath::TLineEquation<> DE(F___,F___+DEDir);
    			const NMath::TVector<2> E=DE.Intersection(C_E_);
    			const NMath::TVector<2> D=DE.Intersection(D_A_);
    			TpointerAnyCommand result;
    			result=new TLineCommand(CurrentCommand.SourceCommand(),E-C_,OnOffCorrectionEmpty);
    			_resultDestination.push(result);
    			result=new TLineCommand(CurrentCommand.SourceCommand(),D-E,OnOffCorrectionEmpty);
    			_resultDestination.push(result);
    			result=new TLineCommand(CurrentCommand.SourceCommand(),D_-D,OnOffCorrectionEmpty);
    			_resultDestination.push(result);
    		}

    Говногость, 20 Августа 2012

    Комментарии (35)
  5. C# / Говнокод #11621

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public int getFileRowsCount(string pathToFile)
    {
           System.IO.TextReader streamReader = new System.IO.StreamReader(pathToFile);
           int rowsCounter = 0;
           while ((streamReader.ReadLine()) != null)
           {
               rowsCounter++;
           }
           streamReader.Close();
           return rowsCounter;
    }

    Из http://habrahabr.ru/post/149877/
    И коммент афтора - "Здесь всё просто: пока не дойдём до пустой строки, прибавляем к счётчику строк единичку. Функция возвращает количество строк."

    phoenixx, 20 Августа 2012

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

    +20

    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
    #include <iostream>
    #include <boost/noncopyable.hpp>
    #include <assert.h>
    
    using namespace std;
    
    class noncopyable
      {
       protected:
          noncopyable() {}
         virtual ~noncopyable() {}
       private:  // emphasize the following members are private
          noncopyable( const noncopyable& );
          virtual const noncopyable& operator=( const noncopyable& )final = delete;
      };
    
    class T: public noncopyable
    {
    public:
       const T& operator=( const T& ){return *this;}
    };
    
    int main() {
       T a;
       a=T();
       std::cout<<"kokoko"<<std::endl;
       return 0;
    }

    http://liveworkspace.org/code/15b5716e7618cc75a6881dfdd46982d5

    В чем смысл =delete, если запретить копировать T все равно не удается? Или это ошибка не стандарта, а реализации gcc?

    HaskellGovno, 20 Августа 2012

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

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static int getRandomNumber(int from, int to)
    {
           System.Threading.Thread.Sleep(10);
           Random r = new Random();
           int var = r.Next(from, to);
           return var;
    }

    No comments

    bazhenovc, 20 Августа 2012

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

    +23

    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
    %:include <iostream>
     
    int main(int argc, char *argv<::>) 
    <%
        if (argc > 1 and argv<:1:> not_eq '\0') <%
            std::cout << "Hello " << argv<:1:> << '\n';
        %>
        std::cout<<"ko"<<std::endl;
    %>
     
     
    
    ??=include <iostream>
     
    int main(int argc, char *argv??(??)) 
    ??<
        if (argc > 1 and argv??(1??) not_eq '\0') ??<
            std::cout << "Hello " << argv??(1??) << '\n';
        ??>
        std::cout<<"ko"<<std::endl;
    ??>

    http://liveworkspace.org/code/150ad59b81b309bbffed963829f4fc9e
    http://liveworkspace.org/code/c64104e4272af4d89f2f74c35c5c2ee3
    Просто оставлю это здесь.

    HaskellGovno, 20 Августа 2012

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

    +24

    1. 1
    masko xor_eq mask;

    А вообще жаль, что эту дельфитню включили в стандарт.

    HaskellGovno, 20 Августа 2012

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

    +136

    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
    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case (int)Constants.WM_PAINT:
                {
                    rh.Clear(DotGL.Color.Blue);
                    IntPtr hdc = User32.GetDC(this.Handle);
                    IntPtr chdc = Gdi32.CreateCompatibleDC(hdc);
    
                    int err = Marshal.GetLastWin32Error();
                    if (err != 0) ;
    
                    IntPtr ppv = IntPtr.Zero;
                    IntPtr hb = Gdi32.CreateDIBSection(chdc, ref q,
                                                   Constants.DIB_RGB_COLORS,
                                                   out ppv, IntPtr.Zero, 0);
    
                    ppv = rh.data.Scan0HGlobal;
    
                    Gdi32.SetDIBitsToDevice(hdc,
                                0, 0, (uint)q.biWidth, (uint)q.biHeight,
                                0, 0, 0, (uint)q.biWidth,
                                ppv, ref q,
                                Constants.DIB_RGB_COLORS);
    
                    User32.ReleaseDC(this.Handle, hdc);
                    FPS();
                    this.Text = "FPS: " + fps.ToString() + ", MAX FPS: " + maxFps.ToString();
                } break;
           default:
                base.WndProc(ref m);
                break;
        }
    }

    Мое, родненькое.

    psina-from-ua, 20 Августа 2012

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