Re: [FRIAM] div. zero bugs?
Ooo. This is one that I can answer. In most computer language syntax, the statement @X = Y assigns the value Y to variable @X. In some comptuer languages, the *expression* ( @X == Y ) compares @X and Y for equality (does @X contain the value Y ?) and returns a result of true or false. In some of those comptuer languages, the assignment statemet @X = Y is also considered an expression, in that it returns the value of @X after the assignment. This is often a useful feature. In some of those languages, a non-zero result is considered the same as boolean TRUE E.g. IF ( 1 ) THEN PRINT IT'S TRUE! always prints IT'S TRUE! because (1) evaluates to TRUE in that context. So, in that kind of language, the typographicial error of omitting one = from a comparison turns the comparison into an assignment, unexpectedly having the side effect of changing the value of the left-side operand! So: // compare for equality, if the result is true, print EQUAL IF ( @X == Y ) THEN PRINT EQUAL Mistype that to leave out one = symbol: // assign value to x, then if x is non-zero/ non-empty, print EQUAL IF (X = Y ) THEN PRINT EQUAL Whoops! Unexpected results! X is always non-empty, because it is assigned the value Y! Also, after this statement, X always contains Y Giles suggestion, to reverse the order of the terms, is a good one, because it prevents a typo from compiling without error and accidentally causing an assignment at run-time, and instead generates a compile-time error, pointing out the typo! ~~James _ http://www.turtlezero.com On 10/25/06, Phil Henshaw [EMAIL PROTECTED] wrote: Giles, Can you explain what that causes? You say is prone to accidental assignment. Sounds like variables erroneously change value when queried. That's not good. My limited experience is different, that code has all kinds of unexpected and hidden structure because it was written by people like me who can't keep a few dozen simple logical steps straight when interacting with few dozen others written by someone else (i.e. there's confusion lying all around). Is that also why variables are accidentally reassigned? Or something different? Ok, so then what happens after that? You don't just come to the wrong answers it seems, but frequently trigger a cascade of mismatching stuff that sometimes gets 'trapped' and sometimes not? Would you describe it differently? About the only useful discovery I've made along these lines: Never do this: if @var == Value Always do this: if Value == @var the reason is because, if you screw up and only put in one equals sign, pretty much every language out there is prone to accidental assignment-during-test bugs, but no languages that I'm aware of are prone to accidental assigning-new-values-to-literals bugs. For what it's worth... -- Giles Bowkett http://www.gilesgoatboy.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
Giles suggestion, to reverse the order of the terms, is a good one, because it prevents a typo from compiling without error and accidentally causing an assignment at run-time, and instead generates a compile-time error, pointing out the typo! yeah that's exactly it. these bugs happen a lot. often enough for these jokes: // World's last bug if (red_button_pressed = 1) launch_missile(); I thought that was pretty funny ^_^ -- Giles Bowkett http://www.gilesgoatboy.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
// World's last bug if (red_button_pressed = 1) launch_missile(); I thought that was pretty funny ^_^ .. for all 7 of us who understood it! -- Owen Owen Densmore http://backspaces.net FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
[FRIAM] Design Week Highlights: Thurs Oct 26: Designs of Nature: Introduction to Biomimicry Keynote
*** tomorrow immediately following Kim Sorvig's 10:30a talk *** ** NOTE location of James Little Theatre ** SPEAKER: Rose Tocke, Director Community Dynamics/Biomimicry Guild TITLE: Designs of Nature: Introduction to Biomimicry Keynote TIME: Thurs Oct 26, 11:30a-12:30p LOCATION: Santa Fe Design Week Event James A. Little Theatre, 1060 Cerrillos Rd. More events: http://www.santafedesignweek.com/program_schedule26.php FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
I was about to say: can someone translate this joke into English? (It looks funny, but...) - Original Message - From: Owen Densmore [EMAIL PROTECTED] To: The Friday Morning Applied Complexity Coffee Group friam@redfish.com Sent: Wednesday, October 25, 2006 8:11 PM Subject: Re: [FRIAM] div. zero bugs? // World's last bug if (red_button_pressed = 1) launch_missile(); I thought that was pretty funny ^_^ .. for all 7 of us who understood it! -- Owen Owen Densmore http://backspaces.net FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
In some languages, the assignment operator, =, not only assigns a value to a variable, it also returns that value as the expression's value itself. This is to allow things like a=b=c=42; So in the expression red_button_pressed = 1 The value 1 is assigned to the variable red_button_pressed, and returns a 1 as the value for the expression. Unfortunately, this is also interpreted as true for conditional statements like if and while etc. The real intent of the code is to use the == operator, which returns true if the two operands are the same. So the *extremely* common bug of using = rather than == causes entirely unexpected consequences .. launching a missile. // World's last bug if (red_button_pressed = 1) launch_missile(); The solution many programmers got into the habit of is to reverse the variable and the value to be: if (1 = red_button_pressed) launch_missile(); This causes an error within the compiler because 1 is a literal and cannot be assigned to. -- Owen Owen Densmore http://backspaces.net On Oct 25, 2006, at 9:44 PM, David Breecker wrote: I was about to say: can someone translate this joke into English? (It looks funny, but...) - Original Message - From: Owen Densmore [EMAIL PROTECTED] To: The Friday Morning Applied Complexity Coffee Group friam@redfish.com Sent: Wednesday, October 25, 2006 8:11 PM Subject: Re: [FRIAM] div. zero bugs? // World's last bug if (red_button_pressed = 1) launch_missile(); I thought that was pretty funny ^_^ .. for all 7 of us who understood it! -- Owen Owen Densmore http://backspaces.net FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
Owen Densmore wrote: So the *extremely* common bug of using = rather than == causes entirely unexpected consequences .. launching a missile. I expect to see both in many circumstances. For example, when opening a file to read that is absent or to write, and write permission is forbidden. if ((fp = fopen (filename, r)) == NULL) abort (); I haven't really created many bugs because of = vs. ==. GCC even gives a warning... $ cat t.c #include stdio.h #include stdlib.h static void launch_missle () { printf (Missle launched\n); } int main (int argc, const char **argv) { int red_button_pressed = 0; if (argc 1) red_button_pressed = atoi (argv[1]); if (red_button_pressed = 1) launch_missle (); return 0; } $ gcc -Wall t.c t.c: In function ‘main’: t.c:18: warning: suggest parentheses around assignment used as truth value FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
// World's last bug if (red_button_pressed = 1) launch_missile(); I thought that was pretty funny ^_^ .. for all 7 of us who understood it! -- Owen The odd thing is it made me laugh a lot, as if I understood the joke, even though I have no idea what it means! (except for the idea of leaving the fate of mankind to something that crashes a lot!) Phil FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org
Re: [FRIAM] div. zero bugs?
OK, thanks Doug and Owen, I'm laughing. And I'm also noting that Cormac McCarthy (who has been hanging out at SFI lately, and even thanked the Institute in his last book) has a new one about a post-nuclear-apocalyptic society ("The Road"). Could this be the result of programming error? Or haning out with programmers? ;-) db - Original Message - From: Douglas Roberts To: The Friday Morning Applied Complexity Coffee Group Sent: Wednesday, October 25, 2006 9:48 PM Subject: Re: [FRIAM] div. zero bugs? Easy.Correct version:// World's last bugif (red_button_pressed == 1) launch_missile();The other version is guaranteed to bomb... -- Doug Roberts, RTI International[EMAIL PROTECTED][EMAIL PROTECTED]505-455-7333 - Office505-670-8195 - Cell On 10/25/06, David Breecker [EMAIL PROTECTED] wrote: I was about to say:can someone translate this joke into English?(Itlooks funny, but...)- Original Message -From: "Owen Densmore" [EMAIL PROTECTED] To: "The Friday Morning Applied Complexity Coffee Group" friam@redfish.comSent: Wednesday, October 25, 2006 8:11 PMSubject: Re: [FRIAM] div. zero bugs? // World's last bug if (red_button_pressed = 1)launch_missile(); I thought that was pretty funny ^_^ .. for all 7 of us who understood it! -- Owen Owen Densmore http://backspaces.net FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.orgFRIAM Applied Complexity Group listservMeets Fridays 9a-11:30 at cafe at St. John's Collegelectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listservMeets Fridays 9a-11:30 at cafe at St. John's Collegelectures, archives, unsubscribe, maps at http://www.friam.org FRIAM Applied Complexity Group listserv Meets Fridays 9a-11:30 at cafe at St. John's College lectures, archives, unsubscribe, maps at http://www.friam.org