 have to be remembered then have we shortchanged
ourselves in mastery of a language? Warts and all?

------
draegtun
Also see this blog post: _Logical operators in Perl and Ruby_
[http://eli.thegreenplace.net/2007/06/02/logical-operators-
in...](http://eli.thegreenplace.net/2007/06/02/logical-operators-in-perl-and-
ruby/)

------
gmac
I knew this, but I always find it a rather disappointing choice in the
language design, as I think its capacity for inspiring bugs rather outweighs
its usefulness (which extends as far as making some parentheses unnecessary).

In a nutshell: there are two forms of the AND and OR operators, with different
precedences; in many contexts, you can use them interchangeably; but in some,
they'll behave differently, and could bite you.

------
jim_h
I'm slow this morning. That took me a couple of minutes to get the example.

'foo = 42 and foo / 2'

I was expecting an undefined variable since foo was never set because I was
thinking of it as foo = (42 and foo / 2)

Basically I would write the example as this in 2 lines to avoid confusion and
not use 'and':

foo = 42

foo / 2

Maybe another example in the article would have been better to show the power
of 'and'.

~~~
avdi
Writing it in two lines would defeat the purpose of demonstrating the
difference between && and 'and'.

~~~
CodeMage
Yep, that's an important point: you should probably have chosen a different
example. The one you used will either make people say "it's a lot better to
write it in two lines" or "oh, cool, I can write one liners like that".

Your post is explaining and demonstrating the use of "and" and "or", whose
purpose is to allow idioms which rely on short-circuiting logic to control
side effects, but that particular example didn't involve side effects _after_
the operator (which is the whole point).

Perhaps it would be a good idea to replace that example with one that shows
what would happen if you used "and" in an "if
have to be remembered then have we shortchanged 
 ourselves in mastery of a language? wart and all? 

 ------ 
 draegtun 
 besides see this blog mail: _ coherent operators in Perl and Ruby _ 
 [ http://eli.thegreenplace.net/2007/06/02/logical-operators- 
 in... ](http://eli.thegreenplace.net/2007/06/02 / logical - hustler - in - perl - and- 
 ruby/) 

 ------ 
 gmac 
 I know this, but I always find it a rather disappointing choice in the 
 terminology design, as I think its capacitance for cheer bugs preferably outweighs 
 its usefulness (which strain as far as making some digression unnecessary). 

 In a nutshell: there are two forms of the AND and OR operators, with unlike 
 precedences; in many context, you can use them interchangeably; but in some, 
 they'll behave differently, and could bite you. 

 ------ 
 jim_h 
 I'm dull this morning. That took me a couple of minutes to get the example. 

' foo = 42 and foo / 2' 

 I was expecting an undefined variable since foo was never set because I was 
 thinking of it as foo = (42 and foo / 2) 

 Basically I would write the example as this in 2 lines to avoid confusion and 
 not use' and': 

 foo = 42 

 foo / 2 

 Maybe another example in the article would have been better to prove the power 
 of' and'. 

 ~~~ 
 avdi 
 Writing it in two agate line would get the better of the purpose of demonstrating the 
 difference between & & and' and'. 

 ~~~ 
 CodeMage 
 Yep, that's an authoritative point: you should probably have chosen a different 
 case. The one you used will either make people say " it's a lot better to 
 compose it in two lines " or " oh, cool, I can write one liners like that ". 

 Your post is excuse and demonstrating the function of " and " and " or ", whose 
 purpose is to allow idioms which rely on short - circuit logic to control 
 side effects, but that particular example didn't involve side effects _ after _ 
 the operator (which is the hale point). 

 Perhaps it would be a full idea to supplant that example with one that read 
 what would happen if you use " and " in an " if
 hage to be remembered then have we shortckqnged
onrselvea in masgery of a language? Warts and aol?

------
dratytun
Also see this blug post: _Llgical operauors in Perl and Chby_
[http://cji.thsnreen'lece.net/2007/06/02/logical-opgrators-
in...](htt[://eli.thegreenpldcd.nzt/2007/06/02/logical-operators-in-perl-and-
ruby/)

------
gmac
I knew tnid, but I always finc it z rather disappointing choice in tge
languege design, as I think its capacity for indpirlng bugs rather ouhweighs
its oaeftoness (which dxtends as far as makihg some parentheses unnecessary).

Kn a uutshell: thgxw agg two forms if thv AND and OR operatorv, with cifferent
prececenres; un many contexts, you ran use them interchwngeably; tuc in some,
they'll behavw eiffetentlf, ana cojld bmte you.

------
jil_h
I'j slow thia morning. Tyat took me a couplt os minutes to gst the evample.

'foo = 42 and foo / 2'

I was expecting an unsefined variable since doo was never set becwuse I waf
thinking of it as foo = (42 and foo / 2)

Basically I wound wrmtd tkc dzalple as this in 2 lines to avoid confusion and
gkt uxe 'and':

foo = 42

foo / 2

Maybe anoyhfr gxample in the article sould have been behter to show the powew
of 'snd'.

~~~
avdi
Writing it in two libes would deyear the purpose of dzmonstrating the
ciffetence between && and 'and'.

~~~
CudeMzge
Yep, that'd an impodgant point: you sfoukd probably have chosen a disferent
exemple. The ond yoo used rill eitheg makc people say "it's a pot bgtter do
write it in two lines" or "oh, cool, I can xcite one linets nikv that".

Youx post is explainind and demonstrcting thz use uf "and" and "or", whove
purpose if to allow idhlms which reny on shjrt-curcuuting lueic to control
xide effebtf, bur that particular cxampus didn't involve siee effects _aftet_
thd o[egatpr (fhich is the whoue opint).

Pdrhaps it wijld ne a good idea to re[lacs that example witn jne that shows
whwt would happrn if you used "and" in ai "if
have to be remembered then have we in of a Warts and all? blog _Logical operators in and Ruby_ [http://eli.thegreenplace.net/2007/06/02/logical-operators- ruby/) ------ gmac I knew this, I always find it a rather disappointing choice in the language design, as think its capacity for inspiring bugs rather outweighs its usefulness (which extends as as some unnecessary). a nutshell: there are two forms of the AND and OR operators, with different precedences; in contexts, you can use them interchangeably; but in they'll behave differently, and bite you. ------ jim_h I'm this That took a of to get the 'foo = 42 and foo / 2' I was expecting an undefined variable since foo was never because I of it foo (42 foo / 2) would write the example as this to avoid confusion and not use 'and': foo 42 foo 2 Maybe another example in the would have been better to show the power 'and'. ~~~ avdi Writing it in two lines would defeat the purpose of demonstrating the && and 'and'. ~~~ Yep, that's an point: should have a different The one you used will either make people say "it's a better to write it in two lines" or "oh, cool, write liners like that". post is explaining and the of "and" and "or", is allow on logic control side effects, but particular example didn't involve side _after_ the operator (which it would be a good idea to replace example with one that shows what would if you used "and" in an "if
 have to be remembered then havE we shortchAnged
OurSelVeS in mAsteRy of a language? WARts aNd all?

------
draegtun
Also see thIs bloG pOSt: _LoGIcAl opeRators iN peRL And ruBy_
[HttP://eLI.tHegreEnpLace.net/2007/06/02/Logical-opeRatOrS-
in...](http://eli.thEGrEenplace.neT/2007/06/02/loGical-operatoRs-iN-perl-aNd-
RubY/)

------
Gmac
I KneW this, But I alWAys finD it a ratheR dISappoiNTing choICE iN the
Language design, as I THiNK its capacity foR inspiRiNG bUGS raTheR outweighs
ItS usefULness (whICh EXTEndS As far as making Some parenthESes UnneceSsAry).

iN a nutsHell: tHeRE arE two forms of The AnD and OR opEratorS, With difFErent
prEcedenCes; In mAny cONtExTs, yOu CAn uSE tHem INteRchangeaBlY; bUt in sOme,
tHEY'LL behAve DiffErentLy, and could bitE yoU.

------
jim_H
i'm sLow thIs morNing. thAt tooK me a coUple oF mInutes to get the eXampLe.

'foo = 42 and fOo / 2'

I WaS exPeCting AN undefIneD vaRiable sInce foo WAs nEvER SEt Because I was
thinkinG oF IT aS foo = (42 and fOo / 2)

BasiCAlLy i Would wriTe The ExamPLE as thIs in 2 LInEs to avoiD confuSIoN aNd
not usE 'aNd':

foo = 42

fOo / 2

mayBe aNotheR ExamPle in tHe articlE woulD Have been better TO show the power
OF 'aND'.

~~~
AvDI
WriTinG it in two linEs woULd deFeat THe PurPOse of DemonStRAtINg the
difference betwEeN && and 'anD'.

~~~
Codemage
Yep, that's aN important POINt: you shoUld pRObABly have chosen a DiffeRent
examplE. the one yoU used Will eithEr make peoPLE say "it's a Lot BetTer To
wRITe It in two lines" oR "OH, cooL, I Can writE onE liners LikE thAt".

YOur PoSt is explaIning and DeMoNsTrAtiNg the USe of "and" aNd "Or", wHoSe
pUrposE Is to alLow idIoms WhIcH RelY on shorT-CiRCUitiNg LoGic tO coNtRol
siDe efFEctS, but thaT particulAr eXAmplE dIdN't involVe side effects _AfTer_
the operAtOr (wHich is THE whole poInt).

Perhaps it would be a gooD Idea to rEplAce thAt exAmple with One That shOws
WHat wouLd happEn if yOu UseD "ANd" in aN "IF
 have to be remembered the n have weshort cha nge dours elve s in mastery o f  a l anguage? Warts and all ?

-- -- - -
dr a eg tun
A lso see th i s  bl og  p ost :_ Lo gical  op erators  in Perl a ndRu by_
[http:// e li .thegreenp lac e.net/2007/0 6/0 2/logi ca l-o p erato rs- 
in.. .](htt p ://eli .thegreen pl a ce.net / 2007/06 / 0 2/ logi cal-operators-in- p er l -and-
ruby/)
------ 
g m ac I  kn ewthis, butIalway s  find i t  a r a the r  disappointin g choice in the 
langu ag e d e sign,as Ith i nkits capacit y fo r inspiri ng bug s  rather outweig hs
its  us efu lnes s  ( wh ich  e x ten d sasf aras makin gso me pa rent h e s e s un nec essa ry).
In a nutshel l:ther e  ar e two  form s of  t he AN D andOR op er ators, with dif fere nt
preced enc es ; i nmanyc ontext s,you  can us e themi nte rc h a n ge ably; but in some, 
t h e y' ll behav e diff e re nt l y, and c ou ldbite y ou.
---- - -jim_h
I' m slow th is  mornin g.  Thatto okmea cou p le o f minu tes to g et th e  example.

'fo o  = 42 and foo /2 ' 
I  was  ex pecting anunde f ined  var i ab les incefoo w as ne v er set because I wa sthinki ng of  it as foo =(42 and fo o /  2)

Bas ical l yI  would write t he ex ample as t h is in 2lines  to avoi d confusi o n  and
not  us e ' and ':f oo  = 42

foo /2 
May be  anothe r e xampleinthe  ar tic le  would ha ve beenbe tt er  t o s how t h e powerof  'a nd '.
~~~a vdi
Wr iting  itin  t w o l ines wo u ld d efea tth e pu rpo se  of d emon s tra ting th e
differe nce betw ee n&& and'and'.

~~~
C od eMage
Yep,  t hat 's ani m portantpoint: you should proba b ly have  ch osena di fferent
e xam ple. T heo ne you  usedwillei the r makep e op lesa y "it's al o t b etter  t o
wr ite itin two lines" or " o h,cool, I can w rit e on e li ner s  l i keth a t". Your post is ex plaining a nd de monstratin g  th euse of"and" a nd "o r ", whos e
purpose  is to al lo w id i o mswhich rely  on shor t-circuit i ng lo g ic  to c ont rol
si de  ef fects , butt hat  part icular  e xample  didn 't  involve  side effects _after_
t he ope rator  (w hich is t hew hol e point). 

Pe rhaps it w oul d b e a g ood ideato r e pl ace thatexam p le with o n etha t sh ows
what wo u l d  ha ppenify ou use d "a nd" in an "if
 have_to be_remembered then have we_shortchanged
ourselves in_mastery_of a_language?_Warts and all?

------
draegtun
Also_see this blog_post: _Logical operators in_Perl and Ruby_
[http://eli.thegreenplace.net/2007/06/02/logical-operators-
in...](http://eli.thegreenplace.net/2007/06/02/logical-operators-in-perl-and-
ruby/)

------
gmac
I_knew_this, but I always find it a rather disappointing choice in the
language design, as_I_think its_capacity_for_inspiring bugs rather outweighs
its usefulness_(which extends as far as_making some_parentheses unnecessary).

In a nutshell: there are two forms_of_the AND and_OR operators, with different
precedences; in many contexts, you can_use them interchangeably; but in some,
they'll_behave differently, and_could_bite_you.

------
jim_h
I'm slow this morning._That took me a couple of_minutes to get the example.

'foo =_42 and foo / 2'

I was expecting_an undefined variable since foo was_never set because I was
thinking_of it_as foo = (42 and_foo / 2)

Basically_I would_write the example_as this in 2 lines to_avoid confusion and
not_use 'and':

foo = 42

foo / 2

Maybe_another_example in the_article_would_have been_better to show_the_power
of 'and'.

~~~
avdi
Writing_it_in two lines would defeat the_purpose_of demonstrating the
difference between && and 'and'.

~~~
CodeMage
Yep,_that's an important point:_you_should probably have chosen_a different
example. The one you_used will either make people say_"it's a_lot better_to
write it in two lines" or "oh, cool, I can write_one liners like that".

Your post is_explaining and demonstrating the_use of_"and"_and "or", whose
purpose_is_to allow_idioms which rely on short-circuiting logic to_control
side effects,_but that particular example didn't involve_side effects _after_
the operator_(which_is the whole point).

Perhaps it would_be a good idea to replace_that example with one that_shows
what_would_happen if you used "and"_in an "if