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

    В номинации:
    За время:
  2. Куча / Говнокод #17353

    +136

    1. 1
    2. 2
    Prelude> [(-1/0),1 .. 1]
    [-Infinity,1.0,Infinity,Infinity]

    Целых 2 бесконечности между единицей.

    Abbath, 22 Декабря 2014

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

    −402

    1. 1
    NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);

    код из afnetworking - американцы поймут что такое GET HEAD)))))))))))))

    kyzmitch, 15 Декабря 2014

    Комментарии (6)
  4. PHP / Говнокод #17312

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($class_week == 1) {
         $current_week = 1;
    } else {
         $current_week = 1;
    }

    В одном из гос. проектов нашёл..

    vGhost, 14 Декабря 2014

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

    +56

    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
    if(i%2==0)
    		{
    			for(j=int (l);j<n+int (l);j++)
    			{
    				A[i][j]=B1[k];
    				k++;
    			}	
    		}
    		else if(i%2!=0)
    		{
    			for(j=int (l);j<n+int (l);j++)
    			{
    				A[i][j]=B2[k];
    				k++;
    			}
    		}

    Когда-то один однокурсник спросил у препода:
    - А как добавить код в ИНАЧЕ от ИНАЧЕ.
    Что-то подобное увидел и в этом коде.

    FalseCoder, 11 Декабря 2014

    Комментарии (6)
  6. Си / Говнокод #17292

    +135

    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
    int log2_floor (unsigned x)
    {
        #define NIMHTNOE0WNM(n) (((~(x>>n)+1)>>n)&n)
     
        int res, n;
     
        n = NIMHTNOE0WNM(16); res  = n; x >>= n;
        n = NIMHTNOE0WNM( 8); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 4); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 2); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 1); res |= n;
        return res;
    }

    Кто-то Воррена перечитал.

    codemonkey, 11 Декабря 2014

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

    +49

    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
    #include <stdio.h>
    #include <math.h>
    #include "determinant.h"
    
    double det(double **matrix, int size)
    {
        if(size==2)
        {
            return matrix[0][0]*matrix[1][1]-matrix[0][1]*matrix[1][0];
        }
        else if(size==1)
            {
                return matrix[0][0];
            }
        int result = 0;
        for(int j=0; j<size; j++)
        {
            if(matrix[0][j]!=0)
            {
                result+=matrix[0][j]*(unsigned)pow(-1.f,(unsigned)j)*det(minor(matrix, size, 0, j), size-1);
            }
        }
        return result;
    }
    
    double **minor(double **matrix, int size, int str, int col)
    {
        double **minor=new double *[size-1];
        int m_str = 0;
        int m_col;
        for(int i=0; i<size; i++)
        {
            if(i!=str)
            {
                m_col = 0;
                minor[m_str]=new double[size-1];
                for(int j=0; j<size; j++)
                {
                    if(j!=col)
                    {
                        minor[m_str][m_col]=matrix[i][j];
                        m_col++;
                    }
                }
                m_col++;
            }
        }
        return minor;
    }

    Считаю определитель рекурсией, во время теста в этом сорце вылетает ошибка EXC_BAD_ACCESS(code=1, access=0x8),
    после одного прохода рекурсии, с чем это связано? Помогите разобраться :)

    aesc_smirnov, 07 Декабря 2014

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

    −396

    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
    @implementation SlideMenuNavigationBar
    
    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        for (UIView *aView in self.subviews) {
            
            // Correcting menu toggle button position
            if ([[aView.class description] isEqualToString:@"UIButton"] && aView.frame.origin.x < self.frame.size.width/2) {
                CGRect frame = aView.frame;
                frame.origin.x = 12; // 8 for correlation
                frame.origin.y = -1; // 1 for correlation
                aView.frame = frame;
            }
            
            if (aView.frame.origin.x > self.frame.size.width/2 && !isIPad && ![[aView.class description] isEqualToString:@"ColoredView"]) {
                CGRect frame = aView.frame;
                frame.origin.x = 260; // 8 for correlation
                frame.origin.y = -1;  // 1 for correlation
                aView.frame = frame;
            }
            
            // Correcting back button and right button positions
            if ([[aView.class description] isEqualToString:@"_UINavigationBarBackIndicatorView"]) {
                CGRect frame = aView.frame;
                frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 5; // 5 for correlation
                aView.frame = frame;
            }
            if ([[aView.class description] isEqualToString:@"UINavigationButton"]) {
                CGRect frame = aView.frame;
                frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 2; // 2 for correlation
                aView.frame = frame;
            }
            
            if ([aView isKindOfClass:[NavigationBarButton class]]) {
                CGRect frame = aView.frame;
                frame.origin.x = 278; // 8 for correlation
                frame.origin.y = 6;   // 1 for correlation
                aView.frame = frame;
            }
        }
    }
    
    @end

    фиг знает что думали :D

    l0gg3r, 11 Ноября 2014

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

    −91

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    [Embed(source = "/assets/video_preview/VideoSlideThumb.png")]
    public static const VIDEO_PREVIEW: Class;
    
    public static function get videoPreviewBD(): BitmapData
    {
    	var image : Bitmap = new VIDEO_PREVIEW ();
    	return image.bitmapData.clone();		
    }

    Когда-то давно бытовала такая пословица: What Intel giveth Microsoft taketh away. Но похоже что переходное красное знамя подхватили и в других организациях по-меньше.

    wvxvw, 04 Ноября 2014

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

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public new string ID
    {
    	get
    	{
    		return base.ID;
    	}
    	set
    	{
    		base.ID = value;
    	}
    }

    taburetka, 24 Октября 2014

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

    +117

    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
    @Override
    public void afterPersistenceInit() {
    	val conn = emProvider.get().unwrap(Connection.class);
    
    	try {
    		log.info("Transaction isolation level: {}", getLevelString(conn.getTransactionIsolation()));
    	} catch (final SQLException e) {
    		log.error("Error getting transaction isolation level", e);
    	}
    }
    
    private String getLevelString(final int isolationLevel) {
    	// Poor man's enums. Use reflection to find a constant with the given value
    	try {
    		for (val maybeLevelConstant: Connection.class.getDeclaredFields()) {
    			if (maybeLevelConstant.getType() == int.class && maybeLevelConstant.getName().startsWith("TRANSACTION_")
    					&& maybeLevelConstant.getInt(null) == isolationLevel) {
    				return maybeLevelConstant.getName();
    			}
    		}
    	} catch (final IllegalArgumentException | IllegalAccessException e) {
    		return "UNKNOWN";
    	}
    	
    	return "UNKNOWN";
    }

    Ищем рефлексией константу с нужным значением. И всё для того, чтобы напечатать её в логе. Вот что крест животворящий отсутствие энумов в legacy API делает.

    someone, 23 Октября 2014

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