From: Brian G. <bri...@ea...> - 2006-11-06 03:33:49
|
On Nov 5, 2006, at 7:03 PM, Larry McVoy wrote: > On Sun, Nov 05, 2006 at 10:59:10PM +0000, Donal K. Fellows wrote: >> Will Duquette wrote: >>> Alternatively, if one used ":=" as the assignment operator for >>> TIP 282 there'd be no active harm in using the enhanced syntax >>> in "if" and "while". You *could* write "if {a := $b}" if you >>> really wanted to, but you'd be much less likely to do it >>> accidentally. >> >> I agree with and strongly support this suggestion. Many years of >> experience with C and Java (learning, using, and teaching) tells >> me that >> the "BCPL mistake"[*] is a horrible thing that always leads to >> trouble. >> If we ensure that "=" is not legal, it forces people to choose >> between >> definitely equality (==) and definitely assignment (:=). I've done >> this >> in the past in other languages, and it makes for fewer user errors. > > For what it is worth, we have 8+ years of usage and we do horrible > things > like > > unless (f = fopen(file, "r")) { > error stuff here > } > > and I can't remember an instance of someone getting it wrong > because we > did an "==" instead of an "=" or the other way around. > > I think this is a newbie error that simply doesn't happen with pros. Never say never. It does happen with pros, just not so often. Modern compilers warn if such assignments are not within parentheses (i.e. unless ((f=fopen(file,"r))) {}). This is a reasonable check to prevent pros from making mistakes as well as newbies. I think an ounce of prevention is worth it here since finding this, if it's a bug, is very difficult, even for a pro. -Brian |