編寫高質量可維護的代碼:一目瞭然的註釋

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"前言"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"有一些人認爲,好的代碼是自我解釋的。合適的命名和優秀的代碼的確可以減輕開發人員閱讀代碼的工作量,對於不是特別複雜的代碼可能確實可以做到自我解釋。但並不是所有場景都可以做到這一點,我們一起來了解一下“註釋”吧。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"編程語言中對“註釋”的解釋"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"註釋就是對代碼的解釋和說明。註釋是開發人員在編寫程序時,給一段代碼的解釋或提示,有助於提高程序代碼的可讀性。註釋不會被計算機編譯。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"要不要加註釋?爲什麼要加註釋?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"註釋的存在就是爲了方便自己的二次閱讀和代碼維護以及項目交接。可以更好的理解代碼,有助於提高協作效率,加快開發進程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"試想,你添加了一段邏輯較爲複雜的代碼,幾個月後再看,還能不能迅速看懂?你剛剛接手一個老項目,項目裏基本沒有註釋且邏輯複雜,你能高效率的看懂代碼和了解業務嗎?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所以添加註釋還是有一定必要滴。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"基礎篇"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"快捷鍵  windows:"},{"type":"codeinline","content":[{"type":"text","text":"ctrl+\/"}]},{"type":"text","text":"   mac: "},{"type":"codeinline","content":[{"type":"text","text":"command+\/"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"註釋的分類"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一、 HTML 中的註釋"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"
\n  這是一行文字\n  \n\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"二、CSS 中的註釋"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 .html 文件中"}]}]}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章