1. Objective C / Говнокод #13464

    −101

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    @implementation NSString (toint)
    - (long long)toInt {
        if (self == nil) return 0;
        if (self.length == 0) return 0;
       return [self longLongValue];
    }
    @end

    В этом коде все прекрасно. Я просто оставлю это здесь. Джава головного мозга.

    notxcain, 22 Июля 2013

    Комментарии (14)
  2. Objective C / Говнокод #13463

    −120

    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
    - (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
    {
        if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
        {
            return nil;
        };
    
        NSFetchRequest *fr=[[NSFetchRequest alloc] init];
        [fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
        [fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
        [fr setIncludesPropertyValues:YES];
        NSError *err;
        NSArray *res=[context executeFetchRequest:fr error:&err];
        if (err!=nil)
        {
            NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
            return nil;
        }
        else
        {
            if ([res count]<=0)
            {
                NSLog(@"[res count]<=0");
                //NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
                return nil;
            }
            else if([res count]>1)
            {
                NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
                return nil;
            }
            else //[res count] == 1
            {
                return [res objectAtIndex:0];
            };
        };
    }

    Фетч

    stanislaw, 21 Июля 2013

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

    −115

    1. 1
    user.status = (user.status == 0)?1:0

    Hits, 16 Июля 2013

    Комментарии (24)
  4. Objective C / Говнокод #13427

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //написали и нам на кодревью сказали что это Оо
    if (([someobj1.index isEqualToNumber:someobj2.index] ? YES : NO)) {...}
    //рефакторим в:
    BOOL *check;
    [someobj1.index isEqualToNumber:someobj2.index] ? (check=YES) : (check = NO)
    if (check) {...}
    //видим что среда ругается и наконец рождаем
    if ([someobj1.index isEqualToNumber:someobj2.index]) {...}

    перлы все тогоже джуна

    torip3ng, 15 Июля 2013

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

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    @implementation ESpeaker
    
    EParticipantQueryGettersGroupForTypeWithSuffix(Speaker,SESSION_COUNT_OFF,LIKES_ON FAV_ON,kEDBAccessorTypePoolEventAndPrivate,ZERO_SESSION_COUNT_ON,);
    EParticipantQueryGettersGroupForTypeWithSuffix(Speaker,SESSION_COUNT_ON_WITH_TYPE,LIKES_ON FAV_ON,kEDBAccessorTypePoolEventAndPrivate,ZERO_SESSION_COUNT_OFF,WithSessionCount);
    
    @end

    От авторов Objective-C говнокода месяца!
    Первый в истории программирования класс, полностью реализованный на дефайнах!

    Продолжение в комментариях!

    Headless, 11 Июля 2013

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

    −110

    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
    // last parameter is the setter code if value allowed to be set
    #define SET_USING_CONFIG(cellSwitch,configKey,...)\
                cell.cellSwitch = [(EExhibitorsListConfigItem*)[self.configInfo configItemAtIndex:0] configKey];\
                if (cell.cellSwitch) {\
                    __VA_ARGS__;\
                }
    
     SET_USING_CONFIG(isLikesCountOn, showLikes,
        cell.likesCount = exhibitor.Rating;
        cell.likedByMe  = exhibitor.IsRated; );
    
    SET_USING_CONFIG(isInFavoritesOn, showFavoritesIndicator,
                         
        __weak EExhibitorCell *weakCell = cell;
    
        cell.didChangeFavouritesStateBlock = ^(BOOL newFavState) {
            [EExhibitorsListViewController updateFavoriteState:newFavState
                              ofExhibitor:exhibitor
                                   inCell:weakCell];
        };
    );

    Define master!

    Headless, 08 Июля 2013

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

    −103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    - (void)updateRating 
    {
        [NSObject cancelPreviousPerformRequestsWithTarget:self
                                                 selector:@selector(delayedUpdateRating)
                                                   object:nil];
        [self performSelector:@selector(delayedUpdateRating)
                   withObject:nil
                   afterDelay:0];
    }

    Коллега занес покушать.
    Большой проект, для американцев, пишут ребята из Днепра...

    clockworkman, 05 Июля 2013

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

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            false ? YES : NO;
    }

    Продолжаем тему укуренных сравнений

    krypt, 02 Июля 2013

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

    −99

    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
    - (void)initPlayerViewController
    {
    	BOOL isSuccess = NO;
    	do {
    		NSString *linkString = nil;
    		unsigned long long objectID = [_videoID intValue];
    		
    		int index = GetElementIndex(objectID, _WidevineTestStubs, WIDEVINE_TEST_COUNT);
    		if (index >= 0) {
    			//linkString = GetLink(_WidevineTestServers[index], _WidevineTestFiles[index]);
    			linkString = _WidevineTestLinks[index];
    		}
    		else {
    			linkString = GetString([_videoLink objectForKey:@"src"]);
    		}
    		if(linkString == nil)
    			goto _end;
    
    		self.linkType = GetLinkType(linkString);
    		switch (_linkType) {
    			case LINK_TYPE_HLS:
    				break;
    			case LINK_TYPE_WV_ADAPTIVE:
    			case LINK_TYPE_WV_MULTI:
    				linkString = WidevinePlay(linkString);
    				if ([linkString length] <= 0) {
    					goto _end;
    				}
    				break;
    			default:
    				goto _end;
    		}
    		
    		NSURL *link = [NSURL URLWithString:linkString];
    		if(link == nil)
    			break;
    
    		self.playerViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:link] autorelease];
    		_playerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    		_playerViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    
    		NSInteger startPosition = GetInteger([_videoLink objectForKey:@"play_start_time"]);
    		if(startPosition > 0) {
    			_playerViewController.moviePlayer.initialPlaybackTime = (NSTimeInterval)startPosition;
    		}
    		
    		[self addControlsView];
    		NSArray *audioTracks = [_videoLink objectForKey:@"audio_list"];
    		if ([audioTracks count] < 2) {
    			UIButton *audioButton = (UIButton *)[_controlsView viewWithTag:TAG_BUTTON_CHANGE_AUDIO];
    			audioButton.enabled = FALSE;
    		}
    		
    		isSuccess = YES;
    	} while(0);
    _end:
    	if(isSuccess) {
    		[_delegate onPlayerCreated:self];
            [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    	}
    	else {
    		[_delegate onLinkError:self];
    	}
    }

    Тут есть все, и do while(0), и проваливающиеся case'ы, и TRUE/FALSE, и глобальные inline методы, и даже goto.

    ArtFeel, 13 Июня 2013

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

    −89

    1. 1
    2. 2
    const char *aPositionCString = [@"a_position" cStringUsingEncoding:NSUTF8StringEncoding];
    GLuint aPosition = glGetAttribLocation(program, aPositionCString);

    Вместо того, чтобы написать так:
    GLuint aPosition = glGetAttribLocation(program, "a_position");

    zummenix, 03 Июня 2013

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