web程序員應(yīng)該避免的五種代碼注釋是什么

本篇內(nèi)容主要講解“web程序員應(yīng)該避免的五種代碼注釋是什么”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“web程序員應(yīng)該避免的五種代碼注釋是什么”吧!

創(chuàng)新互聯(lián)公司業(yè)務(wù)包括:成品網(wǎng)站、企業(yè)產(chǎn)品展示型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、電子商務(wù)型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站制作(多語(yǔ)言)、成都商城網(wǎng)站開(kāi)發(fā)、定制網(wǎng)站、全網(wǎng)營(yíng)銷(xiāo)推廣等。效率優(yōu)先,品質(zhì)保證,用心服務(wù)是我們的核心價(jià)值觀,我們將繼續(xù)以良好的信譽(yù)為基礎(chǔ),秉承穩(wěn)固與發(fā)展、求實(shí)與創(chuàng)新的精神,為客戶(hù)提供更全面、更優(yōu)質(zhì)的互聯(lián)網(wǎng)服務(wù)!

1.自以為很了不得的程序員

public class Program {     static void Main(string[] args)     {         string message = "Hello World!";  // 07/24/2010 Bob         Console.WriteLine(message); // 07/24/2010 Bob         message = "I am so proud of this code!"; // 07/24/2010 Bob         Console.WriteLine(message); // 07/24/2010 Bob     } }

這個(gè)程序員自認(rèn)為寫(xiě)了一段很了不得的代碼,所以覺(jué)得有必要用自己的名字對(duì)每行代碼進(jìn)行標(biāo)記。實(shí)施版本控制系統(tǒng)(VCS)能實(shí)現(xiàn)對(duì)代碼變更的問(wèn)責(zé),但是也不會(huì)這么明顯知道誰(shuí)應(yīng)對(duì)此負(fù)責(zé)。

2.過(guò)時(shí)的程序員

public class Program {     static void Main(string[] args)     {         /* This block of code is no longer needed          * because we found out that Y2K was a hoax          * and our systems did not roll over to 1/1/1900 */         //DateTime today = DateTime.Today;         //if (today == new DateTime(1900, 1, 1))         //{         //    today = today.AddYears(100);         //    string message = "The date has been fixed for Y2K.";         //    Console.WriteLine(message);         //}     } }

如果一段代碼已不再使用(即過(guò)時(shí)),那就刪除它——不要浪費(fèi)時(shí)間給這些代碼寫(xiě)注釋。此外,如果你需要復(fù)制這段被刪除的代碼,別忘了還有版本控制系統(tǒng),你完全可以從早期的版本中恢復(fù)代碼。

3.多此一舉的程序員

public class Program {     static void Main(string[] args)     {         /* This is a for loop that prints the          * words "I Rule!" to the console screen          * 1 million times, each on its own line. It          * accomplishes this by starting at 0 and          * incrementing by 1. If the value of the          * counter equals 1 million the for loop          * stops executing.*/         for (int i = 0; i < 1000000; i++)         {             Console.WriteLine("I Rule!");         }     } }

我們都知道基礎(chǔ)的編程邏輯是如何工作的——所以你不需要多此一舉來(lái)解釋這些顯而易見(jiàn)的工作原理,雖然說(shuō)你解釋得很happy,但這只是在浪費(fèi)時(shí)間和空間。

4.愛(ài)講故事的程序員

public class Program {     static void Main(string[] args)     {        /* I discussed with Jim from Sales over coffee         * at the Starbucks on main street one day and he         * told me that Sales Reps receive commission         * based upon the following structure.         * Friday: 25%         * Wednesday: 15%         * All Other Days: 5%         * Did I mention that I ordered the Caramel Latte with         * a double shot of Espresso?        */         double price = 5.00;         double commissionRate;         double commission;         if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)         {             commissionRate = .25;         }         else if (DateTime.Today.DayOfWeek == DayOfWeek.Wednesday)         {             commissionRate = .15;         }         else         {             commissionRate = .05;         }         commission = price * commissionRate;     } }

如果你一定要在注釋里提及需求,那么不要涉及別人的名字。銷(xiāo)售部門(mén)的Jim可能會(huì)離開(kāi)公司,而且很有可能大多數(shù)程序員根本不知道這是何許人也。不要在注釋里提及不相干的事實(shí)。

5.“以后再做”的程序員

public class Program {     static void Main(string[] args)     {        //TODO: I need to fix this someday - 07/24/1995 Bob        /* I know this error message is hard coded and         * I am relying on a Contains function, but         * someday I will make this code print a         * meaningful error message and exit gracefully.         * I just don't have the time right now.        */        string message = "An error has occurred";        if(message.Contains("error"))        {            throw new Exception(message);        }     } }

這種類(lèi)型的注釋包含了上面所有其他類(lèi)型。如果是在項(xiàng)目的初始開(kāi)發(fā)階段,這種待做注釋是非常有用的,但如果是在幾年后的產(chǎn)品代碼——那就會(huì)出問(wèn)題了。如果有什么需要修復(fù)的,立馬解決,不要把它擱置一邊,“以后再做”。

到此,相信大家對(duì)“web程序員應(yīng)該避免的五種代碼注釋是什么”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!

當(dāng)前文章:web程序員應(yīng)該避免的五種代碼注釋是什么
本文URL:http://bm7419.com/article26/jjeccg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶(hù)體驗(yàn)云服務(wù)器、手機(jī)網(wǎng)站建設(shè)App開(kāi)發(fā)、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司