Skip to content

iPhone Coding WTF

by Tomek on December 5th, 2010

I was asked to code some enhancements to existing iPhone app. I was told it suffered from a lot of bugs leading to crashes and even twice rejection by App Store review team. I was preparing for, quoting last words of Kurtz: "The horror! The horror!".

Unfortunately it came true. Obvious truth has been proved once more: you may know the programming language, and even API, but software design is left behind. Main app controller class was almost 3000 lines long, and below you can find one of my favorite pieces.

The morale is short and simple: stop thinking in Turbo Pascal. Objective-C, as name suggests is object-oriented language, so for God's sake, use it!

Masterpiece example is to be seen below...

for (int i=0; i<8; i++) {
   // ... (few lines omited)
 
switch (i) {
  case 0:
  {
    btn.tag = 0;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 0) btn.selected = YES;
    }
  }
    break;
  case 1:
  {
    btn.tag = 5;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 5) btn.selected = YES;
    }
  }
    break;
  case 2:
  {
    btn.tag = 15;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 15) btn.selected = YES;
    }
  }
    break;
  case 3:
  {
    btn.tag = 30;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 30) btn.selected = YES;
    }
  }
    break;
  case 4:
  {
    btn.tag = 45;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 45) btn.selected = YES;
    }
  }
    break;
  case 5:
  {
    btn.tag = 60;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 60) btn.selected = YES;
    }
  }
    break;
  case 6:
  {
    btn.tag = 120;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 120) btn.selected = YES;
    }
  }
    break;
  case 7:
  {
    btn.tag = 180;
    if (_selectedDay != nil) {
      int ab = 60 * [[_selectedDay valueForKey:@"hour"] intValue] +
        [[_selectedDay valueForKey:@"minute"] intValue];
      if (ab == 180) btn.selected = YES;
    }
  }
  break;
}
}

From → iphone, programming, wtf

One Comment
  1. Well… Turbo Pascal is a multi paradigm language from version 5.5 on :) If someone would write stuff like that in TP I’d probably cut their fingers and stick’em where the sun doesn’t shine :) It’s really a horrible piece of code even by TP standards.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

Comment spam protected by SpamBam