<?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>Vietnamese Developers' Blog &#187; General</title>
	<atom:link href="http://openandfree.wordpress.com/category/programming/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://openandfree.wordpress.com</link>
	<description>There are 10 types of people in the world: Those who know the binary system and those who don't</description>
	<lastBuildDate>Sat, 22 Nov 2008 00:47:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='openandfree.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/caa4770bbad32f97d95cfd98b414dfc1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Vietnamese Developers' Blog &#187; General</title>
		<link>http://openandfree.wordpress.com</link>
	</image>
			<item>
		<title>Programming Style (2)</title>
		<link>http://openandfree.wordpress.com/2007/10/29/programming-style-2/</link>
		<comments>http://openandfree.wordpress.com/2007/10/29/programming-style-2/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 08:06:50 +0000</pubDate>
		<dc:creator>kiennguyen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[idiom]]></category>
		<category><![CDATA[programming style]]></category>

		<guid isPermaLink="false">http://openandfree.wordpress.com/2007/10/29/programming-style-2/</guid>
		<description><![CDATA[Các idiom
Không biết dịch từ &#8220;idiom&#8221; thế nào cho chính xác. Tạm hiểu idiom là các chuẩn không bắt buộc nhưng được đa số người dùng tuân theo. Sử dụng các idiom giúp giảm bớt khả năng mắc lỗi đồng thời làm chương trình dễ đọc hơn và nhất là có vẻ “chuyên nghiệp” hơn [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=openandfree.wordpress.com&blog=1590880&post=27&subd=openandfree&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><font face="Arial"><strong>Các idiom</strong></font></h3>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Không biết dịch từ &#8220;idiom&#8221; thế nào cho chính xác. Tạm hiểu idiom là các chuẩn không bắt buộc nhưng được đa số người dùng tuân theo. Sử dụng các idiom giúp giảm bớt khả năng mắc lỗi đồng thời làm chương trình dễ đọc hơn và nhất là có vẻ “chuyên nghiệp” hơn <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  Sau đây là một số idiom phổ biến:</font></p>
<p><font face="Arial"><strong>Các idiom cho mảng</strong></font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Để duyệt qua n phần tử của một mảng và khởi tạo chúng, có các cách viết sau đây:</font></p>
<pre><font size="2"><tt>i <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
<strong><font color="#0000ff">while</font></strong> <font color="#990000">(</font> i <font color="#990000">&lt;=</font> n – <font color="#993399">1</font> <font color="#990000">)</font>
    array<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> <font color="#993399">1.0</font><font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">hoặc</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> i <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> n<font color="#990000">;</font> <font color="#990000">)</font>
    array<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font>  <font color="#993399">1.0</font><font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">hoặc</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> i <font color="#990000">=</font> n<font color="#990000">;</font> –i <font color="#990000">&gt;=</font> <font color="#993399">0</font><font color="#990000">;</font> <font color="#990000">)</font>
    array<font color="#990000">[</font> i <font color="#990000">]</font> <font color="#990000">=</font> <font color="#993399">1.0</font><font color="#990000">;</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Tất cả những cách viết trên đều đúng, tuy nhiên idioms cho trường hợp này là:</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> i <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> n<font color="#990000">;</font> i<font color="#990000">++</font> <font color="#990000">)</font>
    array<font color="#990000">[</font> i <font color="#990000">]</font> <font color="#990000">=</font> <font color="#993399">1.0</font><font color="#990000">;</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Idiom của vòng lặp duyệt qua các phần tử của một danh sách (list) là</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> p <font color="#990000">=</font> list<font color="#990000">;</font> p <font color="#990000">!=</font> NULL<font color="#990000">;</font> p <font color="#990000">=</font> p<font color="#990000">-&gt;</font>next <font color="#990000">)</font>
    <font color="#990000">...</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Đối với các vòng lặp vô hạn, idiom là</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong> <font color="#990000">(</font> <font color="#990000">;</font> <font color="#990000">;</font> <font color="#990000">)</font>
<font color="#990000">...</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">hoặc</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">while</font></strong><font color="#990000">(</font> <font color="#993399">1</font> <font color="#990000">)</font>
    <font color="#990000">...</font>
</tt></font></pre>
<p><font face="Arial"><strong>Các idiom cho xâu và kí tự</strong></font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Xem đoạn mã sau đây:</font></p>
<p><span id="more-27"></span></p>
<pre><font size="2"><tt><font color="#009900">char</font> <font color="#990000">*</font>p<font color="#990000">,</font> buf<font color="#990000">[</font> <font color="#993399">256</font> <font color="#990000">];</font> 

<strong><font color="#000000">gets</font></strong><font color="#990000">(</font> buf <font color="#990000">);</font>
p <font color="#990000">=</font> <strong><font color="#000000">malloc</font></strong><font color="#990000">(</font> <strong><font color="#000000">strlen</font></strong><font color="#990000">(</font> buf <font color="#990000">)</font> <font color="#990000">);</font>
<strong><font color="#000000">strcpy</font></strong><font color="#990000">(</font> p<font color="#990000">,</font> buf <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Đoạn mã trên sai ở chỗ: Hàm strlen không tính đến kí tự null ở cuối xâu, trong khi hàm strcpy vẫn sao chép kí tự null ở cuối xâu nguồn sang xâu đích. Kết quả là strcpy ghi kí tự null ra ngoài vùng nhớ được cấp phát cho p. Idiom cho trường hợp này là:</font></p>
<pre><font size="2"><tt>p <font color="#990000">=</font> <strong><font color="#000000">malloc</font></strong><font color="#990000">(</font> <strong><font color="#000000">strlen</font></strong><font color="#990000">(</font> buf <font color="#990000">)</font> <font color="#990000">+</font> <font color="#993399">1</font> <font color="#990000">);</font>
<strong><font color="#000000">strcpy</font></strong><font color="#990000">(</font> p<font color="#990000">,</font> buf <font color="#990000">);</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">hoặc trong C++</font></p>
<pre><font size="2"><tt>p <font color="#990000">=</font> <strong><font color="#0000ff">new</font></strong> <font color="#009900">char</font><font color="#990000">[</font> <strong><font color="#000000">strlen</font></strong><font color="#990000">(</font> buf <font color="#990000">)</font> <font color="#990000">+</font> <font color="#993399">1</font> <font color="#990000">];</font>
<strong><font color="#000000">strcpy</font></strong><font color="#990000">(</font> p<font color="#990000">,</font> buf <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Nếu trong một đoạn mã cấp phát bộ nhớ cho xâu mà bạn không nhìn thấy số 1, hãy kiểm tra lại! Java không gặp vấn đề này bởi xâu trong Java không được biểu diễn như các mảng kí tự kết thúc bởi null, hơn nữa các chỉ số của mảng cũng được kiểm tra.</font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Hầu hết các môi trường phát triển C và C++ đều cung cấp một hàm có tên là strdup. Hàm này sử dụng malloc và strcpy để tạo ra một bản sao của xâu, nhờ đó tránh được lỗi nói trên. Thật không may, strdup lại không phải là một hàm chuẩn của ANSI C.</font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Khi làm việc với các kí tự, hãy sử dụng các hằng kí tự thay vì các số nguyên. Ví dụ để kiểm tra xem c có phải một chữ cái hoa hay không, có thể dùng đoạn mã sau</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> c <font color="#990000">&gt;=</font> <font color="#993399">65</font> <font color="#990000">&amp;&amp;</font> c <font color="#990000">&lt;=</font> <font color="#993399">90</font> <font color="#990000">)</font>
    <font color="#990000">...</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Tuy nhiên đoạn mã này hoàn toàn phụ thuộc vào bộ mã biểu diễn kí tự đang được sử dụng. Cách tốt hơn là viết như sau:</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> c <font color="#990000">&gt;=</font> ‘A’ <font color="#990000">&amp;&amp;</font> c <font color="#990000">&lt;=</font> ‘Z’ <font color="#990000">)</font>
    <font color="#990000">...</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Tuy nhiên cách viết này cũng chưa chắc đã đúng nếu trong bảng mã kí tự đang được sử dụng, các chữ cái hoa không nằm cạnh nhau. Đối với những tình huống kiểu này, tốt nhất là sử dụng các hàm chuẩn</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <strong><font color="#000000">isupper</font></strong><font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">trong C và C++, hoặc</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> Character<font color="#990000">.</font><strong><font color="#000000">isUpperCase</font></strong><font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">trong Java.</font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial"><strong>Idiom cho lệnh if</strong></font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Tiếp theo là một idiom dành cho câu lệnh if. Hãy xem đoạn mã loằng ngoằng sau đây làm gì</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> argc<font color="#990000">==</font><font color="#993399">3</font> <font color="#990000">)</font>
    <strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> fin <font color="#990000">=</font> <strong><font color="#000000">fopen</font></strong><font color="#990000">(</font>argv<font color="#990000">[</font>l<font color="#990000">]</font> <font color="#990000">,</font> “r” <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">!=</font> NULL <font color="#990000">)</font>
        <strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> fout <font color="#990000">=</font> <strong><font color="#000000">fopen</font></strong><font color="#990000">(</font> argv<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">],</font> “w” <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">!=</font> NULL <font color="#990000">)</font> <font color="#ff0000">{</font> 

            <strong><font color="#0000ff">while</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> c <font color="#990000">=</font> <strong><font color="#000000">getc</font></strong><font color="#990000">(</font> fin <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">!=</font> EOF <font color="#990000">)</font>
                <strong><font color="#000000">putc</font></strong><font color="#990000">(</font> c<font color="#990000">,</font> fout <font color="#990000">);</font>
            <strong><font color="#000000">fclose</font></strong><font color="#990000">(</font> fin <font color="#990000">);</font>
            <strong><font color="#000000">fclose</font></strong><font color="#990000">(</font> fout <font color="#990000">);</font> 

        <font color="#ff0000">}</font> <strong><font color="#0000ff">else</font></strong>
            <strong><font color="#000000">printf </font></strong><font color="#990000">(</font> “Can’t open output file <font color="#990000">%</font>s<font color="#990000">\</font>n”<font color="#990000">,</font> argv<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">]</font> <font color="#990000">)</font> <font color="#990000">;</font>
    <strong><font color="#0000ff">else</font></strong>
        <strong><font color="#000000">printf</font></strong><font color="#990000">(</font> “Can’t open input file <font color="#990000">%</font>s<font color="#990000">\</font>n”<font color="#990000">,</font> argv<font color="#990000">[</font>l<font color="#990000">]</font> <font color="#990000">)</font> <font color="#990000">;</font>
<strong><font color="#0000ff">else</font></strong>
    <strong><font color="#000000">printf </font></strong><font color="#990000">(</font> “Usage<font color="#990000">:</font> cp input file outputfile<font color="#990000">\</font>n” <font color="#990000">)</font> <font color="#990000">;</font>
</tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Viết lại đoạn mã này theo đúng idiom như sau:</font></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> argc <font color="#990000">!=</font> <font color="#993399">3</font> <font color="#990000">)</font>
    <strong><font color="#000000">printf </font></strong><font color="#990000">(</font> “Usage<font color="#990000">:</font> cp input file outputfile<font color="#990000">\</font>n” <font color="#990000">)</font> <font color="#990000">;</font>
<strong><font color="#0000ff">else</font></strong> <strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> fin <font color="#990000">=</font> <strong><font color="#000000">fopen</font></strong><font color="#990000">(</font> argv<font color="#990000">[</font>l<font color="#990000">]</font> <font color="#990000">,</font> “r” <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">==</font> NULL <font color="#990000">)</font>
    <strong><font color="#000000">printf</font></strong><font color="#990000">(</font> “Can’t open input file <font color="#990000">%</font>s<font color="#990000">\</font>n”<font color="#990000">,</font> argv<font color="#990000">[</font>l<font color="#990000">]</font> <font color="#990000">);</font>
<strong><font color="#0000ff">else</font></strong> <strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> fout <font color="#990000">=</font> <strong><font color="#000000">fopen</font></strong><font color="#990000">(</font> argv<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">],</font> “w” <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">==</font> NULL <font color="#990000">)</font> <font color="#ff0000">{</font>
    <strong><font color="#000000">printf </font></strong><font color="#990000">(</font> “Can’t open output file <font color="#990000">%</font>s<font color="#990000">\</font>n”<font color="#990000">,</font> argv<font color="#990000">[</font><font color="#993399">2</font><font color="#990000">]</font> <font color="#990000">)</font> <font color="#990000">;</font>
    <strong><font color="#000000">fclose</font></strong><font color="#990000">(</font> fin <font color="#990000">)</font> <font color="#990000">;</font>
<font color="#ff0000">}</font> <strong><font color="#0000ff">else</font></strong> <font color="#ff0000">{</font>
    <strong><font color="#0000ff">while</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> c <font color="#990000">=</font> <strong><font color="#000000">getc</font></strong><font color="#990000">(</font> fin <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">!=</font> EOF<font color="#990000">)</font>
        <strong><font color="#000000">putc</font></strong><font color="#990000">(</font> c<font color="#990000">,</font> fout <font color="#990000">);</font>
    <strong><font color="#000000">fclose</font></strong><font color="#990000">(</font> fin <font color="#990000">)</font> <font color="#990000">;</font>
    <strong><font color="#000000">fclose</font></strong><font color="#990000">(</font> fout <font color="#990000">)</font> <font color="#990000">;</font>
<font color="#ff0000">}</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Nguyên tắc khi viết các lệnh if là: Đặt các phép toán kiểm tra điều kiện càng gần các hành động tương ứng càng tốt.</font></p>
<p><font face="Arial"><strong>Số 0 trong chương trình</strong></font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Số không thường xuyên xuất hiện trong các chương trình với nhiều ý nghĩa khác nhau. Trình dịch sẽ tự động chuyển số 0 thành kiểu thích hợp. Tuy nhiên nên viết ra một cách tường minh bản chất của số 0 mà chúng ta đang nói đến. Cụ thể, hãy sử dụng ( void* )0 hoặc NULL để biểu diễn con trỏ null trong C, sử dụng &#8216;\ 0&#8242; cho kí tự null ở cuối mỗi xâu và sử dụng 0.0 cho các số float hoặc double có giá trị không. Đừng viết đoạn mã như sau</font></p>
<pre><font size="2"><tt>p <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
name<font color="#990000">[</font> i <font color="#990000">]</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
x <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Hãy viết</font></p>
<pre><font size="2"><tt>p <font color="#990000">=</font> NULL<font color="#990000">;</font>
name<font color="#990000">[</font> i <font color="#990000">]</font> <font color="#990000">=</font> <font color="#ff0000">'</font><font color="#cc33cc">\ </font><font color="#ff0000">0'</font><font color="#990000">;</font>
x <font color="#990000">=</font> <font color="#993399">0.0</font><font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial">Số 0 nên để dành cho các số nguyên có giá trị bằng không. Tuy nhiên trong C++, 0 (thay vì NULL) lại được sử dụng rộng rãi cho các con trỏ null. Java định nghĩa hẳn từ khóa null cho các cho các object reference không tham chiếu đến cái gì cả.<span> </span></font></p>
<p style="text-align:justify;margin:0;" class="MsoNormal"><font face="Arial"><strong>Cuối cùng là các tài liệu tham khảo về Programming Style</strong></font></p>
<p style="text-indent:-0.25in;text-align:justify;margin:0 0 0 0.5in;" class="MsoNormal"><span><font face="Arial">1-<span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></font></span><font face="Arial"><a href="http://en.wikipedia.org/wiki/The_Elements_of_Style" title="The Elements of Style"><em>The Elements of Style</em> </a>by William Strunk and E.B White: Một cuốn sách tuyệt vời hướng dẫn cách viết tiếng Anh thế nào cho tốt. Hãy nhớ rằng viết mã tốt có nhiều điểm chung với viết tiếng Anh tốt.</font></p>
<p style="text-indent:-0.25in;text-align:justify;margin:0 0 0 0.5in;" class="MsoNormal"><span><font face="Arial">2-<span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></font></span><font face="Arial"><a href="http://en.wikipedia.org/wiki/The_Elements_of_Programming_Style_(book)" title="The Elements of Programming Style"><em>The Elements of Programming Style</em> </a>by Brian Kernighan and P.J. Plauger</font></p>
<p style="text-indent:-0.25in;text-align:justify;margin:0 0 0 0.5in;" class="MsoNormal"><span><font face="Arial">3-<span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></font></span><font face="Arial"><a href="http://safari.informit.com/0735619670" title="Code Complete"><em>Code Complete</em></a> by Steve McConnell</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/openandfree.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/openandfree.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/openandfree.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/openandfree.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/openandfree.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/openandfree.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/openandfree.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/openandfree.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/openandfree.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/openandfree.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/openandfree.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/openandfree.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=openandfree.wordpress.com&blog=1590880&post=27&subd=openandfree&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://openandfree.wordpress.com/2007/10/29/programming-style-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b7240ced9e7e663cff734d741f37158?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kiennguyen</media:title>
		</media:content>
	</item>
		<item>
		<title>Programming Style (1)</title>
		<link>http://openandfree.wordpress.com/2007/10/20/programming-style/</link>
		<comments>http://openandfree.wordpress.com/2007/10/20/programming-style/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 17:19:24 +0000</pubDate>
		<dc:creator>kiennguyen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[programming style]]></category>

		<guid isPermaLink="false">http://openandfree.wordpress.com/2007/10/20/programming-style/</guid>
		<description><![CDATA[Sau một thời gian ra trường và đi làm với công việc chính là lập trình, nhiều khi tôi nhìn lại thời đại học và giật mình vì thấy mình đã học lập trình một cách quá hời hợt. Có rất nhiều kiến thức cơ bản mà tôi đã không học (hay không được dạy?). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=openandfree.wordpress.com&blog=1590880&post=21&subd=openandfree&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Sau một thời gian ra trường và đi làm với công việc chính là lập trình, nhiều khi tôi nhìn lại thời đại học và giật mình vì thấy mình đã học lập trình một cách quá hời hợt. Có rất nhiều kiến thức cơ bản mà tôi đã không học (hay không được dạy?). Nhớ lại hồi năm thứ nhất học Pascal, chúng tôi được học các lệnh if the, while, for…với các ví dụ kiểu như tìm tất cả các ước số của một số nguyên, hay quản lí sắp xếp sinh viên…Đến năm thứ 3 học C, chúng tôi vẫn học từng ý lệnh với từng ý kiểu bài tập. Có quá nhiều những kiến thức vô cùng quan trọng mà các thầy không hề nhắc đến (chứ chưa nói gì đến dạy), chẳng hạn như: Phong cách lập trình (Programming Style), kĩ thuật gỡ lỗi (debug), kiểm thử (test), hiệu năng của chương trình (performance), tính khả chuyển (portable)…Đáng tiếc là sự tồn tại của những kiến thức này lại không hiển nhiên cho lắm để sinh viên có thể tự tìm sách để đọc.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Một trong những cuốn sách tuyệt vời viết về những chủ đề nói trên là cuốn <a href="http://www.informit.com/store/product.aspx?isbn=020161586X"><strong>“The practice of Programming”</strong></a> của <strong>Brian W. Kernighan và Rob Pike</strong> (tôi ước là mình biết đến cuốn sách này sớm hơn). Đây là một cuốn sách được “recommend” cho tất cả các lập trình viên của tất cả các ngôn ngữ lập trình. Trong bài viết này tôi muốn giới thiệu chương đầu tiên của cuốn sách với tiêu đề “Style”. Những chương tiếp theo tôi sẽ giới thiệu khi có thời gian, hoặc tốt nhất là mọi người tự tìm đọc bản tiếng Anh để hấp thu được toàn bộ sự sâu sắc của cuốn sách. <em>(Tôi có bản mềm của cuốn sách này, ai cần có thể PM)</em></span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><font size="4">Phong cách lập trình (programming style)</font></strong><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span></p>
<h2><strong><font size="3"><font size="3">Mở đầu</font></font></strong></h2>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Hãy xem đoạn mã sau đây:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> country <font color="#990000">==</font> SING <font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font> country <font color="#990000">==</font> BRNI <font color="#990000">)</font> <font color="#990000">||</font>
     <font color="#990000">(</font> country <font color="#990000">==</font> POL <font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font> country <font color="#990000">==</font> ITALY <font color="#990000">)</font> <font color="#990000">)</font> <font color="#ff0000">{</font>
    <em><font color="#9a1900">/*</font></em>
<em><font color="#9a1900">     * If the country is Singapore, Brunei or Poland</font></em>
<em><font color="#9a1900">     * then the current time is the answer time</font></em>
<em><font color="#9a1900">     * rather than the off hook time</font></em>
<em><font color="#9a1900">     * Reset answer time and set day of week</font></em>
<em><font color="#9a1900">     */</font></em>
    <font color="#990000">...</font>
<font color="#ff0000">}</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Đoạn mã trên được viết một cách rất đẹp đẽ, được comment cẩn thận và là một phần trong một chương trình chạy hoàn toàn đúng. Tuy nhiên đoạn mã này vẫn gây ra một chút băn khoăn cho người đọc: Những đất nước Singapore, Brunei, Poland và Italy có mối liên hệ gì với nhau? Tại sao Italy lại không được nói đến trong phần comment? Vì đoạn mã và phần comment có sự khác nhau nên một trong hai thứ phải sai mà cũng có thể là cả hai đều sai. Đoạn mã có nhiều khả năng đúng hơn vì nó đã được test; có thể phần comment đã không được cập nhật theo sự thay đổi của đoạn mã. Nếu là người bảo trì cho đoạn chương trình này, rất có thể bạn cần phải biết mối quan hệ giữa các quốc gia được nhắc đến.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Đoạn chương trình nói trên đại diện cho phần lớn các chương trình trong thực tế: Hầu hết chạy đúng nhưng vẫn cần phải cải tiến.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Mục đích của style là làm cho chương trình trở nên dễ đọc đối với người viết và những người khác, một style tốt là một phần thiết yếu của việc lập trình tốt. Viết một chương trình chạy đúng là chưa đủ bởi chương trình không chỉ để cho máy tính đọc mà còn để các lập trình viên khác đọc. Hơn nữa, một chương trình có style tốt luôn có nhiều khả năng chạy đúng hơn một chương trình có style tồi.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Vậy thế nào là một style tốt? Điều đó tùy thuộc vào quy định của từng công ty, tổ chức, dự án…Phần sau đây giới thiệu những style cơ bản nhất.</span></p>
<p><span id="more-21"></span></p>
<h3><font size="3"><strong>1.1 Cách đặt tên cho biến và hàm</strong></font></h3>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Tên của biến hay hàm “đánh dấu” cho biến/hàm đó và mang thông tin về mục đích của đối tượng mà nó mô tả. Tên phải mang thông tin, rõ ràng, dễ nhớ và tốt nhất là phải phát âm được. Tên biến phải phù hợp với phạm vi (scope) của biến đó, phạm vi của biến càng rộng thì tên biến càng phải mang nhiều thông tin.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 1: Đặt tên giàu tính mô tả cho các biến toàn cục và tên ngắn gọn cho các biến cục bộ.</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các biến toàn cục có thể được sử dụng trong toàn chương trình, bởi vậy cần đặt tên đủ dài và đủ ý nghĩa để nhắc nhở người đọc về ý nghĩa của chúng. Nên viết comment bên cạnh phần khai báo của biến toàn cục. Ví dụ:</span></p>
<pre><font size="2"><tt><font color="#009900">int</font> npending <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font> <em><font color="#9a1900">/* độ dài hiện thời của hàng đợi */</font></em></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các hàm, lớp hay cấu trúc toàn cục cũng cần có các tên giàu tính mô tả về vai trò của chúng trong chương trình.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Trái lại, các biến cục bộ chỉ cần các tên ngắn gọn. Đối với một biến cục bộ, chỉ cần đặt tên n hoặc npoints là đủ. Một tên đại loại như numberOfPoints là quá thừa! Theo thônglệ, các tên i và j được dành cho các chỉ số, p và q dành cho các con trỏ, s và t dành cho các xâu. Vì vậy, hoàn toàn không cần thiết để dùng các tên biết dài loằng ngoằng như sau:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong> <font color="#990000">(</font> theElementIndex <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
      theElementIndex <font color="#990000">&lt;</font> numberOfElement<font color="#990000">;</font>
      theElementIndex<font color="#990000">++</font> <font color="#990000">)</font>
    elementArray<font color="#990000">[</font> theElementIndex <font color="#990000">]</font> <font color="#990000">=</font> theElementIndex<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Vòng lặp này có thể viết lại như sau mà vẫn đảm bảo tính dễ hiểu:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> i <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font> i <font color="#990000">&lt;</font> nelems<font color="#990000">,</font> i<font color="#990000">++</font> <font color="#990000">)</font>
    elem<font color="#990000">[</font> i <font color="#990000">]</font> <font color="#990000">=</font> i<font color="#990000">;</font>
</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các lập trình viên thường có xu hướng sử dụng các tên biến dài bất kể ngữ cảnh. Đó là một sai lầm bởi sự rõ ràng thường đạt được nhờ sự ngắn gọn. Thông thường người ta dùng các tên bắt đầu hoặc kết thúc bởi chữ “p” cho các biến con trỏ (chẳng hạn nodep), các tên bắt đầu bằng chữ hoa cho biến toàn cục (chẳng hạn Globals) và tất cả chữ cái hoa cho các hằng số (chẳng hạn CONSTANTS).</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các namespace trong C++ và package trong Java góp phần làm rõ nghĩa của các tên mà không cần sử dụng các tên dài.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 2: Đặt tên một cách nhất quán</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các biến có liên quan phải được đặt các tên có liên quan, đồng thời phải làm nổi bật được sự khác nhau của chúng. Các tên trong lớp sau đây vừa quá dài vừa không hề nhất quán:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">class</font></strong> UserQueue <font color="#ff0000">{</font>
    <font color="#009900">int</font> noOfItemsInQ<font color="#990000">,</font> frontOfTheQueue<font color="#990000">,</font> queueCapacity<font color="#990000">;</font>
    <strong><font color="#0000ff">public</font></strong> <font color="#009900">int</font> <strong><font color="#000000">noOfUsersInQueue</font></strong><font color="#990000">()</font> <font color="#ff0000">{</font><font color="#990000">...</font><font color="#ff0000">}</font>
<font color="#ff0000">}</font><font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Thứ nhất, cùng một nội dung là queue nhưng được biểu diễn bởi ba dấu hiệu: Q, Queue và queue. Thứ hai, các biến và các hàm thành phần của lớp UserQueue chỉ có thể được sử dụng bởi các đối tượng của lớp này, do vậy viết</span></p>
<pre><font size="2"><tt>queue<font color="#990000">.</font>queueCapacity</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">hay</span></p>
<pre><font size="2"><tt>queue<font color="#990000">.</font><strong><font color="#000000">noOfUsersInQueue</font></strong><font color="#990000">()</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">rõ ràng là thừa. Chúng ta có thể viết lại lớp này với các tên mới như sau:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">class</font></strong> UserQueue <font color="#ff0000">{</font>
    <font color="#009900">int</font> nitems<font color="#990000">,</font> front<font color="#990000">,</font> capacity<font color="#990000">;</font>
    <strong><font color="#0000ff">public</font></strong> <font color="#009900">int</font> <strong><font color="#000000">nusers</font></strong><font color="#990000">()</font> <font color="#ff0000">{</font><font color="#990000">...</font><font color="#ff0000">}</font>
<font color="#ff0000">}</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Không chỉ bản thân đoạn mã định nghĩa lớp đó dễ hiểu hơn, mà những đoạn mã sử dụng lớp UserQueue cũng dễ hiểu hơn:</span></p>
<pre><font size="2"><tt>queue<font color="#990000">.</font>capacity<font color="#990000">++;</font>
n <font color="#990000">=</font> queue<font color="#990000">.</font><strong><font color="#000000">nusers</font></strong><font color="#990000">();</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Lớp UserQueue vẫn có thể cải tiến thêm, bởi nitems và nusers thực chất là cùng biểu diễn một khái niệm và do đó chỉ cần sử dụng một trong hai tên đó mà thôi.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 3: Đặt các tên “động” cho hàm</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Tên hàm nên là một động từ theo sau bởi một danh từ. Ví dụ:</span></p>
<pre><font size="2"><tt>now <font color="#990000">=</font> date<font color="#990000">.</font><strong><font color="#000000">getTime</font></strong><font color="#990000">();</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các hàm trả về giá trị boolean nên được đặt tên thể hiện giá trị mà nó trả về. Ví dụ:</span></p>
<pre><font size="2"><tt><strong><font color="#000000">isOctal</font></strong><font color="#990000">(</font> c <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">thì tốt hơn là</span></p>
<pre><font size="2"><tt><strong><font color="#000000">checkOctal</font></strong><font color="#990000">(</font> c <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">vì cách đặt tên thứ nhất cho biết ngay rằng hàm trả về giá trị true nếu c là một số octal và trả về false trong trường hợp ngược lại.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 4: Tên hàm phải phù hợp với chức năng</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Tên một hàm mô tả chức năng của hàm đó. Bởi vậy đặt tên hàm sai dễ dẫn đến việc hiểu sai chức năng của hàm. Ngược lại, một tên hàm đúng có thể giúp người đọc phát hiện ra các lỗi trong định nghĩa hàm. Dưới đây là một macro được đặt tên đúng nhưng định nghĩa lại sai:</span></p>
<pre><font size="2"><tt><strong><font color="#000080">#define</font></strong> <strong><font color="#000000">isoctal</font></strong><font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">(</font> <font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">&gt;=</font> ‘<font color="#993399">0</font>’ <font color="#990000">&amp;&amp;</font> <font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">&lt;=</font> ‘<font color="#993399">8</font>’ <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Trong trường hợp này, việc đặt tên đúng giúp chúng ta dễ dàng phát hiện ra lỗi sai. Định nghĩa đúng cho macro này phải là:</span></p>
<pre><font size="2"><tt><strong><font color="#000080">#define</font></strong> <strong><font color="#000000">isoctal</font></strong><font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">(</font> <font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">&gt;=</font> ‘<font color="#993399">0</font>’ <font color="#990000">&amp;&amp;</font> <font color="#990000">(</font> c <font color="#990000">)</font> <font color="#990000">&lt;=</font> ‘<font color="#993399">7</font>’ <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Sau đây là một hàm với các tên hoàn toàn mâu thuẫn với chức năng của nó:</span></p>
<pre><tt><strong><font color="#0000ff">public</font></strong> boolean <strong><font color="#000000">inTable</font></strong><font color="#990000">(</font> Object obj <font color="#990000">)</font>
<font color="#ff0000">{</font>
    <font color="#009900">int</font> j <font color="#990000">=</font> <strong><font color="#0000ff">this</font></strong><font color="#990000">.</font><strong><font color="#000000">getIndex</font></strong><font color="#990000">(</font> obj <font color="#990000">);</font>    <strong><font color="#0000ff">return</font></strong> <font color="#990000">(</font> j <font color="#990000">==</font> nTable <font color="#990000">);</font>
<font color="#ff0000">}</font>
</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Hàm getIndex trả về một giá trị trong đoạn 0 đến nTable – 1 nếu obj có mặt trong bảng và trả về nTable trong trường hợp ngược lại. Bởi vậy, hàm inTable sẽ trả về true khi j == nTable, tức là khi obj không có mặt trong bảng. Rõ ràng điều này hoàn toàn mâu thuẫn với tên hàm. Những sai làm kiểu này sẽ gây nên rắc rối lớn khi chương trình được bảo trì, phát triển bởi các lập trình viên khác trong tương lai.</span></p>
<h3><font size="3"><strong>1.2: Biểu thức và lệnh</strong></font></h3>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Cũng giống như việc đặt tên cho hàm và biến, chúng ta cần viết các biểu thức và câu lệnh càng dễ hiểu càng tốt. Nên nhớ rằng các chương trình do bạn viết ra không chỉ để cho bạn đọc mà còn dành cho nhiều người khác đọc nữa.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 1: Viết các lệnh “thò ra thụt vào” (indent) để nêu bật cấu trúc của chương trình</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Xem vòng lặp sau đây:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font>n<font color="#990000">++;</font>n<font color="#990000">&lt;</font><font color="#993399">100</font><font color="#990000">;</font>field<font color="#990000">[</font>n<font color="#990000">++]=</font>’’<font color="#990000">);</font>
<font color="#990000">*</font>i <font color="#990000">=</font> ‘’<font color="#990000">;</font>
<strong><font color="#0000ff">return</font></strong><font color="#990000">(</font> ‘<font color="#990000">\</font>n’<font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Định dạng lại ta có đoạn mã tốt hơn sau đây</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font>n<font color="#990000">++,</font> n <font color="#990000">&lt;</font> <font color="#993399">100</font><font color="#990000">;</font> field<font color="#990000">[</font>n<font color="#990000">++]</font> <font color="#990000">=</font> ‘’ <font color="#990000">)</font>
    <font color="#990000">;</font>
<font color="#990000">*</font>i <font color="#990000">=</font> ‘’<font color="#990000">;</font>
<strong><font color="#0000ff">return</font></strong><font color="#990000">(</font> ‘<font color="#990000">\</font>n’<font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chúng ta còn thu được đoạn mã tốt hơn nữa khi sau khi đưa phép gán vào trong thân vòng lặp và tách lệnh tăng n ra:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">for</font></strong><font color="#990000">(</font> n<font color="#990000">++;</font> n <font color="#990000">&lt;</font> <font color="#993399">100</font><font color="#990000">;</font> n<font color="#990000">++</font> <font color="#990000">)</font>
    field<font color="#990000">[</font> n <font color="#990000">]</font> <font color="#990000">=</font> ‘’<font color="#990000">;</font>
<font color="#990000">*</font>i <font color="#990000">=</font> ‘’<font color="#990000">;</font>
<strong><font color="#0000ff">return</font></strong> ‘n’<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 2: Viết các biểu thức ở dạng “tự nhiên”</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Hãy viết các biểu thức ở dạng mà chúng ta nói về chúng. Ví dụ đoạn mã sau đây khá khó hiểu:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">!</font> <font color="#990000">(</font> block_id <font color="#990000">&lt;</font> actblks <font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">!</font> <font color="#990000">(</font> block_id <font color="#990000">&gt;=</font> unblocks <font color="#990000">)</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Biến đổi tương đương chúng ta có đoạn mã “tự nhiên” hơn sau đây:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> <font color="#990000">(</font> block_id <font color="#990000">&gt;=</font> actblks <font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font> blockId <font color="#990000">&lt;</font> unblocks <font color="#990000">)</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 3: Sử dụng cặp dấu ngoặc (,) để tránh nhập nhằng về thứ tự thực hiện của các toán tử</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Vì phép toán logic có độ ưu tiên cao hơn phép gán nên cần sử dụng dấu ngoặc cho hầu hết các biểu thức có mặt chúng đồng thời:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">while</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> c <font color="#990000">==</font> <strong><font color="#000000">getchar</font></strong><font color="#990000">()</font> <font color="#990000">)</font> <font color="#990000">!=</font> EOF <font color="#990000">)</font>
    <font color="#990000">...</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các toán tử thao tác bit &amp; và | có mức ưu tiên thấp hơn các toán tử so sánh như == nên khi nhìn thấy biểu thức</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> x <font color="#990000">&amp;</font> MASK <font color="#990000">==</font> BITS <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">thì thực tế thứ tự thực hiện là</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> x <font color="#990000">&amp;</font> <font color="#990000">(</font> MASK <font color="#990000">==</font> BITS <font color="#990000">)</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chắc hẳn đây không phải là chủ định của lập trình viên viết biểu thức này.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chúng ta nên sử dụng các dấu ngoặc kể cả khi không bắt buộc. Hãy so sánh hai cách viết sau đây xem cách nào tốt hơn:</span></p>
<pre><font size="2"><tt>leap_year <font color="#990000">=</font> y <font color="#990000">%</font> <font color="#993399">4</font> <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">&amp;&amp;</font> y <font color="#990000">%</font> <font color="#993399">100</font> <font color="#990000">!=</font> <font color="#993399">0</font> <font color="#990000">||</font> y <font color="#990000">%</font> <font color="#993399">400</font> <font color="#990000">==</font> <font color="#993399">0</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">và</span></p>
<pre><font size="2"><tt>leap_year <font color="#990000">=</font> <font color="#990000">(</font> <font color="#990000">(</font> y<font color="#990000">%</font><font color="#993399">4</font> <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">)</font> <font color="#990000">&amp;&amp;</font> <font color="#990000">(</font> y<font color="#990000">%</font><font color="#993399">100</font> <font color="#990000">!=</font> <font color="#993399">0</font> <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font> y<font color="#990000">%</font><font color="#993399">400</font> <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chú ý rằng các dấu cách xung quanh các toán tử % đã được bỏ đi nhằm thể hiển rõ hơn cấu trúc của biểu thức.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 4: Tách các biểu thức phức tạp thành các biểu thức đơn giản hơn</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Biểu thức sau đây rất ngắn gọn nhưng lại chứa quá nhiều phép toán:</span></p>
<pre><font size="2"><tt><font color="#990000">*</font>x <font color="#990000">+=</font> <font color="#990000">(</font> <font color="#990000">*</font>xp <font color="#990000">=</font> <font color="#990000">(</font> <font color="#993399">2</font><font color="#990000">*</font>k <font color="#990000">&lt;</font> <font color="#990000">(</font> n – m <font color="#990000">)</font> <font color="#990000">?</font> c<font color="#990000">[</font> k <font color="#990000">+</font> <font color="#993399">1</font> <font color="#990000">]</font> <font color="#990000">:</font> d<font color="#990000">[</font> k — <font color="#990000">]</font> <font color="#990000">)</font> <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chúng ta nên viết lại như sau:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> <font color="#993399">2</font><font color="#990000">*</font>k <font color="#990000">&lt;</font> n – m <font color="#990000">)</font>
    <font color="#990000">*</font>xp <font color="#990000">=</font> c<font color="#990000">[</font> k <font color="#990000">+</font> <font color="#993399">1</font> <font color="#990000">];</font>
<strong><font color="#0000ff">else</font></strong>
    <font color="#990000">*</font>xp <font color="#990000">=</font> d<font color="#990000">[</font> k– <font color="#990000">];</font>
<font color="#990000">*</font>x <font color="#990000">+=</font> <font color="#990000">*</font>xp<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 5: Viết các lệnh dễ hiểu, không viết các lệnh “khôn ngoan”</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các lập trình viên thường thích viết các lệnh càng ngắn gọn càng tốt. Tuy nhiên điều này thường gây phiền toái cho người khác. Hãy xem biểu thức sau đây làm gì:</span></p>
<pre><font size="2"><tt>subkey <font color="#990000">=</font> subkey <font color="#990000">&gt;&gt;</font> <font color="#990000">(</font> bitoff – <font color="#990000">(</font> <font color="#990000">(</font> bitoff <font color="#990000">&gt;&gt;</font> <font color="#993399">3</font> <font color="#990000">)</font> <font color="#990000">&lt;&lt;</font> <font color="#993399">3</font> <font color="#990000">)</font> <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Biểu thức trong cùng ( bitoff &gt;&gt; 3 ) dịch phải bitoff 3 bit. Kết quả thu được lại được dịch trái 3 bit. Bởi vậy 3 bit cuối cùng của bitoff được thay thế bởi các số 0. Kết quả này lại được trừ đi bởi giá trị ban đầu của bitoff, kết quả của phép trừ chính là 3 bit cuối cùng trong giá trị ban đầu của bitoff. Ba bit này được dùng để dịch subkey sang phải.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Bởi vậy, biểu thức nói trên tương đương với biểu thức sau đây:</span></p>
<pre><font size="2"><tt>subkeu <font color="#990000">=</font> subkey <font color="#990000">&gt;&gt;</font> <font color="#990000">(</font> bitoff <font color="#990000">&amp;</font> <font color="#993399">0</font>×<font color="#993399">7</font> <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Rõ ràng cách viết thứ hai dễ hiểu hơn nhiều. Một ví dụ khác về cách viết biểu thức ngắn gọn nhưng làm phức tạp hóa vấn đề:</span></p>
<pre><font size="2"><tt>child <font color="#990000">=</font> <font color="#990000">(</font> <font color="#990000">!</font> LC <font color="#990000">&amp;&amp;</font> <font color="#990000">!</font> RC <font color="#990000">)</font> <font color="#990000">?</font> <font color="#993399">0</font> <font color="#990000">:</font> <font color="#990000">(</font> <font color="#990000">!</font> LC <font color="#990000">?</font> RC <font color="#990000">:</font> LC <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Cách viết dưới đây dài hơn, nhưng dễ hiểu hơn nhiều:</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> LC <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">&amp;&amp;</font> RC <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">)</font>
    child <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
<strong><font color="#0000ff">else</font></strong> <strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> LC <font color="#990000">==</font> <font color="#993399">0</font> <font color="#990000">)</font>
    child <font color="#990000">=</font> RC<font color="#990000">;</font>
<strong><font color="#0000ff">else</font></strong>
    child <font color="#990000">=</font> LC<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Toán tử ?: chỉ thích hợp cho những biểu thức ngắn kiểu như sau đây:</span></p>
<pre><font size="2"><tt>max <font color="#990000">=</font> <font color="#990000">(</font> a <font color="#990000">&gt;</font> b <font color="#990000">)</font> <font color="#990000">?</font> a <font color="#990000">:</font> b<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">hoặc</span></p>
<pre><font size="2"><tt><strong><font color="#000000">printf</font></strong><font color="#990000">(</font> “The list has <font color="#990000">%</font>d item<font color="#990000">%</font>s<font color="#990000">\</font>n”<font color="#990000">,</font> n<font color="#990000">,</font> n <font color="#990000">==</font> <font color="#993399">1</font> <font color="#990000">?</font> “” <font color="#990000">:</font> “s” <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Hãy nhớ rằng mục tiêu của chúng ta là viết những đoạn mã dễ hiểu, chứ không phải các đoạn mã ngắn gọn.</span></p>
<p style="text-align:justify;" class="MsoNormal"><strong><span style="font-size:10pt;font-family:Arial;">Quy tắc 6: Cẩn thận với hiệu ứng lề (side effect)</span></strong></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Toán tử ++ gây ra hiệu ứng lề: Bên cạnh việc trả về giá trị của biến, nó còn tăng giá trị của biến thêm 1 đơn vị. Điều này có thể rất tiện lợi trong nhiều trường hợp, song cũng có thể gây ra rất nhiều phiền toái. Vấn đề nằm ở chỗ việc lấy ra giá trị và việc tăng giá trị của biến có thể không xảy ra cùng lúc. Trong C và C++, thứ tự thực hiện của các hiệu ứng lề là không được định nghĩa. Vì vậy câu lệnh sau đây có thể cho kết quả sai:</span></p>
<pre><font size="2"><tt>str<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> str<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> ‘ ‘<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chủ định của người viết là thêm hai dấu cách vào hai vị trí tiếp theo của xâu str. Tuy nhiên, tùy thuộc vào thời điểm chỉ số i được cập nhật mà sau khi thực hiện lệnh có một hoặc hai dấu cách được thêm vào xâu str cũng như i được tăng lên một hay hai đơn vị. Tốt nhất nên tách lệnh trên thành hai lệnh:</span></p>
<pre><font size="2"><tt>str<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> ‘ ‘<font color="#990000">;</font>
str<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> ‘ ‘<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Tương tự, lệnh sau đây có thể cho nhiều kết quả khác nhau:</span></p>
<pre><font size="2"><tt>array<font color="#990000">[</font> i<font color="#990000">++</font> <font color="#990000">]</font> <font color="#990000">=</font> i<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Nếu giá trị ban đầu của i là 3, phần tử array[ 4 ] có thể nhận giá trị 3 hoặc 4.</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Các thao tác vào/ra dữ liệu cũng thường gây ra hiệu ứng lề. Lệnh sau đây cố gắng đọc hai giá trị số có liên quan từ thiết bị nhập chuẩn:</span></p>
<pre><font size="2"><tt><strong><font color="#000000">scanf</font></strong><font color="#990000">(</font> “ <font color="#990000">%</font>d <font color="#990000">%</font>d”<font color="#990000">,</font> <font color="#990000">&amp;</font>yr<font color="#990000">,</font> <font color="#990000">&amp;</font>profit<font color="#990000">[</font> yr <font color="#990000">]</font> <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Chủ định của người viết là sử dụng giá trị mới của yr trong profit[ yr ]. Tuy nhiên, câu lệnh này sai ở chỗ: Một phần của lệnh thay đổi giá trị của yr trong khi một phần khác lại sử dụng giá trị đó. Nhớ rằng tất cả các tham số của scanf đều được tính toán trước khi scanf thực sự được gọi. Bởi vậy giá trị của yr trong profit[ yr ] luôn là giá trị cũ. Để sửa lỗi này, như thường lệ, hãy viết lại lệnh trên thành hai lệnh dưới đây:</span></p>
<pre><font size="2"><tt><strong><font color="#000000">scanf</font></strong><font color="#990000">(</font> “<font color="#990000">%</font>d”<font color="#990000">,</font> <font color="#990000">&amp;</font>yr <font color="#990000">);</font>
<strong><font color="#000000">scanf</font></strong><font color="#990000">(</font> “<font color="#990000">%</font>d”<font color="#990000">,</font> <font color="#990000">&amp;</font>profit<font color="#990000">[</font> yr <font color="#990000">]</font> <font color="#990000">);</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Sau đây là một số bài tập cho phần 1.1 và 1.2</span></p>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">1 &#8211; Đánh giá cách đặt tên của đoạn mã sau đây:</span></p>
<pre><font size="2"><tt><strong><font color="#000080">#define</font></strong> TRUE    <font color="#993399">0</font>
<strong><font color="#000080">#define</font></strong> FALSE   <font color="#993399">1</font>
<strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> <font color="#990000">(</font> ch <font color="#990000">=</font> <strong><font color="#000000">getchar</font></strong><font color="#990000">()</font> <font color="#990000">)</font> <font color="#990000">==</font> EOF <font color="#990000">)</font>
    not_eof <font color="#990000">=</font> FALSE<font color="#990000">;</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">2-Cải tiến hàm sau đây</span></p>
<pre><font size="2"><tt><font color="#009900">int</font> <strong><font color="#000000">smaller</font></strong><font color="#990000">(</font> char <font color="#990000">*</font>s<font color="#990000">,</font> <font color="#009900">char</font> <font color="#990000">*</font>t <font color="#990000">)</font> <font color="#ff0000">{</font>
    <strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> <strong><font color="#000000">strcmp</font></strong><font color="#990000">(</font> s<font color="#990000">,</font> t <font color="#990000">)</font> <font color="#990000">&lt;</font> <font color="#993399">1</font> <font color="#990000">)</font>
        <strong><font color="#0000ff">return</font></strong> <font color="#993399">1</font><font color="#990000">;</font>
    <strong><font color="#0000ff">else</font></strong>
        <strong><font color="#0000ff">return</font></strong> <font color="#993399">0</font><font color="#990000">;</font>
<font color="#ff0000">}</font>
</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">3-Thử đọc to đoạn mã này lên</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong> <font color="#990000">(</font> <font color="#990000">(</font> <strong><font color="#000000">falloc</font></strong><font color="#990000">(</font> SMRHSHSCRTCH<font color="#990000">,</font> S_IFEXT<font color="#990000">|</font><font color="#993399">0644</font><font color="#990000">,</font> MAXRCDDHSH <font color="#990000">)</font> <font color="#990000">)</font> <font color="#990000">&lt;</font> <font color="#993399">0</font> <font color="#990000">)</font></tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">4-Cải tiến những đoạn mã sau</span></p>
<pre><font size="2"><tt><strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> <font color="#990000">!</font> <font color="#990000">(</font> c <font color="#990000">==</font> ‘y’  <font color="#990000">||</font> c <font color="#990000">==</font> ‘Y’ <font color="#990000">)</font> <font color="#990000">)</font>
    <strong><font color="#0000ff">return</font></strong><font color="#990000">;</font>length <font color="#990000">=</font> <font color="#990000">(</font> length <font color="#990000">&lt;</font> BUFSIZE <font color="#990000">)</font> <font color="#990000">?</font> length <font color="#990000">:</font> BUFSIZE
flag <font color="#990000">=</font> flag <font color="#990000">?</font> <font color="#993399">0</font> <font color="#990000">:</font> <font color="#993399">1</font><font color="#990000">;</font>
quote <font color="#990000">=</font> <font color="#990000">(</font> <font color="#990000">*</font>line <font color="#990000">==</font> ‘”’ <font color="#990000">)</font> <font color="#990000">?</font> <font color="#993399">1</font> <font color="#990000">:</font> <font color="#993399">0</font><font color="#990000">;</font>
<strong><font color="#0000ff">if</font></strong><font color="#990000">(</font> val <font color="#990000">&amp;</font> <font color="#993399">1</font> <font color="#990000">)</font>
    it <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">;</font>
<strong><font color="#0000ff">else</font></strong>
    it <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">5-Đoạn mã sau sai ở đâu</span></p>
<pre><font size="2"><tt><font color="#009900">int</font> <strong><font color="#000000">read</font></strong><font color="#990000">(</font> <font color="#009900">int</font> <font color="#990000">*</font>ip <font color="#990000">)</font> <font color="#ff0000">{</font>
    <strong><font color="#000000">canf</font></strong><font color="#990000">(</font> “<font color="#990000">%</font>d”<font color="#990000">,</font> ip <font color="#990000">);</font>
    eturn <font color="#990000">*</font>ip<font color="#990000">;</font>
<font color="#ff0000">}</font><font color="#990000">...</font>
<strong><font color="#000000">insert</font></strong><font color="#990000">(</font> <font color="#990000">&amp;</font>graph<font color="#990000">[</font> vert <font color="#990000">],</font> <strong><font color="#000000">read</font></strong><font color="#990000">(</font> <font color="#990000">&amp;</font>val <font color="#990000">),</font> <strong><font color="#000000">read</font></strong><font color="#990000">(</font> <font color="#990000">&amp;</font>ch <font color="#990000">)</font> <font color="#990000">);</font>
</tt></font></pre>
<p style="text-align:justify;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">6-Liệt kê tất cả các kết quả có thể có của lệnh sau (hãy thử trên thật nhiều trình dịch)</span></p>
<pre><font size="2"><tt>n <font color="#990000">=</font> <font color="#993399">1</font><font color="#990000">;</font><strong><font color="#000000">printf</font></strong><font color="#990000">(</font> “<font color="#990000">%</font>d <font color="#990000">%</font>d<font color="#990000">\</font>n”<font color="#990000">,</font> n<font color="#990000">++,</font> n<font color="#990000">++</font> <font color="#990000">);</font>
</tt></font></pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/openandfree.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/openandfree.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/openandfree.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/openandfree.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/openandfree.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/openandfree.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/openandfree.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/openandfree.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/openandfree.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/openandfree.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/openandfree.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/openandfree.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=openandfree.wordpress.com&blog=1590880&post=21&subd=openandfree&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://openandfree.wordpress.com/2007/10/20/programming-style/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b7240ced9e7e663cff734d741f37158?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kiennguyen</media:title>
		</media:content>
	</item>
	</channel>
</rss>