<div>hmmmmm</div><div>Something I just don't agree.</div><div>I use Something == false. </div><div>Because I do not name the variable like Is_Something_Right (Apologize for my mike)<span style="line-height: 1.5; font-size: 14px;">.</span></div><div><span style="line-height: 1.5; font-size: 14px;">!</span><span style="font-size: 14px; line-height: 1.5;">Is_Something_Right</span><span style="font-size: 14px; line-height: 1.5;"> could be a better code style.</span></div><div><span style="font-size: 14px; line-height: 1.5;">!Something , in my </span>opinion, is not better than Something == false.</div><div><div><br></div><div>I have see this code style in my project as you write.</div><div>example(Foo, Bar, Ugh) -><br>    case {Foo, Bar, Ugh}<br>      of {false, _, _} -> . . .<br>       ; {true, false, _} -> . . .<br>       ; {true, true, false} -> . . .<br>       ; {true, true, true} -> . . .<br>    end.<span style="line-height: 1.5; font-size: 14px;"> </span></div><div><span style="line-height: 1.5; font-size: 14px;">But when look at the {true,true,false}.</span></div><div>I still need to check which one is true , and which is false (I'm just stupid as a duck).</div><div>And There could be 8 different status.</div><div>That means I should write 8 entry for 3 judgement</div><div>But if three are nest(Although I don't like it).Only need 3 entry. </div><div><span style="line-height: 1.5; font-size: 14px;">So I don't think this a good coding style.</span></div><div><span style="line-height: 1.5; font-size: 14px;"><br></span></div><div><span style="line-height: 1.5; font-size: 14px;">I just wonder is there any way like return in other language could just return and ignore the step below.</span></div><div><span style="line-height: 1.5; font-size: 14px;">And Now I know there are no way to do like that.</span></div><div>More function could be a good choice I think</div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "Richard A. O'Keefe"<ok@cs.otago.ac.nz>;</div><div><b>发送时间:</b> 2013年3月26日(星期二) 上午10:50</div><div><b>收件人:</b> "饕餮"<249505968@qq.com>; <wbr></div><div><b>抄送:</b> "erlang-questions"<erlang-questions@erlang.org>; <wbr></div><div><b>主题:</b> Re: [erlang-questions] How to make a short circuit in erlang ?</div></div><div><br></div><br>On 26/03/2013, at 3:31 PM, 饕餮 wrote:<br><br>> When in other language.We can use like:<br>> example(Something){<br>>     if( Something == false)<br>>         return;<br>>     //do something here;<br>> }<br><br>Brian Marick of www.exampler.com has two great stickers.<br>One I have fixed to my door is "To be less wrong than yesterday."<br>The other is "An example would be useful about now" (from memory).<br><br>Even in C and Java, "if (Something == false)" is bad style.<br>You should write "if (!Something)".  The only time that<br>==false or ==true make sense is when there is a third possibility.<br><br><br>> But in Erlang.I have to write like:<br>> example(Something) -><br>>     if<br>>         Something == false -><br>>             false;<br>>         true -><br>>             %do something here<br>>     end.<br><br>I personally prefer<br><br>    example(Something) -><br>        case Something<br>          of false -> false<br>           ; true  -> . . .<br>        end.<br><br>and then go looking for the third case that probably exists.<br>There is pattern matching in the head.<br>There are guards to be used.<br>In fact, "early-exit" (as it's known in the Smalltalk world)<br>is often an ersatz for guard tests.<br><br>So the chances are that you should either<br> - be rewriting for clarity, or<br> - using guards.<br><br>I think a *real* example would be illuminating.<br>> <br>> That's could make the multiple nested like:<br>> example(Something) -><br>>     if<br>>         Something == false -><br>>             false;<br>>         true -><br>>             if<br>>                 Otherthing == false -><br>>                     false<br>>                 true -><br>>                     %do something here<br>>     end.<br>> <br>> Some code could make 5 or more nested in it.<br><br>No.  SHOW US A REAL EXAMPLE.  And nothing stops you writing<br><br>example(Foo, Bar, Ugh) -><br>    case {Foo, Bar, Ugh}<br>      of {false, _, _} -> . . .<br>       ; {true, false, _} -> . . .<br>       ; {true, true, false} -> . . .<br>       ; {true, true, true} -> . . .<br>    end.<br><br>We need a real example.  (Did I already say that?)<br><br>> Is there any idea to make short circuit to reduce of the nested?<br><br>Give us a real example and *then* we can have an illuminating<br>discussion.<br><br>It's a funny thing.  I use early exit a lot in Smalltalk, rather<br>less so in C, and in ML and Haskell it never occurs to me that I<br>don't actually have it.  Erlang is definitely close to the ML end<br>of things.<br><br>I just spent a day turning 63 SLOC of code I wanted to use for a<br>class example of the importance of comments into 21 lines, which<br>annoyingly needs a lot fewer comments.  Part of it was to not be<br>scared of introducing auxiliary functions (in Java, yet!).<br><br><br></div>