<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>OmniaNour&#039;s Blog</title>
	<atom:link href="http://omnianour.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://omnianour.wordpress.com</link>
	<description>How to write a clean code</description>
	<lastBuildDate>Sat, 01 May 2010 22:13:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='omnianour.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>OmniaNour&#039;s Blog</title>
		<link>http://omnianour.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://omnianour.wordpress.com/osd.xml" title="OmniaNour&#039;s Blog" />
	<atom:link rel='hub' href='http://omnianour.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Introduction to Debugging</title>
		<link>http://omnianour.wordpress.com/2010/05/01/introduction-to-debugging/</link>
		<comments>http://omnianour.wordpress.com/2010/05/01/introduction-to-debugging/#comments</comments>
		<pubDate>Sat, 01 May 2010 22:11:02 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2010/05/01/introduction-to-debugging/</guid>
		<description><![CDATA[Through these posts, Debugging tips are going to be introduced. But first why Debugging?! The reason is simple . . . Software has bugs. Unfortunately, it is true. Even the good old &#8220;Hello World&#8221; program can be considered to be buggy. Developing software means having to deal with defects; old ones, new ones, the ones [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=23&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Through these posts, <a href="http://en.wikipedia.org/wiki/Debugging">Debugging</a> tips are going to be introduced. But first why Debugging?!</p>
<p>The reason is simple . . . <em><strong>Software has bugs</strong>.<br />
</em></p>
<p>Unfortunately, it is true. Even the good old &#8220;Hello World&#8221; program can be considered to be buggy.</p>
<p>Developing software means having to deal with defects; old ones, new ones, the ones you created yourself, and those that others have put in the code. Software developers debug programs for a living.</p>
<p>Hence, good debugging skills are a must-have.</p>
<p>We are going to start with generally applicable hints which should not be neglected. We are going to start with the &#8220;<span style="color:#ff8f43;"><em>13 Golden Rules of Debugging</em></span>&#8220;….</p>
<p><span style="color:#595959;"><em>1. Understand the Requirements<br />
</em></span></p>
<p>Make sure you understand the requirements before you begin to debug and fix anything.</p>
<p><span style="color:#595959;"><em>2. Make it Fail<br />
</em></span></p>
<p>You need a test case. Make your program fail. See it with your own eyes</p>
<p><span style="color:#595959;"><em>3 .Simplify the Test Case<br />
</em></span></p>
<p>You do this in order to</p>
<p>• rule out factors that do not play a role,</p>
<p>• reduce the runtime of the test case and, most importantly,</p>
<p>• make the test case easier to debug. <em>Who wants to deal with data containers filled</em><br />
<em>with hundreds or thousands of items</em>?</p>
<p><span style="color:#595959;"><em>4. Read the Right Error Message<br />
</em></span></p>
<p>Something went wrong and you face a screen full of error messages.</p>
<p>Which ones do you focus on?</p>
<p>It is surprising how many people don&#8217;t give the correct answer.</p>
<p><strong><em>The ones that come out first!<br />
</em></strong></p>
<p>So, first things first – fix the problems in the order of appearance, or have a very good reason for breaking this rule.</p>
<p><span style="color:#595959;"><em>5. Check the Plug<br />
</em></span></p>
<p>Next, check the seemingly obvious. Were all parts of the software up and running when the problem occurred? Permissions OK? Enough disk quota?</p>
<p>Think of ten common mistakes, and ensure nobody made them.</p>
<p><span style="color:#595959;"><em>6 .Separate Facts from Interpretation<br />
</em></span></p>
<p>Don&#8217;t jump to conclusions. Maintain a list of things you know for a fact, and why.</p>
<p>Ask yourself: &#8220;Can you prove it?&#8221; Is the behavior reproducible? Is what you consider a fact really a fact? &#8220;<em>It fails when I select a blue item but it always works for red items</em>&#8221; a bug report may state. So misbehavior depends on the color? Maybe not. It could be that the user selected the blue item with a mouse click and everything else via the keyboard, by specifying its name.</p>
<p><span style="color:#595959;"><em>7 .Divide and Conquer<br />
</em></span></p>
<p>The National Institute of Standards and Technology defines divide and conquer as an algorithmic technique to &#8220;<em>solve a problem, either directly because solving that instance is easy [. . . ] or by dividing it into two or more smaller instances</em>.&#8221; And further &#8220;<em>the solutions are combined to produce a solution for the original instance</em>.&#8221;</p>
<p>This strategy can be successfully applied to debugging in order to deal with complex situations when multiple factors can play a role.</p>
<p><span style="font-size:10pt;"><em>Hint: In the next post we will describe one possible divide-and-conquer approach.<br />
</em></span></p>
<p><span style="color:#595959;"><em>8. Match the Tool to the Bug<br />
</em></span></p>
<p>Some <a href="http://en.wikipedia.org/wiki/Debugging_tool">debugging tools</a> (like <a href="http://en.wikipedia.org/wiki/Gdb_%28debugger%29">GNU</a>) are easier to use than others in a given situation. But not all are equally helpful. It is natural to focus on the tools and processes you feel most comfortable with.</p>
<p><span style="color:#595959;"><em>9. One Change at a Time<br />
</em></span></p>
<p>Do not change more than one thing at a time if possible. Then check if it makes sense and, if not, revert back before trying out the next idea.</p>
<p><span style="color:#595959;"><em>10. Keep an Audit Trail<br />
</em></span></p>
<p>Often you will have to deal with a problem involving multiple parameters. You need to try out a number of combinations. It is all too easy to lose track of your changes.</p>
<p><em>Keep an audit trail</em>!</p>
<p>This is especially important in the case of spurious failures.</p>
<p><span style="color:#595959;"><em>11. Get a Fresh View<br />
</em></span></p>
<p>When you are stuck, go and find somebody to talk to. Make sure to draw a clear line between the facts – and why they are facts – and your theories. The process of explaining the situation to somebody else may help you to separate truth from myths.</p>
<p><span style="color:#595959;"><em>12 .If You Didn&#8217;t Fix it, it isn&#8217;t Fixed<br />
</em></span></p>
<p>Occasionally, a bug will just disappear after you modified some statements. Unless you have a good explanation why your fix is effective, you are better off to assume that the bug still exists and will hit again in the future.</p>
<p><span style="color:#595959;"><em>13. Cover your Bugfix with a Regression Test<br />
</em></span></p>
<p>So the problem is fixed . . . today. What about tomorrow? To make the bug fix last, you should turn your simplified test case (rule number3) into a regression test. Think of it as a safety bolt. It prevents others with access to the source code base from accidentally breaking a feature you have put quite some work into.</p>
<p>The term <strong>regression test</strong> means something along the lines of &#8220;<em>check whether yesterday&#8217;s functionality is still working well today.</em>&#8221; These tests should be automated in order to allow for frequent and efficient execution. And the tests should be self-checking.</p>
<p>Those were our tips for this week. Wait for tips about &#8220;<strong><em>Unit Tests and System Test</em></strong>&#8221; in the next week <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=23&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2010/05/01/introduction-to-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Emergence</title>
		<link>http://omnianour.wordpress.com/2009/12/14/emergence/</link>
		<comments>http://omnianour.wordpress.com/2009/12/14/emergence/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:35:25 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/12/14/emergence/</guid>
		<description><![CDATA[What if there were four simple rules that you could follow that would help you create good designs as you worked? Kent Beck&#8217;s four rules of Simple Design are of significant help in creating well-designed software. According to Kent, a design is &#8220;simple&#8221; if it follows these rules: • Runs all the tests • Contains [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=19&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#c00000;font-size:12pt;"><strong>What if there were four simple rules that you could follow that would help you create good designs as you worked? Kent Beck&#8217;s four rules of <em>Simple Design</em> are of significant help in creating well-designed software.<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">According to Kent, a design is &#8220;simple&#8221; if it follows these rules:<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#231f20;font-size:12pt;">• Runs all the tests</span></p>
<p style="margin-left:36pt;"><span style="color:#231f20;font-size:12pt;">• Contains no duplication<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;"> • Expresses the intent of the programmer<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;"> • Minimizes the number of classes and methods<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;"> (The rules are given in order of importance.)<br />
</span></p>
<p><span style="color:#7f7f7f;font-size:14pt;"><strong>Simple Design Rule 1: Runs All the Tests<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">First and foremost, a design must produce a system that acts as intended.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">A system that is comprehensively tested and passes all of its tests all of the time is a testable system.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Systems that aren&#8217;t testable aren&#8217;t verifiable. Arguably, a system that cannot be verified should never be deployed.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Fortunately, making our systems testable pushes us toward a design where our classes are small and single purpose. So making sure our system is fully testable helps us to create better designs.<br />
</span></p>
<p><span style="color:#7f7f7f;font-size:14pt;"><strong>Simple Design Rules 2: Refactoring<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">For each few lines of code we add, we pause and reflect on the new design. So, we clean it up and run our tests to demonstrate that we haven&#8217;t broken anything.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;"><em>The fact that we have these tests eliminates the fear</em><br />
<em>that cleaning up the code will break it!<br />
</em></span></p>
<p><span style="color:#7f7f7f;font-size:14pt;"><strong>No Duplication<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">Duplication is the primary enemy of a well-designed system. It represents additional work, additional risk, and additional unnecessary complexity.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Duplication forms:<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Lines of code that looks exactly alike<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Duplication of implementation<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">The TEMPLATE METHOD pattern is a common technique for removing higher-level duplication.<br />
</span></p>
<p><span style="color:#7f7f7f;font-size:14pt;"><strong>Expressive<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">The clearer the author can make the code, the less time others will have to spend understanding it. This will reduce defects and shrink the cost of maintenance.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Design patterns, for example, are largely about communication and expressiveness. By using the standard pattern names, such as COMMAND or VISITOR, in the names of the classes that implement those patterns, you can succinctly describe your design to other developers.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;">Well-written unit tests are also expressive. A primary goal of tests is to act as documentation by example.<br />
</span></p>
<p><span style="color:#7f7f7f;font-size:14pt;"><strong>Minimal Classes and Methods<br />
</strong></span></p>
<p><span style="color:#231f20;font-size:12pt;">In an effort to make our classes and methods small, we might create too many tiny classes and methods. So this rule suggests that we also keep our function and class counts low. This rule is the lowest priority of the four rules of Simple Design. So, although it&#8217;s important to keep class and function count low, it&#8217;s more important to have tests, eliminate duplication, and express yourself.<br />
</span></p>
<p><span style="color:#231f20;font-size:12pt;"><strong>Following the practice of simple design can and does encourage and enable developers to adhere to good principles and patterns that otherwise take years to learn.</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=19&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/12/14/emergence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Formatting</title>
		<link>http://omnianour.wordpress.com/2009/12/01/formatting/</link>
		<comments>http://omnianour.wordpress.com/2009/12/01/formatting/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:26:40 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/12/01/formatting/</guid>
		<description><![CDATA[Formatting You should take care that your code is nicely formatted. You should choose a set of simple rules that govern the format of your code, and then you should consistently apply those rules. If you are working on a team, then the team should agree to a single set of formatting rules and all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=15&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Formatting</p>
<ul>
<li><span style="color:black;font-family:Arial;font-size:12pt;">You should take care that your code is nicely formatted. You should choose a set of simple rules that govern the format of your code, and then you should consistently apply those rules.<br />
</span></li>
<li>
<div><span style="color:black;font-family:Arial;font-size:12pt;">If you are working on a team, then the team should agree to a single set of formatting rules and all members should comply.<br />
</span></div>
</li>
</ul>
<p><span style="color:#231f20;font-family:Arial;font-size:14pt;"><strong>The Purpose of Formatting<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;font-family:Arial;font-size:12pt;">Code formatting is about communication, and communication is the professional developer&#8217;s first order of business.<br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:12pt;">The coding style and readability set precedents that continue to affect maintainability and extensibility long after the original code has been changed beyond recognition.<br />
</span></li>
</ul>
<p style="margin-left:36pt;"><span style="color:#943634;font-family:Arial;font-size:16pt;"><strong>The formatting issues that help us to communicate best<br />
</strong></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-size:14pt;"><strong><span style="font-family:Arial;">Vertical Formatting</span><span style="font-family:Arial;"><br />
</span></strong></span></div>
<ul>
<li><span style="color:#231f20;font-family:Arial;">Vertical size: It turns out that there is a huge range of sizes and some remarkable differences in style.<br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;">It appears to be possible to build significant systems out of files that are typically 200 lines long, with an upper limit of 500. Although this should not be a hard and fast rule, it should be considered very desirable. Small files are usually easier to understand than large files are.<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>The Newspaper Metaphor</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;">Think of a well-written newspaper article. You read it vertically. At the top you expect a headline that will tell you what the story is about, We would like a source file to be like a newspaper article. The name should be simple but explanatory. The name, by itself, should be sufficient to tell us whether we are in the right module or not. The topmost parts of the source file should provide the high-level concepts and algorithms. Detail should increase as we move downward, until at the end we find the lowest level functions and details in the source file.<br />
</span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Vertical Openness Between Concepts</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;">Each line represents an expression or a clause, and each group of lines represents a complete thought. Those thoughts should be separated from each other with blank lines. This extremely simple rule has a profound effect on the visual layout of the code. Each blank line is a visual cue that identifies a new and separate concept. As you scan down the listing, your eye is drawn to the first line that follows a blank line.<br />
</span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Vertical Density</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;">If openness separates concepts, then vertical density implies close association. So lines of code that are tightly related should appear vertically dense.<br />
</span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Vertical Distance</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;">Concepts that are closely related should be kept vertically close to each other .Clearly this rule doesn&#8217;t work for concepts that belong in separate files. But then closely related concepts should not be separated into different files unless you have a very good reason.<br />
</span></p>
<p><span style="color:#984806;font-family:Arial;">For those concepts that are so closely related that they belong in the same source file, their vertical separation should be a measure of how important each is to the understandability of the other.<br />
</span></p>
<p><span style="color:#595959;font-family:Arial;"><strong>Variable Declarations</strong></span><span style="color:#231f20;"><span style="font-family:Arial;"><strong>,</strong></span><span style="font-family:Arial;"> Variables should be declared as close to their usage as possible. Local variables should appear at the top of each function, control variables for loops should usually be declared within the loop statement (In rare cases a variable might be declared at the top of a block or just before a loop in a long-ish function.)<br />
</span></span></p>
<p><span style="color:#595959;font-family:Arial;"><strong>Instance variables</strong></span><span style="color:#231f20;"><span style="font-family:Arial;"><strong>,</strong></span><span style="font-family:Arial;"> In C++ we commonly practiced the so-called </span><span style="font-family:Arial;"><em>scissors rule</em></span><span style="font-family:Arial;">, which put all the instance variables at the bottom, the common convention in Java, however, is to put them all at the top of the class. The important thing is for the instance variables to be declared in one well-known place. Everybody should know where to go to see the declarations.<br />
</span></span></p>
<p><span style="color:#595959;font-family:Arial;"><strong>Dependent Functions</strong></span><span style="color:#231f20;"><span style="font-family:Arial;"><strong>, </strong></span><span style="font-family:Arial;">If one function calls another, they should be vertically close, and the caller should be above the callee, if at all possible.<br />
</span></span></p>
<p><span style="color:#595959;font-family:Arial;"><strong>Conceptual Affinity</strong></span><span style="color:#231f20;"><span style="font-family:Arial;"><strong>, </strong></span><span style="font-family:Arial;">Certain bits of code </span><span style="font-family:Arial;"><em>want </em></span><span style="font-family:Arial;">to be near other bits. They have a certain</span><span style="font-family:Arial;"><em><br />
</em></span><span style="font-family:Arial;">conceptual affinity. The stronger that affinity, the</span><span style="font-family:Arial;"><em><br />
</em></span><span style="font-family:Arial;">less vertical distance there should be between</span><span style="font-family:Arial;"><em><br />
</em></span><span style="font-family:Arial;">them. The affinity might be based on a direct dependence (one function calling another, function using variable) OR other possible causes of affinity, it might be caused because a group of functions perform a similar operation.<br />
</span></span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Vertical Ordering</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;">In general we want function call dependencies to point in the downward direction. That is, a function that is called should be below a function that does the calling. This creates a nice flow down the source code module from high level to low level. As in newspaper articles, we expect the most important concepts to come first, and we expect them to be expressed with the least amount of polluting detail.<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:14pt;"><strong>Horizontal Formatting</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<ul style="margin-left:72pt;">
<li><span style="color:#231f20;font-family:Arial;">Programmers clearly prefer short lines. This suggests that we should strive to keep our lines short. The old Hollerith limit of 80 is a bit arbitrary, now it&#8217;s not opposed to lines edging out to 100 or even 120. But beyond that is probably just careless.<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Horizontal Openness and Density</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;"> We use horizontal white space to associate things that are strongly related and disassociate things that are more weakly related.<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#1d1b11;font-family:Courier New;">totalChars += lineSize;<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#984806;font-family:Arial;">The assignment operators were surrounded with white space to accentuate them. The spaces make that separation obvious.<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#984806;font-family:Arial;">Another use for white space is to accentuate the precedence of operators.<br />
</span></p>
<p><span style="color:#1d1b11;font-family:Courier New;"> double determinant = determinant (a, b, c);<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#1d1b11;font-family:Courier New;">return (-b + Math.sqrt(determinant)) / (2*a);<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#984806;font-family:Arial;">The factors have no white space between them because they are high precedence. The terms are separated by white space because addition and subtraction are lower precedence.<br />
</span></p>
<ul style="margin-left:72pt;">
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Indentation</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;"> A source file is a hierarchy rather like an outline. To make the hierarchy of scopes visible, we indent the lines of source code in proportion to their position in the hierarchy.<br />
</span></p>
<ul style="margin-left:72pt;">
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:12pt;"><strong>Dummy Scopes</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#984806;font-family:Arial;"> Sometimes the body of a </span><span style="font-family:Courier New;">while</span><span style="font-family:Arial;"> or </span><span style="font-family:Courier New;">for</span><span style="font-family:Arial;"> statement is a dummy<span style="color:#984806;"> (try to avoid them), when u cannot avoid them make sure that the dummy body is properly indented. Unless you make that semicolon </span></span><span style="font-family:Arial;"><em>visible </em></span><span style="color:#984806;font-family:Arial;">by indenting it on</span></p>
<p><span style="color:#984806;font-family:Arial;"> its own line, it&#8217;s just too hard to see.<br />
</span></p>
<ul>
<li>
<div><span style="color:#231f20;"><span style="font-family:Arial;font-size:14pt;"><strong>Team Rules</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></div>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;">A team of developers should agree upon a single formatting style, and then every member of that team should use that style. We don&#8217;t want it to appear to have been written by a bunch of disagreeing individuals.<br />
</span></div>
</li>
</ul>
</li>
</ul>
<p><span style="color:#231f20;font-family:Arial;"><strong> Remember, a good software system is composed of a set of documents that read nicely. They need to have a consistent and smooth style. The reader needs to be able to trust that the formatting gestures he or she has seen in one source file will mean the same thing in others. The last thing we want to do is add more complexity to the source code by writing it in a jumble of different individual styles.</strong></span></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;"><!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE AR-SA                           &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face 	{font-family:Cambria; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073741899 0 0 159 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:Arial; 	mso-bidi-theme-font:minor-bidi;} p.MsoTitle, li.MsoTitle, div.MsoTitle 	{mso-style-priority:10; 	mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-link:"Title Char"; 	mso-style-next:Normal; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:15.0pt; 	margin-left:0in; 	mso-add-space:auto; 	mso-pagination:widow-orphan; 	border:none; 	mso-border-bottom-alt:solid #4F81BD 1.0pt; 	mso-border-bottom-themecolor:accent1; 	padding:0in; 	mso-padding-alt:0in 0in 4.0pt 0in; 	font-size:26.0pt; 	font-family:"Cambria","serif"; 	mso-ascii-font-family:Cambria; 	mso-ascii-theme-font:major-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:major-fareast; 	mso-hansi-font-family:Cambria; 	mso-hansi-theme-font:major-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:major-bidi; 	color:#17365D; 	mso-themecolor:text2; 	mso-themeshade:191; 	letter-spacing:.25pt; 	mso-font-kerning:14.0pt;} p.MsoTitleCxSpFirst, li.MsoTitleCxSpFirst, div.MsoTitleCxSpFirst 	{mso-style-priority:10; 	mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-link:"Title Char"; 	mso-style-next:Normal; 	mso-style-type:export-only; 	margin:0in; 	margin-bottom:.0001pt; 	mso-add-space:auto; 	mso-pagination:widow-orphan; 	border:none; 	mso-border-bottom-alt:solid #4F81BD 1.0pt; 	mso-border-bottom-themecolor:accent1; 	padding:0in; 	mso-padding-alt:0in 0in 4.0pt 0in; 	font-size:26.0pt; 	font-family:"Cambria","serif"; 	mso-ascii-font-family:Cambria; 	mso-ascii-theme-font:major-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:major-fareast; 	mso-hansi-font-family:Cambria; 	mso-hansi-theme-font:major-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:major-bidi; 	color:#17365D; 	mso-themecolor:text2; 	mso-themeshade:191; 	letter-spacing:.25pt; 	mso-font-kerning:14.0pt;} p.MsoTitleCxSpMiddle, li.MsoTitleCxSpMiddle, div.MsoTitleCxSpMiddle 	{mso-style-priority:10; 	mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-link:"Title Char"; 	mso-style-next:Normal; 	mso-style-type:export-only; 	margin:0in; 	margin-bottom:.0001pt; 	mso-add-space:auto; 	mso-pagination:widow-orphan; 	border:none; 	mso-border-bottom-alt:solid #4F81BD 1.0pt; 	mso-border-bottom-themecolor:accent1; 	padding:0in; 	mso-padding-alt:0in 0in 4.0pt 0in; 	font-size:26.0pt; 	font-family:"Cambria","serif"; 	mso-ascii-font-family:Cambria; 	mso-ascii-theme-font:major-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:major-fareast; 	mso-hansi-font-family:Cambria; 	mso-hansi-theme-font:major-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:major-bidi; 	color:#17365D; 	mso-themecolor:text2; 	mso-themeshade:191; 	letter-spacing:.25pt; 	mso-font-kerning:14.0pt;} p.MsoTitleCxSpLast, li.MsoTitleCxSpLast, div.MsoTitleCxSpLast 	{mso-style-priority:10; 	mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-link:"Title Char"; 	mso-style-next:Normal; 	mso-style-type:export-only; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:15.0pt; 	margin-left:0in; 	mso-add-space:auto; 	mso-pagination:widow-orphan; 	border:none; 	mso-border-bottom-alt:solid #4F81BD 1.0pt; 	mso-border-bottom-themecolor:accent1; 	padding:0in; 	mso-padding-alt:0in 0in 4.0pt 0in; 	font-size:26.0pt; 	font-family:"Cambria","serif"; 	mso-ascii-font-family:Cambria; 	mso-ascii-theme-font:major-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:major-fareast; 	mso-hansi-font-family:Cambria; 	mso-hansi-theme-font:major-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:major-bidi; 	color:#17365D; 	mso-themecolor:text2; 	mso-themeshade:191; 	letter-spacing:.25pt; 	mso-font-kerning:14.0pt;} span.MsoBookTitle 	{mso-style-priority:33; 	mso-style-unhide:no; 	mso-style-qformat:yes; 	font-variant:small-caps; 	letter-spacing:.25pt; 	font-weight:bold;} span.TitleChar 	{mso-style-name:"Title Char"; 	mso-style-priority:10; 	mso-style-unhide:no; 	mso-style-locked:yes; 	mso-style-link:Title; 	mso-ansi-font-size:26.0pt; 	mso-bidi-font-size:26.0pt; 	font-family:"Cambria","serif"; 	mso-ascii-font-family:Cambria; 	mso-ascii-theme-font:major-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:major-fareast; 	mso-hansi-font-family:Cambria; 	mso-hansi-theme-font:major-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:major-bidi; 	color:#17365D; 	mso-themecolor:text2; 	mso-themeshade:191; 	letter-spacing:.25pt; 	mso-font-kerning:14.0pt;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:Arial; 	mso-bidi-theme-font:minor-bidi;} .MsoPapDefault 	{mso-style-type:export-only; 	margin-bottom:10.0pt; 	line-height:115%;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:&quot;Table Normal&quot;; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:&quot;&quot;; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin-top:0in; 	mso-para-margin-right:0in; 	mso-para-margin-bottom:10.0pt; 	mso-para-margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:&quot;Times New Roman&quot;; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin;} --> <!--[endif]--></p>
<div style="background:white none repeat scroll 0 0;border:medium medium 1pt none none solid 0 0 #4f81bd;padding:0 0 4pt;">
<p class="MsoTitle" style="background:white none repeat scroll 0 0;"><span class="MsoBookTitle"><span style="font-size:18pt;color:black;">Formatting</span></span></p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=15&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/12/01/formatting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Comments</title>
		<link>http://omnianour.wordpress.com/2009/11/12/comments/</link>
		<comments>http://omnianour.wordpress.com/2009/11/12/comments/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 22:10:31 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/11/12/comments/</guid>
		<description><![CDATA[Chapter#4 Comments The proper use of comments is to compensate for our failure to express our self in code. Comments are always failures. We must have them because we cannot always figure out how to express ourselves without them, but their use is not a cause for celebration. So when you find yourself in a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=8&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:12pt;"><strong>Chapter#4<br />
</strong></span></p>
<p><span style="font-size:12pt;"><strong> Comments<br />
</strong></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">The proper use of comments is to compensate for our failure to express our self in code. Comments are always failures. We must have them because we cannot always figure out how to express ourselves without them, but their use is not a cause for celebration. So when you find yourself in a position where you need to write a comment, think it through and see whether there isn&#8217;t some way to turn the tables and express yourself in code.<br />
</span></div>
</li>
<li><span style="color:#231f20;font-size:10pt;"><span style="font-family:Arial;">Code changes and evolves. Chunks of it move from here to there. Those chunks bifurcate and reproduce and come together again to form chimeras. Unfortunately the comments don&#8217;t always follow them</span><span style="font-family:Arial;"><em>—can&#8217;t</em></span><span style="font-family:Arial;"><em><br />
</em>always follow them. And all too often the comments get separated from the code they describe and become orphaned blurbs of ever decreasing accuracy.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">It is possible to make the point that programmers should be disciplined enough to keep the comments in a high state of repair, relevance, and accuracy. It&#8217;s Okay, But it is better that energy go toward making the code so clear and expressive that it does not need the comments in the first place.<br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Truth can only be found in one place: the code. Only the code can truly tell you what it does.</span> <span style="color:#231f20;"><span style="font-family:Arial;font-size:10pt;"> </span></span></li>
<li><span style="color:#231f20;"><span style="font-family:Arial;font-size:10pt;">One of the more common motivations for writing comments is bad code. But </span><span style="font-family:Arial;font-size:12pt;"><strong>Comments Do Not Make Up for Bad Code.</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#7f7f7f;font-family:Arial;font-size:20pt;"><strong>Good Comments<br />
</strong></span></p>
<p style="margin-left:36pt;"><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Legal Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Copyright and authorship statements are necessary and reasonable things to put into a comment at the start of each source file.<br />
</span></div>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> // Copyright (C) 2003, 2004, 2005 by Object Mentor, Inc. All rights reserved.<br />
</span></p>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Informative Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">It is sometimes useful to provide basic information with a comment. For example, consider this comment that explains the return value of an abstract method:</span><span style="color:#231f20;font-family:Arial;"> </span></li>
</ul>
<p><span style="font-size:9pt;"><span style="color:red;"><span style="font-family:Arial;"><strong> </strong></span><span style="font-family:Courier New;">// format matched kk:mm:ss EEE, MMM dd, yyyy</span></span></span><span style="color:red;font-family:Courier New;font-size:9pt;"> </span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> Pattern timeMatcher = Pattern.compile (&#8220;\\d*:\\d*:\\d* \\w*, \\w* \\d*, \\d*&#8221;);<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Explanation of Intent</strong></span><span style="font-family:Courier New;font-size:9pt;"><br />
</span></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes a comment goes beyond just useful information about the implementation and provides the intent behind a decision.<br />
</span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Clarification</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">In general it is better to find a way to make that argument or return value clear in its own right; but when it&#8217;s part of the standard library, or in code that you cannot alter, and then a helpful clarifying comment can be useful.<br />
</span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Warning of Consequences</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes it is useful to warn other programmers about certain consequences. For example, here is a comment that explains why a particular test case is turned off:</span><span style="color:#231f20;font-family:Arial;font-size:10pt;"> </span></li>
</ul>
<p><span style="color:red;"><span style="font-family:Arial;font-size:10pt;"> </span><span style="font-family:Arial;font-size:9pt;"><strong>// Don&#8217;t run unless you have some time to kill.<br />
</strong></span></span></p>
<p style="margin-left:36pt;"><span style="color:gray;"><strong><span style="font-family:Arial;font-size:12pt;">TODO Comments</span><span style="font-family:Arial;font-size:9pt;"><br />
</span></strong></span></p>
<ul>
<li>
<div><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;">TODO</span><span style="font-family:Arial;font-size:10pt;">s are jobs that the programmer thinks should be done, but for some reason can&#8217;t do at the moment, so it is sometimes reasonable to leave &#8220;To do&#8221; notes in the form of </span><span style="font-family:Courier New;font-size:9pt;">//TODO </span><span style="font-family:Arial;font-size:10pt;">comments, But you don&#8217;t want your code to be littered with </span><span style="font-family:Courier New;font-size:9pt;">TODO</span><span style="font-family:Arial;font-size:10pt;">s. So scan through them regularly and eliminate the ones you can.<br />
</span></span></div>
<p><span style="color:gray;font-family:Arial;font-size:12pt;"><strong>Amplification</strong></span><span style="color:#231f20;font-family:Arial;font-size:10pt;"><br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">A comment may be used to amplify the importance of something that may otherwise seem inconsequential.<br />
</span></li>
</ul>
<p><span style="font-family:Courier New;font-size:9pt;"><span style="color:#231f20;"> </span><span style="color:red;">String listItemContent = match.group (3).trim ();</span></span><span style="color:red;font-family:Arial;font-size:9pt;"><strong> </strong></span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Arial;font-size:9pt;"><strong> // the trim is real important. It removes the starting</strong><strong> </strong></span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Arial;font-size:9pt;"><strong> // spaces that could cause the item to be recognized<br />
</strong></span></p>
<p><span style="color:red;font-family:Arial;font-size:9pt;"><strong> // as another list.<br />
</strong></span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">new ListItemWidget (this, listItemContent, this.level + 1);</span><span style="color:red;font-family:Courier New;font-size:9pt;"> </span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">return buildList (text.substring (match.end ()));<br />
</span></p>
<p style="margin-left:36pt;">
<p><span style="color:#7f7f7f;font-family:Arial;font-size:20pt;"><strong>Bad Comments<br />
</strong></span></p>
<p><span style="color:#7f7f7f;"><span style="font-family:Arial;font-size:14pt;"><strong>(</strong></span><span style="font-family:Arial;font-size:10pt;">Most comments fall into this category.</span><span style="font-family:Arial;font-size:14pt;"><strong>)<br />
</strong></span></span></p>
<p style="margin-left:36pt;">
<p style="margin-left:36pt;"><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Mumbling</strong></span><span style="font-family:Courier New;font-size:9pt;"><br />
</span></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">If you decide to write a comment, then spend the time necessary to make sure it is the best comment you can write or it will turned into mumbling and it will left an enigma behind it<br />
</span></div>
<p><span style="color:#231f20;font-family:Arial;font-size:10pt;">Any comment that forces you to look in another module for the meaning of that comment has failed to communicate to you and is not worth the bits it consumes.<br />
</span></p>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Redundant Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">If the comment is not more informative than the code, or does not justify the code, or provide intent or rationale then it&#8217;s a redundant code.<br />
</span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Misleading Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes, with all the best intentions, a programmer makes a statement in his comments that isn&#8217;t precise enough to be accurate. This could cause another programmer to blithely call this function in wrong case. That poor programmer would then find himself in a debugging session trying to figure out where is the problem.<br />
</span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Mandated Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">It is just not rational to have a rule that says that every function must have a doc., or every variable must have a comment. Comments like this just clutter up the code and lend to general confusion and disorganization.<br />
</span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Journal Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes people add a comment to the start of a module every time they edit it. These comments accumulate as a kind of journal, or log, of every change that has ever been made. For example:<br />
</span></li>
</ul>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> /*<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> Changes (from 11-Oct-2001)<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> 11-Oct-2001: Re-organised the class and moved it to new package<br />
</span></p>
<p style="margin-left:72pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> com.jrefinery.date (DG);<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> 05-Nov-2001: Added a getDescription () method, and eliminated NotableDate<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> Class (DG);<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> 12-Nov-2001: IBD requires setDescription () method, now that NotableDate<br />
</span></p>
<p style="margin-left:108pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> class is gone (DG); Changed getPreviousDayOfWeek (),<br />
</span></p>
<p style="margin-left:72pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> getFollowingDayOfWeek () and getNearestDayOfWeek () to correct<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> bugs (DG);<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> */<br />
</span></p>
<p style="margin-left:36pt;">
<p style="margin-left:36pt;"><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Noise Comments</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes you see comments that are nothing but noise. They restate the obvious and provide no new information. For example:<br />
</span></div>
<p><span style="color:red;font-family:Courier New;font-size:9pt;">/** The day of the month. */<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;">private int dayOfMonth;<br />
</span></p>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Don&#8217;t Use a Comment When You Can Use a Function or a Variable</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Consider the following stretch of code:<br />
</span></div>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> // does the module from the global list &lt;mod&gt; depend on the<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">// subsystem we are part of?<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> if (smodule.getDependSubsystems ().contains(subSysMod.getSubSystem()))<br />
</span></p>
<p><span style="font-family:Arial;font-size:10pt;">This could be rephrased without the comment as<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> ArrayList moduleDependees = smodule.getDependSubsystems ();<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> String ourSubSystem = subSysMod.getSubSystem ();<br />
</span></p>
<p><span style="color:red;font-family:Courier New;font-size:9pt;"> if (moduleDependees.contains (ourSubSystem))<span style="text-decoration:underline;"><br />
</span></span></p>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Position Markers</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes programmers like to mark a particular position in a source file. For example, (was found in real program):<br />
</span></li>
</ul>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">// Actions //////////////////////////////////<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:#231f20;font-family:Arial;font-size:10pt;">There are rare times when it makes sense to gather certain functions together beneath a banner like this. But in general they are clutter that should be eliminated—especially the noisy train of slashes at the end.<br />
</span></p>
<p style="margin-left:36pt;">
<p style="margin-left:36pt;"><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Closing Brace Comments</strong></span><span style="font-family:Arial;font-size:10pt;text-decoration:underline;"><br />
</span></span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Sometimes programmers will put special comments on closing braces. Although this might make sense for long functions with deeply nested structures, it serves only to clutter the kind of small and encapsulated functions that we prefer. So if you find yourself wanting to mark your closing braces, try to shorten your functions instead.<span style="text-decoration:underline;"><br />
</span></span></div>
<p><span style="color:gray;"><span style="font-family:Arial;font-size:12pt;"><strong>Attributions and Bylines</strong></span><span style="font-family:Arial;font-size:10pt;text-decoration:underline;"><br />
</span></span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">/* Added by Rick */<br />
</span></p>
</li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">There is no need to pollute the code with little bylines. You might think that such comments would be useful in order to help others know who to talk to about the code. But the reality is that they tend to stay around for years and years, getting less and less accurate and relevant.<br />
</span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">The best place for this kind of information is the source code control system.<br />
</span></div>
<p><span style="color:gray;font-family:Arial;font-size:12pt;"><strong>Nonlocal Information<br />
</strong></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">If you must write a comment, then make sure it describes the code it appears near. Don&#8217;t offer system wide information in the context of a local comment.<br />
</span></div>
<p><span style="color:gray;font-family:Arial;font-size:12pt;"><strong>Inobvious Connection<br />
</strong></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">The connection between a comment and the code it describes should be obvious. If you are going to the trouble to write a comment, then at least you&#8217;d like the reader to be able to look at the comment and the code and understand what the comment is talking about. Consider, for example:<br />
</span></li>
</ul>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;"> /*<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">* start with an array that is big enough to hold all the pixels<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">* (plus filter bytes), and an extra 200 bytes for header info<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">*/<br />
</span></p>
<p style="margin-left:36pt;"><span style="color:red;font-family:Courier New;font-size:9pt;">this.pngBytes = new byte [((this.width + 1) * this.height * 3) + 200];<br />
</span></p>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">The purpose of a comment is to explain code that does not explain itself. It is a pity when a comment needs its own explanation.<br />
</span></div>
<p><span style="color:gray;font-family:Arial;font-size:12pt;"><strong>Function Headers<br />
</strong></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Short functions don&#8217;t need much description. A well-chosen name for a small function that does one thing is usually better than a comment header.<br />
</span></li>
</ul>
<ul>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;"><strong>Nothing can be quite as helpful as a well-placed comment. Nothing can clutter up a module more than frivolous dogmatic comment. Nothing can be quite as damaging as an old crufty comment that propagates lies and misinformation.<br />
</strong></span></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=8&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/11/12/comments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Functions</title>
		<link>http://omnianour.wordpress.com/2009/11/07/functions/</link>
		<comments>http://omnianour.wordpress.com/2009/11/07/functions/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 04:30:35 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/11/07/functions/</guid>
		<description><![CDATA[Clean Code Chapter#3: Functions The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. How short should a function be? Functions should hardly ever be 20 lines long, each should be transparently obvious, each should tell a story, and each should [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=7&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#215868;font-size:26pt;">Clean Code<br />
</span></p>
<h2><span style="color:#215868;font-size:14pt;"><em>Chapter#3:<br />
</em></span></h2>
<h2><span style="color:#215868;font-size:14pt;"><em>Functions</em><br />
</span></h2>
<ul>
<li><span style="font-size:10pt;"><span style="color:#231f20;font-family:Arial;">The first rule of functions is that they should be small. The second rule of functions is that </span><span style="color:#4bacc6;font-family:Arial;"><em>they should be smaller than that</em></span><span style="color:#231f20;font-family:Arial;">.<br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;"><strong>How short should a function be?<br />
</strong></span></div>
<ul>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Functions should hardly ever be 20 lines long, each should be transparently obvious, each should tell a story, and each should lead you to the next in a compelling order.<br />
</span></li>
</ul>
</li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Blocks within </span><span style="color:red;font-family:Courier New;font-size:9pt;">if</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-family:Arial;font-size:10pt;">statements, </span></span><span style="color:red;font-family:Courier New;font-size:9pt;">else</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-family:Arial;font-size:10pt;">statements, </span></span><span style="color:red;font-family:Courier New;font-size:9pt;">while</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-family:Arial;font-size:10pt;">statements, and so on should be one line long. Probably that line should be a function call.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">The indent level of a function should not be greater than one or two.<br />
</span></li>
<li><span style="color:#4bacc6;font-family:Arial;"><strong><em>F<span style="font-size:9pt;">UNCTIONS SHOULD DO ONE THING</span>. T<span style="font-size:9pt;">HEY SHOULD DO IT WELL</span>.T<span style="font-size:9pt;">HEY SHOULD DO IT ONLY</span>.<br />
</em></strong></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">The reason we write functions is to decompose a larger concept (in other words, the name of the function) into a set of steps at the next level of abstraction.<br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Functions that do one thing cannot be reasonably divided into sections.<br />
</span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Another way to know that a function is doing more than &#8220;one thing&#8221; is if you can extract another function from it with a name that is not merely a restatement of its implementation.<br />
</span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Mixing levels of abstraction within a function is always confusing. Readers may not be able to tell whether a particular expression is an essential concept or a detail. Worse, like broken windows, once details are mixed with essential concepts, more and more details tend to accrete within the function.<br />
</span></div>
<p><span style="color:#231f20;font-size:12pt;"><span style="font-family:Arial;"><strong><span style="text-decoration:underline;">The Stepdown Rule</span> (</strong></span><span style="font-family:Arial;">Reading Code from Top to Bottom</span><span style="font-family:Arial;"><strong>)<br />
</strong></span></span></li>
<li>
<div><span style="color:#231f20;font-size:10pt;"><span style="font-family:Arial;">It gives the ability to read the program as though it were a set of </span><span style="font-family:Arial;"><em>TO </em></span><span style="font-family:Arial;">paragraphs, each of which is describing the current level of abstraction and referencing subsequent </span><span style="font-family:Arial;"><em>TO </em></span><span style="font-family:Arial;">paragraphs at the next level down.<br />
</span></span></div>
<p><span style="color:#231f20;font-family:Arial;font-size:10pt;text-decoration:underline;"><strong>Switch Statements:<br />
</strong></span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">The general rule for </span><span style="color:red;font-family:Courier New;font-size:9pt;">switch</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-family:Arial;font-size:10pt;">statements is that they can be tolerated if they appear only once, are used to create polymorphic objects, and are hidden behind an inheritance relationship so that the rest of the system can&#8217;t see them.<br />
</span></span></div>
</li>
<li><span style="font-size:10pt;"><span style="color:#231f20;font-family:Arial;"><strong>Ward&#8217;s principle</strong>: &#8220;</span><span style="color:#4bacc6;font-family:Arial;"><em>You know you are working on clean code when each routine turns out to be pretty much what you expected</em></span><span style="color:#231f20;"><span style="font-family:Arial;"><em>.</em></span><span style="font-family:Arial;">&#8221; Half the battle to achieving that principle is choosing good names for small functions that do one thing. The smaller and more focused a function is, the easier it is to choose a descriptive name.<br />
</span></span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Be consistent in your names. Use the same phrases, nouns, and verbs in the function names you choose for your modules.<br />
</span></li>
<li><span style="font-family:Arial;font-size:10pt;"><span style="color:#231f20;">The ideal number of arguments for a function is zero (</span><span style="color:#e36c0a;"><strong>niladic</strong></span><span style="color:#231f20;">). Next comes one (</span><span style="color:#e36c0a;"><strong>monadic</strong></span><span style="color:#231f20;">), followed closely by two (</span><span style="color:#e36c0a;"><strong>dyadic</strong></span><span style="color:#231f20;">). Three arguments (</span><span style="color:#e36c0a;"><strong>triadic</strong></span><span style="color:#231f20;">) should be avoided where possible. More than three (</span><span style="color:#e36c0a;"><strong>polyadic</strong></span><span style="color:#231f20;">) requires very special justification—and then shouldn&#8217;t be used anyway.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Arguments are even harder from a testing point of view. Imagine the difficulty of writing all the test cases to ensure that all the various combinations of arguments work properly.<br />
</span></li>
<li><span style="font-size:10pt;"><span style="color:#231f20;font-family:Arial;">There are two very common reasons to pass a single argument (</span><span style="color:#e36c0a;font-family:Arial;"><strong>monadic</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">) into a function. You may be asking a question about that argument, or you may be operating on that argument, transforming it into something else and </span><span style="font-family:Arial;"><em>returning it</em></span><span style="font-family:Arial;">.<br />
</span></span></span></li>
<li><span style="font-size:10pt;"><span style="color:#231f20;font-family:Arial;">A function with two arguments (</span><span style="color:#e36c0a;font-family:Arial;"><strong>dyadic</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">) is harder to understand than a monadic function. The first argument glides past the eye, easily depositing its meaning. The second requires a short pause until we learn to ignore the first parameter. And </span><span style="font-family:Arial;"><em>that</em></span><span style="font-family:Arial;">, of course, eventually results in problems because we should never ignore any part of code. The parts we ignore are where the bugs will hide.<br />
</span></span></span></li>
<li><span style="color:#231f20;font-size:10pt;"><span style="font-family:Arial;">There are times, of course, where two arguments are appropriate. This case i</span><span style="font-family:Arial;"><em>s ordered components of a single value!</em></span><span style="font-family:Arial;"><br />
</span></span></li>
<li>
<div><span style="font-family:Arial;font-size:10pt;"><span style="color:#231f20;">Functions that take three arguments (</span><span style="color:#e36c0a;"><strong>triadic</strong></span><span style="color:#231f20;">) are significantly harder to understand than dyads. The issues of ordering, pausing, and ignoring are more than doubled.<br />
</span></span></div>
</li>
<li><span style="color:#231f20;font-size:10pt;"><span style="font-family:Arial;">A somewhat less common, but still very useful form for a single argument function is an </span><span style="font-family:Arial;"><em>event</em></span><span style="font-family:Arial;">. In this form there is an input argument but no output argument. The overall program is meant to interpret the function call as an event and use the argument to alter the state of the system.<br />
</span></span></li>
</ul>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;"><strong><em>Flag arguments</em></strong> are ugly. Passing a Boolean into a function is a truly terrible practice. It immediately complicates the signature of the method, loudly proclaiming that this function does        more than one thing. It does one thing if the flag is true and another if the flag is false!<br />
</span></div>
</li>
</ul>
<ul>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">When a function seems to need more than two or three arguments, it is likely that some of those arguments ought to be wrapped into a class of their own. Consider, for example:<br />
</span></div>
<ul>
<li><span style="color:#a6a6a6;font-family:Courier New;font-size:9pt;">Circle makeCircle(double x, double y, double radius);<br />
</span></li>
<li><span style="color:#a6a6a6;"><span style="font-family:Courier New;font-size:9pt;">Circle makeCircle(Point center, double radius);</span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></li>
</ul>
<p><span style="color:#231f20;font-family:Arial;font-size:10pt;">When groups of variables are passed together, they are likely part of a concept that deserves a name of its own.<br />
</span></li>
<li>
<div><span style="color:#231f20;font-family:Arial;font-size:10pt;">Anything that <strong>forces</strong> you to check the function signature is equivalent to a double-take. It&#8217;s a cognitive break and should be avoided.<br />
</span></div>
</li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;"><strong><em>Duplication</em></strong> may be the root of all evil in software. Many principles and practices have been created for the purpose of controlling or eliminating it.<br />
</span></li>
<li>
<div><span style="font-family:Arial;font-size:10pt;"><span style="color:#231f20;">Some programmers follow </span><span style="color:#4bacc6;"><strong>Edsger Dijkstra</strong></span></span><span style="color:#231f20;"><span style="font-family:Arial;"><span style="font-size:10pt;">&#8216;s rules of structured programming.</span><span style="font-size:5pt;">14 </span><span style="font-size:10pt;">Dijkstra said that every function, and every block within a function, should have one entry and one exit. Following these rules means that there should only be one </span></span><span style="font-family:Courier New;font-size:9pt;">return </span><span style="font-family:Arial;font-size:10pt;">statement in a function, no </span></span><span style="color:red;font-family:Courier New;font-size:9pt;">break</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-family:Arial;font-size:10pt;">or </span></span><span style="color:red;font-family:Courier New;font-size:9pt;">continue</span><span style="color:#231f20;"><span style="font-family:Courier New;font-size:9pt;"><br />
</span><span style="font-size:10pt;"><span style="font-family:Arial;">statements in a loop, and never, </span><span style="font-family:Arial;"><em>ever, </em></span><span style="font-family:Arial;">any </span></span><span style="font-family:Courier New;font-size:9pt;">goto </span><span style="font-family:Arial;font-size:10pt;">statements.<br />
</span></span></div>
</li>
<li><span style="color:#231f20;font-family:Arial;font-size:10pt;">Every system is built from a domain-specific language designed by the programmers to describe that system. Functions are the verbs of that language, and classes are the nouns.<br />
</span></li>
</ul>
<p><span style="color:#231f20;font-family:Arial;font-size:10pt;">Never forget that your real goal is to tell the story of the system, and that the functions you write need to fit cleanly together into a clear and precise language to help you with that telling.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=7&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/11/07/functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Meaningful Names</title>
		<link>http://omnianour.wordpress.com/2009/10/23/6/</link>
		<comments>http://omnianour.wordpress.com/2009/10/23/6/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 16:46:02 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/10/23/6/</guid>
		<description><![CDATA[Clean Code Chapter#2 &#8220;Meaningful Names&#8221; Using intention-revealing names: Choosing good names takes time but saves more than it takes. Take care with your names and change them when you find better ones. The name of a variable, function, or class, should answer all the big questions. It should tell you why it exists, what it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=6&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#1f497d;font-family:Century Gothic;font-size:20pt;"><strong>Clean Code<br />
</strong></span></p>
<p><span style="color:#1f497d;font-family:Century Gothic;"><strong>Chapter#2 &#8220;Meaningful Names&#8221;<br />
</strong></span></p>
<p><span style="color:#1f497d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Using intention-revealing names:<br />
</strong></span></p>
<ul>
<li><span style="font-family:Century Gothic;"><span style="color:#231f20;">Choosing good names takes time but saves more than it takes.</span><br />
</span></li>
<li><span style="font-family:Century Gothic;"><span style="color:#231f20;">Take care with your names and change them when you find better ones.</span><br />
</span></li>
<li>
<div><span style="color:#231f20;font-family:Century Gothic;">The name of a variable, function, or class, should answer all the big questions. It should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.<br />
</span></div>
</li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Avoid Disinformation:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;font-family:Century Gothic;">Programmers must avoid leaving false clues that obscure the meaning of code.<span style="text-decoration:underline;"><br />
</span></span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">We should avoid words whose entrenched meanings vary from our intended meaning. For example,</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">hp</span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">aix</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">sco</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">would be poor variable names because they are the names of <strong>UNIX</strong> platforms or variants.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Do not refer to a grouping of accounts as an </span><span style="font-family:Courier New;"><strong>accountList</strong><span style="color:#231f20;"><br />
</span></span><span style="font-family:Century Gothic;">unless it&#8217;s actually a </span><span style="font-family:Courier New;"><strong>List</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">. </span><span style="font-family:Century Gothic;">The word list means something specific to programmers. If the container holding the accounts is not actually a</span><span style="font-family:Arial;"><br />
</span></span><span style="font-family:Courier New;"><strong>List</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">it may lead to false conclusions. So</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>accountGroup</strong><br />
</span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>bunchOfAccounts</strong><br />
</span><span style="font-family:Century Gothic;">or just plain</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>accounts</strong><br />
</span><span style="font-family:Century Gothic;">would be better.<br />
</span></span></li>
<li>
<div><span style="color:#231f20;"><span style="font-family:Century Gothic;">Beware of using names which vary in small way. </span><span style="font-family:Arial;">(</span></span><span style="color:red;font-family:Courier New;">XYZControllerForEfficientHandlingOfStrings</span><span style="color:#231f20;"><span style="font-family:Courier New;">,</span><span style="font-family:Arial;"><br />
</span></span></div>
<p><span style="color:red;font-family:Courier New;">XYZControllerForEfficientStorageOfStrings</span><span style="color:#231f20;font-family:Arial;">)<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">Spelling similar concepts similarly is</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Century Gothic;"><strong><em>information</em></strong></span><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">Using inconsistent spellings is</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Century Gothic;"><strong><em>disinformation</em></strong></span><span style="font-family:Arial;">.</span><span style="font-family:Arial;"><br />
</span></span></li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Make Meaningful Distinctions:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;font-family:Century Gothic;">Programmers create problems for themselves when they write code solely to satisfy a compiler or interpreter.<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">It is not sufficient to add number series </span><span style="font-family:Courier New;">(</span></span><span style="font-family:Courier New;"><span style="color:red;">a1</span><span style="color:#231f20;">, </span><span style="color:red;">a2</span><span style="color:#231f20;">&#8230; </span><span style="color:red;">aN</span></span><span style="color:#231f20;"><span style="font-family:Courier New;">)</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Century Gothic;">or noise words, even though the compiler is satisfied.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Noise words are another meaningless distinction. Imagine that you have a </span><span style="color:red;font-family:Courier New;">Product</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">class. If you have another called </span></span><span style="color:red;font-family:Courier New;">ProductInfo</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">ProductData</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">you have made the names different without making them mean anything different.</span><span style="font-family:Arial;"><br />
</span></span><span style="font-family:Courier New;"><strong>Info</strong><span style="color:#231f20;"><br />
</span></span><span style="font-family:Century Gothic;">and</span><span style="color:#231f20;font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>Data</strong><span style="color:#231f20;"><br />
</span></span><span style="font-family:Century Gothic;">are indistinct noise words like</span><span style="color:#231f20;"><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>a</strong></span><span style="font-family:Arial;">, </span><span style="font-family:Courier New;"><strong>an</strong></span><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>the</strong></span><span style="font-family:Arial;">.</span><span style="font-family:Courier New;"><br />
</span></span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">The word</span><span style="font-family:Arial;"><br />
</span><span style="font-family:Courier New;"><strong>variable</strong><br />
</span><span style="font-family:Century Gothic;">should never appear in a variable name, the word </span><span style="font-family:Courier New;"><strong>table</strong><br />
</span><span style="font-family:Century Gothic;">should never appear in a table name.<br />
</span></span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">The variable</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">moneyAmount</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">is indistinguishable from</span><span style="font-family:Arial;"><br />
</span></span><span style="font-family:Courier New;"><strong>money</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">customerInfo</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">is indistinguishable from </span></span><span style="font-family:Courier New;"><strong>customer</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">accountData</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">is indistinguishable from </span></span><span style="font-family:Courier New;"><strong>account</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">theMessage</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">is indistinguishable from</span><span style="font-family:Arial;"><br />
</span></span><span style="font-family:Courier New;"><strong>message</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">.</span><span style="font-family:Century Gothic;"> Distinguish names in such a way that the reader knows what the differences offer.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">A significant part of our brains is dedicated to the concept of words. And words are, by definition, pronounceable. It would be a shame not to take advantage of that huge portion of our brains that has evolved to deal with spoken language. So make your names pronounceable.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">This matters because programming is a social activity.<br />
</span></li>
<li>
<div><span style="font-family:Century Gothic;"><span style="color:#17365d;font-size:16pt;text-decoration:underline;"><strong>Use Searchable Names:</strong></span><span style="color:#231f20;"><br />
</span></span></div>
</li>
<li><span style="color:#231f20;font-family:Century Gothic;">Single-letter names and numeric constants have a particular problem in that they are not easy to locate across a body of text.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Single-letter names can ONLY be used as local variables inside short methods.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">The length of a name should correspond to the size of its scope.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">If a variable or constant might be seen or used in multiple places in a body of code, it is imperative to give it a search-friendly name.<br />
</span></li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Avoid Encoding:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;font-family:Century Gothic;"><em>Encoded names are seldom pronounceable and are easy to mis-type.<br />
</em></span></li>
<li>
<div><span style="color:#365f91;"><span style="font-family:Arial;font-size:12pt;"><strong>Hungarian Notation</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></div>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;"><br />
</span><span style="font-family:Century Gothic;"><strong>FORTRAN</strong> forced encodings by making the first letter a code for the type.<br />
</span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Early versions of <strong>BASIC</strong> allowed only a letter plus one digit.<br />
</span></li>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">HN was considered to be pretty important back in the <strong>Windows C API</strong>, when everything was an integer handle or a long pointer or a </span><span style="font-family:Courier New;">void </span><span style="font-family:Century Gothic;">pointer, or one of several implementations.</span><span style="font-family:Arial;"><br />
</span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">In modern languages we have much richer type systems, and the compilers remember and enforce the types. So nowadays <strong>HN</strong> and other forms of type encoding are simply impediments. They make it harder to change the name or type of a variable, function, or class. They make it harder to read the code. And they create the possibility that the encoding system will mislead the reader.<span style="font-size:10pt;"><br />
</span></span></li>
</ul>
</li>
<li>
<div><span style="color:#365f91;"><span style="font-family:Arial;font-size:12pt;"><strong>Member Prefixes</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></div>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">You don&#8217;t need to prefix member variables with</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">m_</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">anymore because the more we read the code, the less we see the prefixes. Eventually the prefixes become unseen clutter and a marker of older code.<br />
</span></span></li>
</ul>
</li>
<li>
<div><span style="color:#365f91;"><span style="font-family:Arial;font-size:12pt;"><strong>Interfaces and Implementations</strong></span><span style="font-family:Arial;font-size:10pt;"><br />
</span></span></div>
<ul>
<li><span style="color:#231f20;font-family:Century Gothic;">These are sometimes a special case for encodings. if you must encode either the interface or the implementation, I choose the implementation.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Example: an <strong>ABSTRACT FACTORY </strong>for the creation of shapes will be an interface and will be implemented by a concrete class, what should be its name &#8220;</span><span style="color:red;font-family:Courier New;">IShapeFactory</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">or</span><span style="font-family:Courier New;"><br />
</span></span><span style="color:red;font-family:Courier New;">ShapeFactory</span><span style="color:#231f20;"><span style="font-family:Courier New;">&#8220;?</span><span style="font-family:Arial;">! </span><span style="font-family:Century Gothic;">The preceding</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;"><strong>I</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">so common in today&#8217;s legacy wads, is a distraction at best and too much information at worst, you just want them to know that it&#8217;s a </span></span><span style="color:red;font-family:Courier New;">ShapeFactory</span><span style="color:#231f20;font-family:Arial;">.<br />
</span></li>
</ul>
</li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Avoid Mental Mapping:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;font-family:Century Gothic;">Readers shouldn&#8217;t have to mentally translate your names into other names they already know. This problem generally arises from a choice to use neither problem domain terms nor solution domain terms.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">A loop counter may be named </span><span style="color:red;font-family:Courier New;">i</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">j</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">k</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Arial;">(</span><span style="font-family:Century Gothic;">though never </span></span><span style="color:red;font-family:Courier New;">l</span><span style="color:#231f20;"><span style="font-family:Arial;">!)</span><span style="font-family:Century Gothic;"> if its scope is very small and no other names can conflict with it, but generally a single-letter name is a poor choice.<br />
</span></span></li>
<li>
<div><span style="color:#231f20;"><span style="font-family:Century Gothic;">One difference between a smart programmer and a professional programmer is that the professional understands that <strong><em>clarity is king</em></strong></span><span style="font-family:Arial;">.<br />
</span></span></div>
</li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Class Names:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">Classes and objects should have noun or noun phrase names like</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">Customer</span><span style="color:#231f20;"><span style="font-family:Arial;">,</span><span style="font-family:Courier New;"><br />
</span></span><span style="color:red;font-family:Courier New;">Account</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">AddressParser</span><span style="color:#231f20;"><span style="font-family:Arial;">. </span><span style="font-family:Century Gothic;">Avoid words like</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">Manager</span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">Processor</span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">Data</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">Info</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">in the name of a class. A class name should not be a verb.</span><span style="font-family:Arial;"><br />
</span></span></li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Method Names:<br />
</strong></span></p>
<ul>
<li><span style="color:#231f20;"><span style="font-family:Century Gothic;">Methods should have verb or verb phrase names like</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">postPayment</span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;">deletePage</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">or</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">save</span><span style="color:#231f20;"><span style="font-family:Arial;">. </span><span style="font-family:Century Gothic;"><strong>Accessors</strong>, <strong>mutators</strong>, and <strong>predicates</strong> should be named for their value and prefixed with </span></span><span style="color:red;font-family:Courier New;">get</span><span style="color:#231f20;"><span style="font-family:Arial;">,</span><span style="font-family:Courier New;"><br />
</span></span><span style="color:red;font-family:Courier New;">set</span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;">is</span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">according to the <strong><em>JavaBeans</em></strong> standard</span><span style="font-family:Arial;">. (</span></span>JavaBeans technology is the component architecture for the Java 2 Platform, Standard Edition (J2SE). Components (JavaBeans) are reusable software programs that you can develop and assemble easily to create sophisticated applications.)<span style="color:#231f20;font-family:Arial;"><br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">When constructors are overloaded, use static factory methods with names that describe the arguments.<br />
</span></li>
</ul>
<p><span style="color:#17365d;font-family:Century Gothic;font-size:16pt;text-decoration:underline;"><strong>Tips:<br />
</strong></span></p>
<p style="margin-left:36pt;">
<ul>
<li><span style="color:#231f20;"><span style="font-family:Arial;">I</span><span style="font-family:Century Gothic;">f names are too clever, they will be memorable only to people who share the author&#8217;s sense of humor, and only as long as these people remember the joke. This often appears in the form of colloquialisms or slang. So &#8220;Say what you mean. Mean what you say&#8221;.<br />
</span></span></li>
<li>
<div><span style="color:#231f20;font-family:Century Gothic;">Pick one word for one abstract concept and stick with it. For instance, it&#8217;s confusing to have </span><span style="color:red;font-family:Courier New;"><strong>fetch</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>retrieve</strong></span><span style="color:#231f20;"><span style="font-family:Courier New;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;"><strong>get</strong></span><span style="color:#231f20;"><span style="font-family:Courier New;"><br />
</span><span style="font-family:Century Gothic;">as equivalent methods of different classes.<br />
</span></span></div>
<p><span style="color:#231f20;font-family:Century Gothic;">(Modern editing environments like Eclipse and IntelliJ-provide context-sensitive clues, such list of methods you can call on a given object).<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Avoid using the same word for two purposes.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Using the same term for two different ideas is essentially a pun, so follow &#8220;one word per concept&#8221; rule.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Remember that the people who read your code will be programmers. So go ahead and use computer science (<strong>CS</strong>) terms, algorithm names, pattern names, math terms and so forth.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">When there is no &#8220;<em>programmer-eese</em>&#8221; for what you&#8217;re doing, use the name from the problem domain.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Separating solution and problem domain concepts is part of the job of a good programmer and designer.<br />
</span></li>
<li><span style="color:#231f20;font-family:Century Gothic;">Shorter names are generally better than longer ones, so long as they are clear. Add no more context to a name than is necessary.<br />
</span></li>
<li>
<div><span style="color:#231f20;"><span style="font-family:Century Gothic;">Imagine that you have variables named</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;"><strong>firstName</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>lastName</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>street</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>houseNumber</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>city</strong></span><span style="color:#231f20;font-family:Arial;">, </span><span style="color:red;font-family:Courier New;"><strong>state</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">, </span><span style="font-family:Century Gothic;">and</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;"><strong>zipcode</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">. </span><span style="font-family:Century Gothic;">Taken together it&#8217;s pretty clear that they form an address.But if u want to use state variable alone in a method you can add context by using prefixes &#8220;</span></span><span style="color:red;font-family:Courier New;"><strong>addrState</strong></span><span style="color:#231f20;font-family:Century Gothic;">&#8221; ,so readers will understand that these variables are part of a larger structure.<br />
</span></div>
<p><span style="color:#231f20;"><span style="font-family:Century Gothic;">(Of course, a better solution is to create a class named</span><span style="font-family:Arial;"><br />
</span></span><span style="color:red;font-family:Courier New;"><strong>Address</strong></span><span style="color:#231f20;"><span style="font-family:Arial;">. </span><span style="font-family:Century Gothic;">Then, even the compiler knows that the variables belong to a bigger concept.</span><span style="font-family:Arial;">)<br />
</span></span></li>
</ul>
<p><span style="color:#231f20;"><span style="font-family:Arial;"><br />
</span><span style="font-family:Century Gothic;"><strong>The hardest thing about choosing good names is that it requires good descriptive skills and a shared cultural background. Follow some of these rules and see whether you don&#8217;t improve the readability of your code. If you are maintaining someone else&#8217;s code, use refactoring tools to help resolve these problems. It will pay off in the short term and continue to pay in the long run.</strong></span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=6&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/10/23/6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to Clean Code</title>
		<link>http://omnianour.wordpress.com/2009/10/17/introduction-to-clean-code/</link>
		<comments>http://omnianour.wordpress.com/2009/10/17/introduction-to-clean-code/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 23:40:41 +0000</pubDate>
		<dc:creator>OmniaNour</dc:creator>
				<category><![CDATA[CleanCode]]></category>

		<guid isPermaLink="false">http://omnianour.wordpress.com/2009/10/17/introduction-to-clean-code/</guid>
		<description><![CDATA[Clean Code &#160; Chapter 1: &#8220;Clean Code&#8221; Code represents the details of the requirements. Programming means specifying requirements in such detail that a machine can execute them. There is a bad code and clean code dealing with bad code is called &#8220;wading through a bad code&#8221;. A bad code can bring a company down …there [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=3&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;">
<h1><span style="font-family:Century Gothic;font-size:22pt;">Clean Code<br />
</span></h1>
<p>&nbsp;</p>
<h1><span style="font-family:Century Gothic;font-size:12pt;">Chapter 1:<br />
</span></h1>
<h2><span style="font-family:Century Gothic;font-size:12pt;"> &#8220;Clean Code&#8221;<br />
</span></h2>
<ul>
<li><span style="font-family:Century Gothic;font-size:12pt;">Code represents the details of the requirements.<br />
</span></li>
<li><span style="font-family:Century Gothic;font-size:12pt;"><span style="color:gray;"><strong>Programming</strong></span> means specifying requirements in such detail that a machine can execute them.<br />
</span></li>
<li><span style="font-family:Century Gothic;font-size:12pt;">There is a <span style="color:gray;"><strong>bad code</strong></span> and <span style="color:gray;"><strong>clean code</strong></span> dealing with bad code is called &#8220;wading through a bad code&#8221;.<br />
</span></li>
<li>
<div><span style="font-family:Century Gothic;font-size:12pt;">A bad code can bring a company down …there was a company in the late 80s, wrote a <em>killer</em> app. It was very popular, and lots of professionals bought and used it. But then the release cycles began to stretch. Bugs were not repaired from one release to the next. Load times grew and crashes increased, then the company went out of business.<br />
</span></div>
<p><span style="font-family:Century Gothic;font-size:12pt;">What exactly happened is that the company had rushed the product to market and had made a huge mess in the code. As they added more and more features, the code got worse and worse until they simply could not manage it any longer. <span style="color:gray;"><strong><em>It was the bad code that brought the company down</em></strong><span style="color:#95b3d7;">.</span><br />
</span></span></li>
<li>
<div><span style="font-family:Century Gothic;font-size:12pt;">Never write a program in harry then revise it later according to<br />
</span></div>
<p><span style="color:gray;font-family:Century Gothic;font-size:12pt;"><em><strong>LeBlanc&#8217;s Law: </strong>Later equals never.<br />
</em></span></li>
<li><span style="font-family:Century Gothic;font-size:12pt;">When a company team fails to finish a program because of the messy code, another team is collected called &#8220;Tiger team&#8221; to start coding from the beginning. Then the competition starts between the 2 teams to finish the program, this takes a lot of time it could reach 10 years!!<br />
</span></li>
<li>
<div><span style="font-family:Century Gothic;font-size:12pt;">The key of writing a clean code is &#8220;code-sense&#8221;. Not only does it let us see whether code is good or bad, but it also shows us the strategy for applying our discipline to transform bad code into clean code.<br />
</span></div>
</li>
<li>
<div><span style="font-family:Century Gothic;font-size:12pt;">There are probably as many definitions as there are programmers for <span style="color:gray;"><strong>clean code</strong></span>. So next are thoughts of some very well-known and deeply experienced programmers:<br />
</span></div>
<ul>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>Grady Booch, author of Object Oriented Analysis and Design with Applications…</strong>&#8220;<br />
</span></div>
<p><span style="font-family:Century Gothic;font-size:12pt;"><span style="color:#231f20;">Clean code reads like well-written prose&#8221;.</span><br />
</span></li>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>&#8220;Big&#8221; Dave Thomas, founder of OTI, godfather of the Eclipse strategy…</strong>&#8220;<strong><br />
</strong></span></div>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">Clean code can be read, and enhanced by a developer other than its original author.&#8221;<strong><br />
</strong></span></li>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>Michael Feathers, author of Working Effectively with Legacy Code…</strong>&#8220;<em><br />
</em></span></div>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares.&#8221;<br />
</span></li>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>Ron Jeffries, author of Extreme Programming Installed and Extreme Programming Adventures in C# &#8230;<em><br />
</em></strong></span></div>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;"><strong>&#8220;</strong>In recent years I begin, and nearly end, with Beck&#8217;s rules of simple code. In priority order, simple code:<br />
</span></p>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">• Runs all the tests;<br />
</span></p>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">• Contains no duplication;<br />
</span></p>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">• Expresses all the design ideas that are in the system.<br />
</span></p>
<p style="margin-left:21pt;"><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">• Minimizes the number of entities such as classes, methods, functions, and the like.&#8221;<br />
</span></p>
</li>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>Ward Cunningham, inventor of Wiki, inventor of Fit, co-inventor of eXtreme Programming. Motive force behind Design Patterns. Smalltalk and OO thought leader. The godfather of all those who care about code…<br />
</strong></span></div>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;"><strong>&#8220;</strong>You can call it beautiful code when the code also makes it look like the language was made for the problem.&#8221;<br />
</span></li>
<li>
<div><span style="color:#254061;font-family:Century Gothic;font-size:12pt;"><strong>Bjarne Stroustrup, inventor of C++ and author of The C++ Programming Language…</strong>&#8220;<em><br />
</em><br />
</span></div>
<p><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">I like my code to be elegant and efficient &#8220;.<br />
</span></li>
</ul>
</li>
<li><span style="font-family:Century Gothic;font-size:12pt;"><span style="color:#231f20;">Elegance, Efficiency,</span><br />
<span style="color:#231f20;">Simplicity, Clarity, Readability and Caring they all share in creating a <strong><span style="color:gray;">clean code</span>.</strong><em><br />
</em></span></span></li>
<li><span style="color:#231f20;font-family:Century Gothic;font-size:12pt;">Pragmatic Dave Thomas and Andy Hunt said this in a different way. They used the metaphor of broken windows&#8221; <em>A building with broken windows looks like nobody cares about it &#8220;. </em>So the next times you write a line of code remember you are an author writing for readers who will judge your effort.</span></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/omnianour.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/omnianour.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/omnianour.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=omnianour.wordpress.com&amp;blog=9984977&amp;post=3&amp;subd=omnianour&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://omnianour.wordpress.com/2009/10/17/introduction-to-clean-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d6514e885d5b53acafe11c5261d85ac7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">OmniaNour</media:title>
		</media:content>
	</item>
	</channel>
</rss>
