Introduce Explaining Variable

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by TobiW)
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://imygijesusy.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 
----
 
=[http://imygijesusy.co.cc CLICK HERE]=
 
----
 
</div>
 
 
If you have a complicated expression put them into temporary variables that explain what they do. This can help make code easier to read and understand.
 
If you have a complicated expression put them into temporary variables that explain what they do. This can help make code easier to read and understand.
  
  if ( (platform.toUpperCase().indexOf(&quot;MAC&quot;) &gt; -1) &amp;&amp;
+
  if ( (platform.toUpperCase().indexOf("MAC") > -1) &&
  (browser.toUpperCase().indexOf(&quot;IE&quot;) &gt; -1) &amp;&amp;
+
  (browser.toUpperCase().indexOf("IE") > -1) &&
  wasInitialized() &amp;&amp; resize &gt; 0 )
+
  wasInitialized() && resize > 0 )
 
  {
 
  {
 
   // do something
 
   // do something
 
  }
 
  }
  
  final boolean isMacOs    = platform.toUpperCase().indexOf(&quot;MAC&quot;) &gt; -1;&lt;br&gt;
+
  final boolean isMacOs    = platform.toUpperCase().indexOf("MAC") > -1;<br>
  final boolean isIEBrowser = browser.toUpperCase().indexOf(&quot;IE&quot;&gt; -1;&lt;br&gt;
+
  final boolean isIEBrowser = browser.toUpperCase().indexOf("IE"> -1;<br>
  final boolean wasResized  = resize &gt; 0;&lt;br&gt;&lt;br&gt;
+
  final boolean wasResized  = resize > 0;<br><br>
  if (isMacOs &amp;&amp; isIEBrowser &amp;&amp; wasInitialized() &amp;&amp; wasResized)
+
  if (isMacOs && isIEBrowser && wasInitialized() && wasResized)
 
  {
 
  {
 
   // do something
 
   // do something
 
  }
 
  }

Latest revision as of 03:08, 25 November 2010

If you have a complicated expression put them into temporary variables that explain what they do. This can help make code easier to read and understand.

if ( (platform.toUpperCase().indexOf("MAC") > -1) &&
(browser.toUpperCase().indexOf("IE") > -1) &&
wasInitialized() && resize > 0 )
{
  // do something
}
final boolean isMacOs     = platform.toUpperCase().indexOf("MAC") > -1;
final boolean isIEBrowser = browser.toUpperCase().indexOf("IE") > -1;
final boolean wasResized = resize > 0;

if (isMacOs && isIEBrowser && wasInitialized() && wasResized) { // do something }
Personal tools