Субъективный Си / Говнокод #18104 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
- (void) doSomething {
    <...>
    if (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut) {
        @synchronized (self.failedURLs) {
            
            {
                // javascript-style...
                char* xcEnv = getenv("XcodeColors");
                BOOL useColors = (xcEnv && !strcmp(xcEnv, "YES"));
                NSString *colorWrapper;
                if (useColors)
                    colorWrapper = @"\033[fg0,153,0;%@\033[;";
                else
                    colorWrapper = @"%@";

                void (^colorLog)(NSString *format, ...) = ^(NSString *format, ...)
                {
                    va_list args;
                    va_start(args, format);
                    NSLog(colorWrapper, [[NSString alloc] initWithFormat:format arguments:args]);
                    va_end(args);
                };
                
                colorLog(@"SDWebImageManager download failed");
                colorLog(@"\turl: %@", url.absoluteString);
                colorLog(@"\terror: %@", [error description]);
            }
            
            
            [self.failedURLs addObject:url];
        }
    }
    <...>
}

Когда очень хочется извратиться

krypt krypt, (Updated )

Комментарии (1, +1)

Субъективный Си / Говнокод #18013 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
#pragma mark - class methods
+ (CGFloat)cellHeightForCategory:(PostCategory *)category subscribed:(BOOL)subscribed
{
    static CategoryTableViewCell *cell = nil;
    if(!cell) {
        cell = [[[UINib nibWithNibName:NSStringFromClass([self class]) bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil] firstObject];
    }
    [cell setupCellForCategory:category subscribed:subscribed];
    [cell layoutIfNeeded];
    return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize].height;
}

Задаёмся мы тут вопросом, почему это таблица загрузке данных зависает на 5 секунд...

krypt krypt, (Updated )

Комментарии (9, +9)

Субъективный Си / Говнокод #17947 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
[self.userView sd_setImageWithURL:[comment.sender avatarThumbnailURL] placeholderImage:[UIImage coloredAvatarWithId:[NSString stringWithFormat:@"%lld", comment.sender.idValue]
																									 andName:comment.sender.firstName
																									  ofSize:CGSizeMake (57, 57)]];

	self.dateLabel.text = [self tsFromDate:comment.createdAt];

	[self.dateLabel sizeToFit];

	if (comment.sender == [SWCore account])
	{
		self.balloonImage.image = [[UIImage imageNamed:@"in_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];

		self.messageLabel.textColor = [UIColor colorWithWhite:.4f alpha:1.0f];

		self.userView.left = 20;
		self.balloonImage.right = 300;
		self.dateLabel.right = self.balloonImage.right;
		self.dateIcon.right = self.dateLabel.left - 3;
	}
	else
	{
		self.balloonImage.image = [[UIImage imageNamed:@"out_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];

		self.messageLabel.textColor = [UIColor whiteColor];

		self.userView.right = 300;
		self.balloonImage.left = 20;
		self.dateIcon.left = self.balloonImage.left;
		self.dateLabel.left = self.dateIcon.right + 3;
	}

Мастерское владение размерами

shadeapps shadeapps, (Updated )

Комментарии (156, +156)

Субъективный Си / Говнокод #17943 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell = nil;

	if (indexPath.row == self.titles.count - 1)
	{
		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];

		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;

		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];

		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];

		scell.settingIcon.visible = YES;

		@weakify(self);
		[scell.settingButton bk_addEventHandler:^(id sender) {
			[UIAlertView bk_showAlertViewWithTitle:@"Logout"
										   message:@"Do you want to logout?"
								 cancelButtonTitle:@"NO"
								 otherButtonTitles:@[@"YES"]
										   handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
											   @strongify(self);

											   if (buttonIndex != 0)
											   {
												   [[SWCore instance] logout];
                                                   // fix
                                                   [SVProgressHUD show];
                                                   // end fix
											   }
										   }];
		}                      forControlEvents:UIControlEventTouchUpInside];
	}
	else if (indexPath.row == self.titles.count - 2)
	{
		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];

		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;

		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];

		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];

		scell.settingIcon.visible = NO;

		@weakify(self);
		[scell.settingButton bk_addEventHandler:^(id sender) {

			@strongify(self);
			[self performSegueWithIdentifier:@"pushSettingsSegue" sender:nil];
		}                      forControlEvents:UIControlEventTouchUpInside];
	}
	else
	{
		cell = [tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];

		SWSettingCell *scell = (SWSettingCell *) cell;

		scell.settingLabel.text = self.titles[indexPath.row];
		[scell.settingIcon setImage:self.icons[indexPath.row]];

		switch (indexPath.row)
		{
			case 0:
			{
				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PROFILE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_profile_icon_on"] : [UIImage imageNamed:@"settings_profile_icon_off"];
			}
				break;

			case 1:
			{
				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_EVENTS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_events_button_on"] : [UIImage imageNamed:@"settings_events_button_off"];
			}
				break;

			case 2:
			{
				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHONE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_phone_button_on"] : [UIImage imageNamed:@"settings_phone_button_off"];
			}
				break;

			case 3:
			{
				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHOTOS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_photos_button_on"] : [UIImage imageNamed:@"settings_photos_button_off"];
			}
				break;

			default:
				break;
		}

		scell.settingSwitch.tag = indexPath.row;
		[scell.settingSwitch bk_removeEventHandlersForControlEvents:UIControlEventValueChanged];

Один из самых классных методов cellForRowAtIndexPath что я когда-либо видел

shadeapps shadeapps, (Updated )

Комментарии (11, +11)

Субъективный Си / Говнокод #17942 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	if (self.mode == EventsMode)
	{
		SWEvent *event = [self.eventsController.dataModel itemAtIndexPath:indexPath];

		static NSString *CellIdentifier = @"actionCell";
		SWActionCell    *cell           = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

		[cell formatForEvent:event];

		@weakify(self);
		@weakify(cell);

		if (![cell.actionButton_1 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
		{
			[cell.actionButton_1 bk_addEventHandler:^(id sender) {
				@strongify(cell);

				SWEvent *cellEvent = cell.event;

				if (cellEvent.isLikedValue)
				{
					[[SWCore instance] unlikeEvent:cellEvent];
				}
				else
				{
					[[SWCore instance] likeEvent:cellEvent];
				}

			}                      forControlEvents:UIControlEventTouchUpInside];
		}

		if (![cell.actionButton_2 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
		{
			[cell.actionButton_2 bk_addEventHandler:^(id sender) {
				@strongify(self);
				@strongify(cell);

				SWEvent *cellEvent = cell.event;

				self.presentController = [SWMediaController controllerWithEvent:cellEvent];
				[self.presentController addPhotoInController:self];
			}                      forControlEvents:UIControlEventTouchUpInside];
		}

		if (![cell.actionButton_3 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
		{
			[cell.actionButton_3 bk_addEventHandler:^(id sender) {
				@strongify(self);
				@strongify(cell);

				SWEvent *cellEvent = cell.event;

				[self performSegueWithIdentifier:@"commentsSegue" sender:cellEvent];
			}                      forControlEvents:UIControlEventTouchUpInside];
		}


		if (![cell.actionButton_4 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
		{
			[cell.actionButton_4 bk_addEventHandler:^(id sender) {
				@strongify(self);
				@strongify(cell);

				SWEvent *cellEvent = cell.event;
				self.presentController = [SWMediaController controllerWithEvent:cellEvent];
				[self.presentController openPhotoBrowserInNavigationController:self.navigationController];
			}                      forControlEvents:UIControlEventTouchUpInside];
		}


		if (![cell.nextButton bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
		{
			[cell.nextButton bk_addEventHandler:^(id sender) {
				@strongify(self);
				@strongify(cell);

				SWEvent *cellEvent = cell.event;

				[self performSegueWithIdentifier:@"eventControllerSegue" sender:cellEvent];

			}                  forControlEvents:UIControlEventTouchUpInside];
		}


		return cell;
	}

Найдено в одном чужих из проектов. Призываем экспертов по говнокоду чтобы прокомментировать неочевидные решения автора и пролить свет на тайну этого метода

shadeapps shadeapps, (Updated )

Комментарии (2, +2)

Субъективный Си / Говнокод #17902 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
if (indexPath.row == 0) {
        if (![centerViewController isKindOfClass:[T7DUserInfoViewController class]]) {
            T7DUserInfoViewController *userViewController = [[T7DUserInfoViewController alloc] init];
            [navigationController popViewControllerAnimated:NO];
            [navigationController pushViewController:userViewController animated:NO];
        }
    }
    if (indexPath.row == 1) {
        if (![centerViewController isKindOfClass:[T7DMapViewController class]]) {
            T7DMapViewController *mapViewController = [[T7DMapViewController alloc] init];
            [navigationController popViewControllerAnimated:NO];
            [navigationController pushViewController:mapViewController animated:NO];
        }
    }
    if (indexPath.row == 2) {
        if (![centerViewController isKindOfClass:[T7DOrderListViewController class]]) {
            T7DOrderListViewController *orderListViewController = [[T7DOrderListViewController alloc] init];
            [navigationController popViewControllerAnimated:NO];
            [navigationController pushViewController:orderListViewController animated:NO];
        }
    }
    if (indexPath.row == 3) {
        if (![centerViewController isKindOfClass:[T7DCurrentOrderViewController class]]) {
            T7DCurrentOrderViewController *orderViewController = [[T7DCurrentOrderViewController alloc] init];
            [orderViewController setOrderType:T7DOrderTypeCurrent];
            [orderViewController setOrder:[T7DOrder currentOrder]];
            [navigationController popViewControllerAnimated:NO];
            [navigationController pushViewController:orderViewController animated:NO];
        }
    }
    if (indexPath.row == 4) {
        if (![centerViewController isKindOfClass:[T7DMessagesViewController class]]) {
            T7DMessagesViewController *messagesViewConroller = [[T7DMessagesViewController alloc] init];
            [navigationController popViewControllerAnimated:NO];
            [navigationController pushViewController:messagesViewConroller animated:NO];
        }
    }
    if (indexPath.row == 5) {
        [self logout];
        return;
    }

Мудаки.

pr0gl pr0gl, (Updated )

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