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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    bool MyClass::operator==(int elem){
        if (list.isExist(elem)){
            list.remove(elem);
            return true; // Операция завершена успешно
        }
        return false; // Элемент elem не найден в списке
    }

    (C) https://www.linux.org.ru/forum/development/14063699?cid=14063991

    Вырвано из контекста (треда), но считаю данная кучка должна лежать здесь.

    Elvenfighter, 05 Марта 2018

    Комментарии (6)
  2. JavaScript / Говнокод #23869

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    new Template('device.matrix.container').load(function (container_tpl) {
    	new Template('device.matrix.device').load(function (device_tpl) {
    		new Template('device.matrix.port').load(function (port_tpl) {
    			new ApiCall('device.matrix.list')
    				.set('house', event.house_id)
    				.do(function (r) {
    					// Do anything
    				})
    		});
    	});
    });

    How don't need to write JS.

    DAVIDhaker, 05 Марта 2018

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

    +9

    1. 1
    Argument type mismatch

    Assertion failed

    Exception, 04 Марта 2018

    Комментарии (25)
  4. Pascal / Говнокод #23863

    +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
    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
    var
     DPen: TGPPen;
     Drawer: TGPGraphics;
     DBrush: TGPSolidBrush;
     DFntFam: TGPFontFamily;
     DPath: TGPGraphicsPath;
     IC,BC:Integer;
     ICL, BCL:TGPColor;
     W:WideString;
     si:TGPRectF;
     rt:TGPRectF;
     GP:TGPPoint;
    begin
      W:=FWaterMark.Text;
      IC:=ColortoRGB(FWaterMark.Font.Color);
      BC:=ColorToRGB(FWaterMark.CircuitColor);
      ICl:=MakeColor(GetRValue(IC), GetGValue(IC), GetBValue(IC));
      BCL:=MakeColor(GetRValue(BC), GetGValue(BC), GetBValue(BC));
      Drawer:=TGPGraphics.Create(FBitMap.Canvas.Handle);
      Drawer.SetCompositingQuality(CompositingQualityHighQuality);
      Drawer.SetSmoothingMode(SmoothingModeAntiAlias);
      Drawer.SetTextRenderingHint(TextRenderingHintAntiAlias);
      DPath:=TGPGraphicsPath.Create;
      DPen:=TGPPen.Create(BCL, FWaterMark.FCircuitWidth);
      DBrush:=TGPSolidBrush.Create(ICL);
      DFntFam:=TGPFontFamily.Create(FWaterMark.Font.Name);
    
      RT.X:=0;
      RT.Y:=0;
      RT.Width:=FBitMap.Width;
      RT.Height:=FBitMap.Height;
      
      DPath.AddString(W, Length(W), DFntFam, FontStyleBold, FWaterMark.Font.Size, GP, TGPStringFormat.Create()); 
      DPath.GetBounds(RT, nil, DPen);
      DPath.Reset; 
    
    //В общем, хз, как узнать ширину и высоту нарисованного.
    //MeasureString/MeasureCharacterRanges не подходят,а в доке такая муть, что я чуть не спился.

    Нежнейший аромат...

    Exception, 04 Марта 2018

    Комментарии (272)
  5. Си / Говнокод #23862

    +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
    // https://github.com/Samsung/ADBI/blob/3e424c45386b0a36c57211da819021cb1929775a/idk/include/division.h#L138
    
    /* Long division by 10. */
    static unsigned long long int div10l(unsigned long long int v) {
    
        /* It's a kind of magic.  We achieve 64-bit (long) division by dividing the two 32-bit halfs of the number 64-bit
         * number.  The first (most significant) half can produce a rest when dividing, which has to be carried over to the
         * second half.  The rest_add table contains values added to the second half after dividing depending on the rest
         * from the first division.  This allows evaluation of a result which is almost correct -- it can be either the
         * expected result, or the expected result plus one.  The error can be easily detected and corrected.
         */
        
        /* one dream */
        static unsigned long long int rest_add[] = {
            0x00000000, 0x1999999a, 0x33333334, 0x4ccccccd, 0x66666667,
            0x80000001, 0x9999999a, 0xb3333334, 0xcccccccd, 0xe6666667
        };
        
        /* one soul */
        unsigned long long int a = div10((unsigned int)(v >> 32));
        unsigned long long int b = div10((unsigned int)(v & 0xffffffff));
        
        /* one prize */
        int ri = (v >> 32) - a * 10;
        
        /* one goal */
        unsigned long long int ret = (a << 32) + b + rest_add[ri];
        
        /* one golden glance */
        if (ret * 10L > v) {
            //printf("OGG %llu %llu\n", ret * 10, v);
            --ret;
        }
        
        /* of what should be */
        return ret;
    }

    Деление на 10. Но зачем? Неужели компилятор настолько туп, что сам не может этого сделать?
    И да, эти туповатые комментарии one dream, one soul это отсылка к песне Queen - A Kind of Magic https://youtu.be/0p_1QSUsbsM

    j123123, 03 Марта 2018

    Комментарии (52)
  6. Куча / Говнокод #23861

    0

    1. 1
    https://habrahabr.ru/post/348744/

    Обнаружен пидар.

    subaru, 03 Марта 2018

    Комментарии (20)
  7. Haskell / Говнокод #23859

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    data Foo a = Foo {a :: a, b :: Int}
               | Bar {b :: Int}
    
    foo :: (a -> b) -> Foo a -> Foo b
    foo f x@Foo{a = a} = x{a = f a}
    foo _ x@Bar{} = x   -- error: Couldn't match type ‘a’ with ‘b’
    foo _ x@Bar{} = x{} -- error: Empty record update

    Рекорды всё-таки дубовые

    cast @HaskellGovno

    CHayT, 03 Марта 2018

    Комментарии (32)
  8. JavaScript / Говнокод #23858

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    var i, j;
    
    loop1:
    for (i = 0; i < 3; i++) {      //The first for statement is labeled "loop1"
       loop2:
       for (j = 0; j < 3; j++) {   //The second for statement is labeled "loop2"
          if (i === 1 && j === 1) {
             continue loop1;
          }
          console.log('i = ' + i + ', j = ' + j);
       }
    }

    Метки в js. Баян?
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

    vistefan, 03 Марта 2018

    Комментарии (6)
  9. Куча / Говнокод #23856

    −2

    1. 1
    Что за браузер?

    AntiUeban, 03 Марта 2018

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

    −1

    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
    #include <iostream>
    using namespace std;
    struct MyType { MyType() {  cout << __PRETTY_FUNCTION__ << endl; }};
    MyType& MyType() { cout << __PRETTY_FUNCTION__ << endl; }
    using MyType2 = struct MyType;
    int main() {
      // MyType t; <- error: expected ‘;’ before ‘t’
      MyType();
      struct MyType t;
      struct MyType t1 = MyType();
      struct MyType t2 = (struct MyType)::MyType();
      struct MyType t3 = MyType2();
      new(&t2) struct MyType();
      return 0;
    }

    Крестоблядство по мотивам #23850.
    https://ideone.com/XcK2hf.
    Особенно меня порадовал каст на 11 строчке.

    Bobik, 03 Марта 2018

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