3 ms·
I agree that for some people, RubyMotion may be better than ObjC. I'm not one of them. Regardless, I think your Ruby code examples could have been better chosen
by e28eta 14y ago
I agree that for some people, RubyMotion may be better than ObjC. I'm not one of them. Regardless, I think your Ruby code examples could have been better chosen:
- I'm a huge fan of Ruby's || operator, but probably wouldn't use it to dequeue or create a table cell, because the line is way too long. Perhaps this is fixable with a return after the ||
- creating labels programmatically seems like a poor example because I'd do that in my storyboard, and it would take zero lines of code. Or 6 lines of XML for 6 labels, if I'm being pedantic.
- natesm 14y agoAlso, the || operator can be written ?: in Objective-C.
- randomdata 14y agoA possible Objective-C version to create the labels looks pretty much the same to me anyway: #define MSTR(...) [[NSString stringWithFormat:__VA_ARGS__] UTF8String] @implementation LotsaLabels - (id)initWithFrame:(CGRect)frame { if (self = [super init]) { CGFloat offset = 0.0; [@[@"label1", @"label2", @"label3", @"label4"] enumerateObjectUsingBlock:^ (id object, NSInteger idx, BOOL *stop) { object_setInstanceVariable(self, MSTR(@"%@_text", object), [[UILabel alloc] initWithFrame:CGRectMake(0, 10 + offset, self.frame.size.width, 40)]); object_setInstanceVariable(self, MSTR(@"%@_label", object), [[UILabel alloc] initWithFrame:CGRectMake(0, 55 + offset, self.frame.size.width, 14)]); UILabel *text = object_getInstanceVariable(self, MSTR(@"%@_text", object)); UILabel *label = object_getInstanceVariable(self, MSTR(@"%@_label", object)); text.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:40]; text.textColor = [UIColor redColor]; label.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:15]; text.textColor = [UIColor grayColor]; text.text = label.text = [object capitalizedString]; text.adjustsFontSizeToFitWidth = label.adjustsFontSizeToFitWidth = YES; text.backgroundColor = label.backgroundColor = [UIColor clearColor]; text.textAlignment = label.textAlignment = UITextAlignmentCenter; [self addSubview:text]; [self addSubview:label]; offset += 90.0; }]; } return self; } @end The Ruby version is slightly less verbose, I'll give him that, but many of the lines are nearly identical.