Re: New Cocoa Programmer
Re: New Cocoa Programmer
- Subject: Re: New Cocoa Programmer
- From: Ondra Cada <email@hidden>
- Date: Sun, 11 Nov 2001 15:20:41 +0100
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\>
JCR> with each case going on for about 100 lines. Talk about
JCR> missing the point!
I'm afraid the example misses the point (of anything related to the switch
statement) completely. Any student who would bring me a programme containing
a function/method which would by itself contain hundreds of lines would have
quite a hard time passing the exam -- regardless the language used, and
regardless the actual primitives used inside the func.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc