<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: If-Methods Redux</title>
    <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>If-Methods Redux</title>
      <description>&lt;p&gt;So was looking over my blog on &lt;a href=http://blog.objectmentor.com/articles/2008/09/23/if-methods&gt;If-Methods&lt;/a&gt; this morning and I realized that I fell into a trap.  I was solving one problem but thinking about another.&lt;/p&gt;  
&lt;p&gt;There I was working on lexer code and I thought &amp;#8220;Hmm&amp;#8230; I&amp;#8217;d really like to extract these if-blocks.&amp;#8221; I mulled it over a bit, and while thinking about the &lt;i&gt;general&lt;/i&gt; problem of naming if-blocks, I settled on a naming scheme that I thought would be good in general, but it ended up being a bit odd in particular.  The comments on the blog show this.  Many of them offer good suggestions for dealing with the particular case I showed, but I was really after something different, a good general-purpose naming scheme for methods extracted around conditional.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m going to try this again and see if I can come up with a case which motivates a generic naming scheme a bit better.&lt;/p&gt;
&lt;p&gt;Consider this chunk of code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    if (sensorTripped) {
        ...
        alarm.sound();
    }
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We could extract the body of the if-block, but in a long method, we might want to extract the entire concern.  What should we call it?&lt;/p&gt;  
&lt;p&gt;One option is to call it &lt;code&gt;soundAlarm()&lt;/code&gt;.  It&amp;#8217;s not quite true, however.  The sounding is conditional.&lt;/p&gt;  
&lt;p&gt;We could, on the other hand, get explicit: &lt;code&gt;soundAlarmIfSensorTripped()&lt;/code&gt;.  This smacks more of implementation than intention, however.  Now, having said that, I do think that in legacy code these names are great reminders as you make your first cut.. slicing and dicing a long method.  They help you remember what is going on as you plan your next move.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s another option: &lt;code&gt;handleAlarmActions()&lt;/code&gt;.  I don&amp;#8217;t like this one very much.  The word &lt;i&gt;handle&lt;/i&gt; is nice, but the name makes it sound like the alarms are an event.&lt;/p&gt;
&lt;p&gt;How about this one? &lt;code&gt;handleSensorStateChange()&lt;/code&gt;.  Much better in my opinion.  I&amp;#8217;m not quite sure how to justify this but I think that it is better to name these sorts of methods after their condition rather than their action. In the legacy code situation, at least, it helps to accent conditions.  In not-so legacy code, it separates concerns at a deeper level.&lt;/p&gt;
&lt;p&gt;Are there exceptions?  Of course.  Null pointer checks, guards.. the conditions that indicate errors rather than problem domain conditionality.. code surrounded by these can be safely extracted into methods named for their primary action.&lt;/p&gt;
&lt;p&gt;This:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    if (alarm != null) {
        ...
        alarm.sound();
    }
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;becomes this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    soundAlarm();
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with this definition:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    void soundAlarm() {
        if (alarm == null) {
            // handle error, throw exception, etc.
        }
        ...
        alarm.sound();
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That code still has problems, but that extraction was a way forward.&lt;/p&gt;
&lt;p&gt;All this is good, as far as it goes, but there is still a problem.  The &lt;i&gt;handle&lt;/i&gt; naming idiom seems to always call for generalization when I use it in real cases.&lt;/p&gt;
&lt;p&gt;Imagine a condition like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
if (sensor != null 
        &amp;#38;&amp;#38; sensor.isTripped() 
        &amp;#38;&amp;#38; configFlag == X_MODE 
        &amp;#38;&amp;#38; usingBasicIO) {
    ...
}
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;It would be &lt;i&gt;handle&lt;/i&gt;.. what?&lt;/p&gt;
&lt;p&gt;Sometimes you have a good name for a condition, sometimes you don&amp;#8217;t.  A convention would be nice, however.&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 12:05:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e78814ad-1bb5-4247-892e-a12920149635</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>"If-Methods Redux" by Office 2010</title>
      <description>&lt;p&gt;This article is GREAT it can be EXCELLENT JOB and what a great tool!&lt;/p&gt;</description>
      <pubDate>Fri, 13 Jan 2012 20:24:43 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:8f249332-ce6f-4b00-94c5-f14f394e8d68</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-197752</link>
    </item>
    <item>
      <title>"If-Methods Redux" by alwadifa</title>
      <description>&lt;p&gt;I liked you blog so im going bookmark it with my prefered websites, you have posted an amazing posts so thank you I liked you blog so im going bookmark it with my prefered websites, you have posted an amazing posts so thank you&lt;/p&gt;</description>
      <pubDate>Sat, 05 Nov 2011 17:55:52 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:26da5f7f-607a-48ff-839a-1a4096a50747</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-168769</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Tips For Bowling</title>
      <description>&lt;p&gt;I maintain also that substances, whether material or immaterial, cannot be conceived in their bare essence without any activity, activity being of the essence of substance in general.
Gottfried Leibniz&lt;/p&gt;</description>
      <pubDate>Thu, 20 Oct 2011 13:26:46 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c4a0c066-e5d4-447a-a95f-e98029608feb</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-160240</link>
    </item>
    <item>
      <title>"If-Methods Redux" by ysbearing</title>
      <description>&lt;p&gt;Slewing ring is also called slewing bearing, some people called: rotary support, swing support. English Name: slewing bearing or slewing ring bearing or turn table bearing, slewing ring in the real industrial applications is very wide.&lt;/p&gt;</description>
      <pubDate>Wed, 19 Oct 2011 03:29:28 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:45d4eece-248c-4bb8-8393-023e45b15510</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-159522</link>
    </item>
    <item>
      <title>"If-Methods Redux" by UGG Paisley Stivali</title>
      <description>&lt;p&gt;&lt;a href="http://www.uggscarpe2011.com/ugg-paisley-stivali-6/" rel="nofollow"&gt;UGG Paisley Stivali&lt;/a&gt; , Come si lascia il backspin, il difensore &#232; in questo momento alle spalle tutti, e vorrete essere alla ricerca insieme al basket hoop.Step 3: Fine-Non appena si lascia la &amp;#8220;spin&amp;#8221; che normalmente hanno due alternative , sparare o forse pass.If ha avuto un fronte superiore aperto con l&amp;#8217;obiettivo di basket (RIM), quindi prendere la shot.Nevertheless particolare, se un altro difensore ha lasciato uno in ogni dei tuoi compagni di squadra per aiutare la difesa, allora &#232; consiglia di passare a tuo compagno di squadra ora disponibile per avere un facile cesti regalo gourmet e un superbo assistere in base alle proprie needs.Keep a cuore, se si pu&#242; avere iniziato a spostare i propri Spin dal post basso, allora avrete una buona aspettano di utilizzare il tabellone per un turno facile lay-indietro up.Now che ar&lt;/p&gt;</description>
      <pubDate>Tue, 18 Oct 2011 22:25:27 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:db882fe7-0937-4138-a6fd-5207d7f0f84b</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-159215</link>
    </item>
    <item>
      <title>"If-Methods Redux" by shoesshoes</title>
      <description>&lt;p&gt;Cheap alfredia louboutin profit designed. 2010 Brand-new Design alfredia louboutin Footwear, &lt;a href="http://www.louboutinchaussures-fr.com/jimmy-choo-jimmy-choo-pompes-39_35/" rel="nofollow"&gt;Jimmy Choo Pompes&lt;/a&gt;alfredia louboutin bridalPumps, Innovative sandals resorts in jamaica, Alfredia Louboutin Boots. Excellent Promises. &lt;a href="http://www.louboutinchaussures-fr.com/jimmy-choo-39/" rel="nofollow"&gt;Jimmy Choo&lt;/a&gt;No charge Travel. Get hold of Now!, &lt;a href="http://www.canadagoosejakkedk.com" rel="nofollow"&gt;&lt;strong&gt;canada goose&lt;/strong&gt;&lt;/a&gt;Alfredia Louboutin women&#8217; ersus attire around ShopStyle. &lt;a href="http://www.canadagoosejakkedk.com" rel="nofollow"&gt;&lt;strong&gt;canada goose outlet&lt;/strong&gt;&lt;/a&gt;,Glance prevalent sellers to uncover alfredia louboutin pumps for cheap profits &#8211; a lot of a particular posture.&lt;/p&gt;


	&lt;p&gt;LOS ANGELES just simply currently,&lt;p&gt;&lt;a href="http://www.north-face-jakke.com/" rel="nofollow"&gt;&lt;em&gt;&lt;strong&gt;north face jakke&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; a person&amp;#8217;s sizeable theaters round the usa in a hurry to the shops humorous hwy humourous training video launched, &#8220;usua&lt;p&gt;&lt;a href="http://www.north-face-jakke.com/" rel="nofollow"&gt;&lt;em&gt;&lt;strong&gt;north face jakke&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;lly means all over, &#8221; furnishing increase so you might witnessing a different false male or female, this actually also popular issue is certainly absolutely in the training video merely a astounding sport activity gamed outside just by Zhang Xin Yi A person&amp;#8217;s &#8220; garnishment hoax girl. &#8221;&lt;/p&gt;</description>
      <pubDate>Fri, 16 Sep 2011 22:30:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:04023d62-701f-46b1-bc59-2df099950c37</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-141514</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Bowtrol</title>
      <description>&lt;p&gt;hmm ,i&amp;#8217;m not sure if this is what i&amp;#8217;m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff&lt;/p&gt;</description>
      <pubDate>Mon, 08 Aug 2011 16:08:32 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4efead27-bfed-44f7-8cc4-461f5bc3001f</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-125739</link>
    </item>
    <item>
      <title>"If-Methods Redux" by beats by dr dre headphones</title>
      <description>&lt;p&gt;I found that his foot odors never bring us to death.I never regret buying these &lt;a href="http://www.drebeatsstudio.com/beats-by-dr-dre-studio-c-3.html" rel="nofollow"&gt;beats by dr dre studio&lt;/a&gt; for him.
These &lt;a href="http://www.drebeatsstudio.com/beats-by-dr-dre-solo-c-5.html" rel="nofollow"&gt;beats by dr dre solo&lt;/a&gt; are just the same as selling in the franchise store.Or even better.&lt;/p&gt;</description>
      <pubDate>Fri, 03 Jun 2011 23:00:26 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:58707378-c535-482b-8404-fd2f388867bd</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-107865</link>
    </item>
    <item>
      <title>"If-Methods Redux" by christian louboutin shoes on sale</title>
      <description>&lt;p&gt;The article is dull.&lt;/p&gt;</description>
      <pubDate>Fri, 03 Jun 2011 06:49:18 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e5bdb554-6c90-4f30-bf11-e1b7d1c42c10</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-107648</link>
    </item>
    <item>
      <title>"If-Methods Redux" by real estate advertising</title>
      <description>&lt;p&gt;I love your article, I read it
Thank you :-)&lt;/p&gt;</description>
      <pubDate>Sat, 14 May 2011 13:40:08 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9e8bbf53-06de-4d16-82bf-4dec6882de5c</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-99901</link>
    </item>
    <item>
      <title>"If-Methods Redux" by okey oyunu oyna </title>
      <description>&lt;p&gt;great explanation.&lt;/p&gt;


	&lt;p&gt;internette g&#246;r&#252;nt&#252;l&#252; olarak &lt;a href="http://www.okeyoyunu-oyna.com" rel="nofollow"&gt;okey oyunu oyna&lt;/a&gt;, ger&#231;ek kisilerle tanis,
 turnuva heyecanini yasa.&lt;/p&gt;</description>
      <pubDate>Wed, 27 Apr 2011 14:13:38 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:19400e63-38fc-4335-9bb9-814fc4c0a8c2</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-91891</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Golda Skewek</title>
      <description>&lt;p&gt;I love this one. A very good post. Thank you. &lt;a href="http://www.kirkeyroofing.com/" rel="nofollow"&gt;roofing venice&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 13 Apr 2011 01:10:37 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:dbb388a1-188d-4cab-b20c-67ad47e1170e</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-83695</link>
    </item>
    <item>
      <title>"If-Methods Redux" by accounting services</title>
      <description>&lt;p&gt;The example you are using here again seems to indicate a context where many events need to be connected to some action.&lt;a href="http://www.admgroupllc.com/" rel="nofollow"&gt;accounting services&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 20 Jan 2011 10:33:18 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:b4ab385b-1e58-4dc3-8943-63be33ccc82e</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-58184</link>
    </item>
    <item>
      <title>"If-Methods Redux" by http://www.blacktowhiteiphone4.com</title>
      <description>&lt;p&gt;Bad news for folks who&amp;#8217;ve been holding out for a &lt;a href="http://www.blacktowhiteiphone4.com" rel="nofollow"&gt;white iPhone 4&lt;/a&gt;: Apple has delayed the white version of its popular smartphone until later this year. The white iPhone 4 was first delayed until late July, and then promised for the end of the month by Apple chief executive Steve Jobs just a week ago, but now there&amp;#8217;s no ship date in sight.&lt;/p&gt;</description>
      <pubDate>Wed, 22 Dec 2010 21:21:03 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e6545473-a90b-4675-a497-eeafc18ab925</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-51180</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Daniel Rijkhof</title>
      <description>&lt;p&gt;After reading i can only think of doing the next:&lt;/p&gt;


	&lt;p&gt;Split your if into 2 if&amp;#8217;s and only extract the inner if.&lt;/p&gt;


	&lt;p&gt;Very easy:&lt;/p&gt;


	&lt;p&gt;if ( configFlag == X_MODE &amp;#38;&amp;#38; usingBasicIO ) {
    soundAlarm();
}&lt;/p&gt;


	&lt;p&gt;+ the method&amp;#8230;&lt;/p&gt;


	&lt;p&gt;void soundAlarm(){
    if (sensor != null &amp;#38;&amp;#38; sensor.isTripped() ) {
        ...
    }
}&lt;/p&gt;


	&lt;p&gt;You still might want to extract the outer if aswel, but naming will at least be easier&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Sat, 18 Oct 2008 19:43:25 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f5362594-66e9-4bd3-a324-d60c36a2ccc4</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2129</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Keith Nicholas</title>
      <description>&lt;p&gt;considerSoundingAlarm&lt;/p&gt;</description>
      <pubDate>Tue, 07 Oct 2008 02:13:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e32acf38-48a7-42e4-aeeb-b7dd22cd4ea8</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2116</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Mark Knell</title>
      <description>&lt;p&gt;For that matter, I&amp;#8217;ve never been enamored with the naming pattern that begins booleans with &amp;#8220;is&amp;#8221;.  Like most of the above schemes, it&amp;#8217;s Hungarian notation all over again: forcing metadata into the same lexical token as the name.  ughYuck.&lt;/p&gt;


	&lt;p&gt;Back to the point: you&amp;#8217;ve already isolated where things fall apart. You had a nice, compact, conventionally verb-y phrase in mind to express the method&amp;#8217;s core behavior (&amp;#8220;soundAlarm&amp;#8221;). So far, so incontrovertible.&lt;/p&gt;


	&lt;p&gt;Once you start to shade the meaning with qualifiers like &amp;#8220;if&amp;#8221;, &amp;#8220;on&amp;#8221;, &amp;#8220;maybe&amp;#8221;, &amp;#8220;handle&amp;#8221;, etc., the days of simple declarative sentences are behind you.  In the syntax of natural language, when a verb becomes conditional, you&amp;#8217;ve gone subjunctive.  Quick show of hands: who can explain the subjunctive tense without a side trip to Wikipedia? Okay then: who knew that, technically, the subjunctive is a mood, not a tense? How many of you non-hand raisers are effective thinkers and communicators, despite your crippling ignorance of grammatical formalisms?  Yeah, I thought so.&lt;/p&gt;


	&lt;p&gt;In other words, the problem of expressing conditional behavior is not comfortably solved in most natural languages, so I wouldn&amp;#8217;t lose sleep over it here.  Moreover, by the nature of the problem, the extracted methods are implementation details, hence private, hence you can assume that no human reader will encounter any one of the extractions without the others close at hand.  Any halfway consistent notation will do.&lt;/p&gt;</description>
      <pubDate>Sat, 27 Sep 2008 06:41:12 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:a9a6e06f-7bf5-43e5-8cbc-4776734fb7e2</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2096</link>
    </item>
    <item>
      <title>"If-Methods Redux" by orcmid</title>
      <description>&lt;p&gt;I first saw the desire to bury conditional code in compiler writing a very long time ago.  The idea is to assure something if it is needed and do nothing otherwise (the desired state is already there), and to move the conditionality into the procedure to cut way down on having the caller know the condition to check at every point of call.&lt;/p&gt;


	&lt;p&gt;I think the key idea is that the post-condition is fixed, whatever the pre-condition is.  This allows simple sequences of operations and, at the end of each, some post-condition is established.&lt;/p&gt;


	&lt;p&gt;For example assureInAccumulator(whatever) or assureInputReady(stream), that sort of abstraction.&lt;/p&gt;


	&lt;p&gt;Instead of using is&amp;#8230; (for a predicate) or if&amp;#8230; (with unclear assertion), I thought of handle&amp;#8230; after the first post.  You can also use neededAlarm(...) or anyAlarm(...) to avoid convoluted wording, the idea being that, if it is called for, it has been handled.  Sometimes mk&amp;#8230; or make&amp;#8230; are used.&lt;/p&gt;


	&lt;p&gt;I think whatever it is, you want to consider the post-condition and frame the name in terms of whatever action is required to achieve it.  But being creative and appropriate to the context matters.&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 16:36:01 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ce202fe7-6410-4cbb-adcf-de75d74f8799</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2094</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Mark Stijnman</title>
      <description>&lt;p&gt;The example you are using here again seems to indicate a context where many events need to be connected to some action. I was wondering: is this the context in which you encounter these most?&lt;/p&gt;


	&lt;p&gt;Let me summarize the problem as I interpreted it: you have a long list of events (conditions) and their corresponding actions that are all in a single function. The connection between each event and each action is done by a simple if-statement. You now want to refactor this function, but you want the original function to still reflect the event, the action and their relationship.&lt;/p&gt;


In that case, personally,I wouldn&amp;#8217;t refactor it further than:
&lt;pre&gt;&lt;code&gt;
if (isSensorTriggered()) { SoundAlarm(); }
if (someOtherCondition()) { someOtherAction(); }
...
&lt;/code&gt;&lt;/pre&gt;
To me, this expresses the intent of the code just fine. An &amp;#8220;if (sensor  null)" check can be moved into "isSensorTriggerd", just as "if (alarm  null)&amp;#8221; can be moved into &amp;#8220;SoundAlarm()&amp;#8221;, because they are implementation details of the event and the action, respectively. They distract from the overall intent, so I want them gone. However, I want to maintain the cause-and-effect relation between &amp;#8220;isSensorTriggered&amp;#8221; and &amp;#8220;SoundAlarm&amp;#8221;, so I don&amp;#8217;t want to move &lt;em&gt;that&lt;/em&gt; &amp;#8220;if&amp;#8221; into a separate function.

IMHO, moving both the event and the action into a single entity will never be satisfactory. You have basically three choices:
&lt;ol&gt;
&lt;li&gt;Only name it after the event. This loses information on what the action will do when the event occurs.&lt;/li&gt;
&lt;li&gt;Only name it after the action. This loses information on when the action will be performed. (I suspect Avdi&amp;#8217;s suggestion of the &amp;#8216;maybe&amp;#8217;-convention to be among the best of this type, as it at least alerts the user that this information is missing)&lt;/li&gt;
&lt;li&gt;
Name it after both the event and the action. This makes me feel uneasy because it means I&amp;#8217;m admitting I have one entity performing two tasks, but at least all information is present in my main function. However, &lt;pre&gt;IfSensorTriggeredThenSoundAlarm();&lt;/pre&gt; or &lt;pre&gt;SoundAlarmWhenSensorTriggered();&lt;/pre&gt; isn&amp;#8217;t really better than &lt;pre&gt;if (isSensorTriggerd) { SoundAlarm(); }&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

If you really want to (or need to), you could work towards something like:
&lt;pre&gt;&lt;code&gt;
EventHandler ev = new EventHandler()
ev.RegisterEvent(isAlarmTriggered, soundAlarm)
ev.RegisterEvent(someOtherCondition, someOtherAction)
...
// elsewhere:
ev.HandleEvents()
&lt;/code&gt;&lt;/pre&gt;
This solution is more declarative in nature, clearly listing all the events and their corresponding actions, while more explicitly pointing out the event-action nature of the code. It also allows easy extension of the list of events and actions, even at run time.

	&lt;p&gt;As to your final example: it seems to me that the sub-conditions in that if-condition have different functions and therefore need to be separated anyway. Some clearly belong to the event condition (check for null on sensor: sensor can only trigger when there is a sensor), so they should be moved to the isSensorTripped() function. Others appear to belong to the action (what sort of IO to use), and should therefore be transferred to the SoundAlarm() function. I expect that most of the sub-conditions can be pushed to either the condition or the action functions.&lt;/p&gt;


	&lt;p&gt;Yet other sub-conditions appear to be used to switch the event on or off completely (configFlag). Note that the EventHandler approach allows you to elegantly separate this last type of sub-condition function as well: you simply register the isSensorTripped event only when configFlag is true.&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 16:03:22 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:16651949-1e4f-4ee1-894a-d88051d6744b</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2093</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Christian Edward Gruber</title>
      <description>&lt;p&gt;So this whole issue stems from the fact that you&amp;#8217;re actually building complex business rules (if chains are often a business rules issue).   You might consider that this is the sweet spot for a rules engine, such as JESS, DROOLS, or JRules and the like.  These use funky decision tree systems to keep rules execution clean and fast, then fire events (or hit callback functions) upon the successful exit from the rules system at a meaningful point.&lt;/p&gt;


	&lt;p&gt;If you have a small area where this is concentrated, then it&amp;#8217;s probably overkill, but if you have lots of this sort of thing, your application may benefit from this approach. From a code aesthetics and maintainability perspective, these can really really clean up this kind of system.  But it does effectively turn your system into a quasi-event-driven system, so your event-oriented naming becomes appropriate, and is quite nice to read.&lt;/p&gt;


	&lt;p&gt;in general, however, when I see if (foo &amp;#38;&amp;#38; bar &amp;#38;&amp;#38; (bash || !blah)) { doStuff(); } in the core business logic, I start to consider a rules engine, if it&amp;#8217;s more than a few instances of the case.&lt;/p&gt;


	&lt;p&gt;Side note &amp;#8211; this is sort of an application of the domain-specific language concept.  You&amp;#8217;re using a rules execution language (not a true DSL, but more domain-specific than a generalized programming language).&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 15:21:19 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:cab99a26-faa8-4213-b86e-ea5c8666fa83</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2092</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Morten Lyhr</title>
      <description>&lt;p&gt;If it is so hard to name right, perhaps we should not refactor the if statement to a new method?&lt;/p&gt;


	&lt;p&gt;On the other hand if the If statement is easily included in a method name(guard clauses etc.) then it can be refactored.&lt;/p&gt;


	&lt;p&gt;I think your if statements should be at the same level of abstraction, as the method(s) that is inside them&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 14:28:30 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:252543e9-9cb4-4750-b8c7-2bec98924f23</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2091</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Gaboto</title>
      <description>&lt;p&gt;What about modeling it with a state pattern or something that implies using polimorphic objects? I think the problem is that there are so many conditions that your code has plenty of if&amp;#8217;s&lt;/p&gt;


	&lt;p&gt;For example. If you are working on something like a parser (as you showed in your provious post):&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
if (Character.isLetter(ch) &amp;#38;&amp;#38; identCharCount &amp;gt; MIN_IDENT_LEN) {
    currentToken.append(ch);
}

if (Character.isWhitespace(char ch) {
    tokens.add(new Token(tokenBuffer.toString(), TokenType.IDENT));
    currentToken = new StringBuilder();
}
&lt;/code&gt;&lt;/pre&gt;

you can replace that code with something like:
&lt;pre&gt;&lt;code&gt;
...
this.parserActionFor(ch).doIt();
....
ParserAction parserActionFor(char ch)
{
     foreach( this.parserActionsClasses as actionClass)
    if(actionClass.isFor(ch))
         return actionClass.newFor(ch);  
}
...

Class ParserActionForLetter extends ParserAction
{
    static bool isFor(char ch)
        {
             return Character.isLetter(ch) &amp;#38;&amp;#38; identCharCount  &amp;gt; MIN_IDENT_LEN;
    }

    void doIt()
    {
        currentToken.append(ch);
    }
}
&lt;/code&gt;&lt;/pre&gt;
I think that something like that is more readable and makes your code more extensible and clean. I don&amp;#8217;t think that a name like &amp;#8220;doSomethingIfSomething&amp;#8221; is a problem, because it is readable and with clear intention. Nevertheless, if you have so many methods with those names in your class maybe you can try to model more polimorphic objects to solve the problem.

	&lt;p&gt;(Sorry about my english and my programming languages mixture in the examples :) )
bye!
Gaboto&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 14:21:37 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:06b6f5d4-5f97-4f49-b00f-d53b1e2385d1</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2090</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Dean Wampler</title>
      <description>&lt;p&gt;Personally, I would prefer &lt;code&gt;soundAlarmIfSensorTripped&lt;/code&gt; over &lt;code&gt;handleSensorStateChange&lt;/code&gt;. If I tell the Stakeholder &amp;#8220;the alarm will sound if the sensor is tripped&amp;#8221;, she will nod her head in agreement. If I tell her &amp;#8220;the sensor state change will be handled&amp;#8221;, she will mumble &amp;#8220;WTF??&amp;#8221;&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 14:15:29 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:581c92ce-984a-4f99-bd7a-c47447920192</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2089</link>
    </item>
    <item>
      <title>"If-Methods Redux" by Avdi Grimm</title>
      <description>&lt;p&gt;A convention I&amp;#8217;ve seen in (IIRC) Emacs-Lisp is to use the prefix &amp;#8220;maybe&amp;#8221;.  As in maybeSoundAlarm().  True, it doesn&amp;#8217;t tell you anything about the condition, but at least it makes it clear that it IS conditional and, as you point out, sometimes the condition is too complex to be summed up.  &amp;#8220;Maybe&amp;#8221; is a flag to the reader to consult the source if they need to know under what conditions the alarm will sound.&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 13:48:29 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1fe34200-964b-48fd-a531-8cf2bc6b6c81</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux#comment-2088</link>
    </item>
  </channel>
</rss>

