• 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: "John C. Randolph" <email@hidden>
  • Date: Mon, 12 Nov 2001 01:11:44 -0800

On Monday, November 12, 2001, at 12:26 AM, Marcel Weiher wrote:

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.

Come to think of it, it was deployed on OpenStep 4.2, but it was a NeXTSTEP 3.3 code base.

-jcr

"These kids today don't know the simple joy of saving four bytes of page-0 memory on a 6502" - unknown


References: 
 >Re: New Cocoa Programmer (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Re: New Cocoa Programmer
  • 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