• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: New Cocoa Programmer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New Cocoa Programmer


  • Subject: Re: New Cocoa Programmer
  • From: Marcel Weiher <email@hidden>
  • Date: Mon, 12 Nov 2001 09:26:09 +0100

On Sunday, November 11, 2001, at 03:20 PM, Ondra Cada wrote:

John,

John C. Randolph (JCR) wrote at Sun, 11 Nov 2001 05:11:22 -0800:
JCR> I don't quite agree with that. I notice that I don't write many
JCR> switch() statments anymore.

I do, though. Although you always can replace a switch by a number of ifs,
quite often it makes code pretty unreadable.

JCR> BTW, the most horrific Obj-C code I ever saw used "switch ([self
JCR> class])"

I don't think you saw this, unless you use your time reading code which
would never compile. The problem is that class ids are link-time constant,
and case: statements allow only compile-time ones. Just try it:

185 /tmp\> cat q.m
#import <Foundation/Foundation.h>

void main() {
switch ([NSString class]) {
case (int)[NSString class]: break; // would fail
}
186 /tmp\> cc -Wall -framework Foundation q.m
q.m: In function `main':
q.m:4: switch quantity not an integer
q.m:5: case label does not reduce to an integer constant
187 /tmp\>


Actually, this could be compiled back when class-names by themselves could be used

switch ( [myObject class] ) {
case NSString:
break;

}

I don't quite remember when class-names stopped being legal values, but I think the change was between NextStep and OpenStep.

Marcel


  • Follow-Ups:
    • Re: New Cocoa Programmer
      • From: Ondra Cada <email@hidden>
    • Re: New Cocoa Programmer
      • From: "John C. Randolph" <email@hidden>
References: 
 >Re: New Cocoa Programmer (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Regular Expressions
  • Next by Date: Re: New Cocoa Programmer
  • Previous by thread: Re: New Cocoa Programmer
  • Next by thread: Re: New Cocoa Programmer
  • Index(es):
    • Date
    • Thread