On Wed, Dec 29, 2010 at 12:47:22PM -0500, Olin Lathrop wrote: > Byron Jeff wrote: > > I kind of like C's ability to use assignment as an expression. >=20 > Hmm. I rather doubt there is any real efficiency gained from that by > reasonably written compilers. >=20 > > Again it > > does facilitate a compactness of expression that other languages do > > not have the ability to accomplish. >=20 > That may have been K&R's intent, and perhaps there was some limited reaso= n > for it back then, but there is certainly little reason for it now. Clari= ty > is far more important than compactness, and I think should have been back > then too. I mostly care about compactness only as it enhances clarity. = Go > too far and it detracts from clarity. C certainly has the ability to bash clarity down into the ground if a programmer so decides to want to do it. But there are times when clarity and compactness do not have to be at odds. Even something as simple as: a =3D b =3D c =3D d =3D 0; is perfectly readable yet compact. But it's only doable if assignment is an expression, and not a statement. >=20 > > BTW you didn't even get to the one that just sticks in my craw: > > > > The default drop through action of cases in the switch statement. >=20 > Yeah, that's another good one. I totally agree the default should be to = end > the switch, not fall thru to the next case. The C SWITCH is just a compu= ted > GOTO, not a real selection of multiple cases as the syntax would lead a > casual observer to believe. If they had named it MULTIJUMP or something,= it > wouldn't bother me so much, but then I'd still want a real multi-case > statement. >=20 > By the way, the Pascal CASE statement does work as you describe. For > example: >=20 > choice :=3D 1; > case choice of > 1: writeln ('1 was picked'); > 3: writeln ('2 was picked'); > 3: writeln ('3 was picked'); > otherwise > writeln ('Other was picked'); > end; >=20 > would only result in "1 was picked" to be written. You don't have to be = a > Pascal whiz to have a pretty good idea what the above code does. I know. I learned the case statement first. That's one reason why the C switch always drove me nuts. >=20 > > The only argument that holds water is that since ranges are not > > allowed, > > the default fall through allows multiple cases to share the same code: > > > > choice =3D 1; > > switch (choice) { > > case 1: > > case 2: > > case 3: printf("1,2, or 3 was picked\n"); > > break; > > default: printf("other was picked\n"); > > break; // Unneccessary but often put in for consistency. > > } >=20 > Pascal gets around it this way: >=20 > case choice of > 1, 2, 3: writeln ('1, 2, or 3 was picked'); > otherwise > writeln ('Other was picked'); > end; >=20 > In other words, you can't put a bunch of cases in a row and fall thru, bu= t > you can give each case multiple target values. I think that addresses yo= ur > concern adequately enough. Agreed. But as you pointed out, C's switch is a computed goto and has no facility to do that. >=20 > > switch (choice) { > > case 1: continue; > > case 2: continue; > > case 3: printf("1,2, or 3 was picked\n"); > > break; > > default: printf("other was picked\n"); > > break; // Unneccessary but often put in for consistency. > > } >=20 > Something like that, although as Martin pointed out, CONTINUE already has > another meaning. I would be fine with this if a different and new keywor= d > were used, like NEXTCASE for example. It's probably my C bias leaking through. Since break was multipurposed in loops and switches, it seems natural to me that continue could have done the same. >=20 > > Byron A. Jeff > > Department Chair: IT/CS/CNET > > College of Information and Mathematical Sciences > > Clayton State University >=20 > Hey, when did that happen? Congratulations! Is that the same place you > were before, or did you have to go elsewhere to get promoted? Thanks. Same place. Tenure, promotion, and put into administration all at the same time. > Last I > remember (probably a long time ago since my brain usually tunes out email > signatures) you were someplace in Georgia. This happened about 6 months ago. I've been out of the loop busy learning the new job. Also we had a slight E-mail change and my old registered E-mail wasn't available for list postings. I finally got around to reregistering. So I plan to drop in an out with postings though I lurk regularly. BAJ --=20 Byron A. Jeff Department Chair: IT/CS/CNET College of Information and Mathematical Sciences Clayton State University http://cims.clayton.edu/bjeff --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .