Prev: nike air max 2003 ney style hot sell ....free shipping to worldwide
Next: cluttered code prevention?
From: optimistx on 20 Oct 2009 02:58 Stevo wrote: > It doesn't take long for people to figure out how unfriendly > PointedEars is. It's weird isn't it, if he only knew how to > communicate in a friendly manner he might well become a hero around > here. Instead though, despite his obvious knowledge, he makes enemies > here every day. Yes. When writing a book the publisher provides a person to read the text, and propose (usually numerous) changes to make it follow certain styles, habits, rules. With the help of such a person the texts of some people (not only TL) here would be good material for an educational book. But with the bitter, sour, unfriendly tone now here (as understood by readers) might prohibit the sales of a future bestseller. FAQ is material for the book. It is irrational to call it FAQ, when frequently asked questions are not allowed here. It would be more useful as a manual, with pictures, diagrams, friendly human attitude. Trying to be consice and accurate as scientific text is not educationally useful. Very few people if any start learning a new science by reading original research reports. I share the feelings of the OP. Do not go away.
From: SAM on 20 Oct 2009 05:24 Le 10/20/09 2:53 AM, dsmithy a �crit : > Hi, > I came across this line of code in a book. It appears to use the > alternative if syntax, but it doesn't quite make sense to me: > > res += (i * j) % 8 ? " " : "*"; > > where res is a string variable, and i and j are number variables (i > increments from 1 to 7 and j increments from 1 to 15). > > What's confusing me is that I thought the expression preceding the ? > had to be a conditional (i.e., true or false) Yes indeed. when (i * j) % 8 == 0 ==> false or when (i * j) % 8 == NaN ==> false if not ==> true Try in the address bar : javascript:alert((1*0)%8);alert((1*0)%8?'ok':'!ok') javascript:alert((1*'a')%8);alert((1*'a')%8?'ok':'!ok') javascript:alert((1*2)%8);alert((1*2)%8?'ok':'!ok') -- sm
From: Gregor Kofler on 20 Oct 2009 07:51 Stevo meinte: > Yes it is. There's nothing at all wrong with referring to a ternary > statement as "alternative if syntax". It gets across in very simple > terms what you can do with it. If a regular if looks like this: > > if ( x==1 ) y=2; else y=0; > > and as a ternary statement it looks like this: > > y = x==1 ? 2 : 0; > > That is clearly an alternative if syntax. Stop trying to confuse people. It's only an alternative in this very particular case. Hence calling it an "alternative if syntax" (wich implies "general alternative") is completely wrong. Gregor -- http://www.gregorkofler.com
From: Stevo on 20 Oct 2009 08:16 Gregor Kofler wrote: > Stevo meinte: > >> Yes it is. There's nothing at all wrong with referring to a ternary >> statement as "alternative if syntax". It gets across in very simple >> terms what you can do with it. If a regular if looks like this: >> >> if ( x==1 ) y=2; else y=0; >> >> and as a ternary statement it looks like this: >> >> y = x==1 ? 2 : 0; >> >> That is clearly an alternative if syntax. Stop trying to confuse people. > > It's only an alternative in this very particular case. Hence calling it > an "alternative if syntax" (wich implies "general alternative") is > completely wrong. > > Gregor But as an explanationary description to help out someone learning JavaScript, it's a perfectly fine description.
From: beegee on 20 Oct 2009 09:17
On Oct 20, 8:16 am, Stevo <n...(a)mail.invalid> wrote: > Gregor Kofler wrote: > > It's only an alternative in this very particular case. Hence calling it > > an "alternative if syntax" (wich implies "general alternative") is > > completely wrong. > > > Gregor > > But as an explanationary description to help out someone learning > JavaScript, it's a perfectly fine description. Yes, it's a fine description but one gets the impression that the book the op read actually calls it "the alternative if syntax" which as stated by Gregor and Thomas, is wrong. The name in this language and many others is the ternary statement. Even as a description, "alternative if-else clause" would be better. I agree with Pointed Ears. Dump the book. Also, remembering the order of precedence in a statement like: res += (i * j) % 8 ? " " : "*"; seems a hellish exercise. I would write it: var appendStr = ((i * j) % 8 )? " " : "*"; res += appendStr; I had a friend who loved to write things like: return userPrefersRed()?userPrefersMaroon()? processOrange(): (userPrefersBurgundy()? processBurgundy(): processRed()): processBlue(); His code was strangely bulletproof but impossible to read. Bob |