<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.planetoid.info/index.php?action=history&amp;feed=atom&amp;title=Coding_habits_to_avoid</id>
	<title>Coding habits to avoid - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.planetoid.info/index.php?action=history&amp;feed=atom&amp;title=Coding_habits_to_avoid"/>
	<link rel="alternate" type="text/html" href="https://wiki.planetoid.info/index.php?title=Coding_habits_to_avoid&amp;action=history"/>
	<updated>2026-05-11T16:40:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://wiki.planetoid.info/index.php?title=Coding_habits_to_avoid&amp;diff=26082&amp;oldid=prev</id>
		<title>Planetoid at 11:19, 5 November 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetoid.info/index.php?title=Coding_habits_to_avoid&amp;diff=26082&amp;oldid=prev"/>
		<updated>2025-11-05T11:19:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:19, 5 November 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* 避免使用過於籠統的變數名稱，例如 $data 或 $file_path 「這個 $data 裡面放的是什麼？」當變數名稱不夠明確時，三個月後連自己都會忘記當初的設計。使用具描述性的變數名稱，可以讓程式碼自我說明，減少日後維護的困擾。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* 避免使用過於籠統的變數名稱，例如 $data 或 $file_path 「這個 $data 裡面放的是什麼？」當變數名稱不夠明確時，三個月後連自己都會忘記當初的設計。使用具描述性的變數名稱，可以讓程式碼自我說明，減少日後維護的困擾。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** $data 可能代表任何資料，過一陣子就會忘記裡面存的是什麼內容。建議改成更具體的名稱，例如: (1) $user_data：使用者資料、(2) $order_list：訂單清單、(3)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** $data 可能代表任何資料，過一陣子就會忘記裡面存的是什麼內容。建議改成更具體的名稱，例如: (1) $user_data：使用者資料、(2) $order_list：訂單清單、(3) $product_info：產品資訊&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;$product_info：產品資訊&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** $file_path 建議改成能表達檔案用途的名稱，例如: (1) $config_file_path：設定檔路徑、(2) $upload_image_path：上傳圖片路徑&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** $file_path 建議改成能表達檔案用途的名稱，例如: (1) $config_file_path：設定檔路徑、(2) $upload_image_path：上傳圖片路徑&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Planetoid</name></author>
	</entry>
	<entry>
		<id>https://wiki.planetoid.info/index.php?title=Coding_habits_to_avoid&amp;diff=26080&amp;oldid=prev</id>
		<title>Planetoid: Created page with &quot;避免的 coding 習慣 * 避免使用簡化的的變數名稱，例如 $sd 或 $d 也許一開始還會記得，但是過一陣子就會忘記這是什麼  * 避免使用過於籠統的變數名稱，例如 $data 或 $file_path 「這個 $data 裡面放的是什麼？」當變數名稱不夠明確時，三個月後連自己都會忘記當初的設計。使用具描述性的變數名稱，可以讓程式碼自我說明，減少日後維護的困擾。  ** $data 可能代...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetoid.info/index.php?title=Coding_habits_to_avoid&amp;diff=26080&amp;oldid=prev"/>
		<updated>2025-11-05T11:18:33Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;避免的 coding 習慣 * 避免使用簡化的的變數名稱，例如 $sd 或 $d 也許一開始還會記得，但是過一陣子就會忘記這是什麼  * 避免使用過於籠統的變數名稱，例如 $data 或 $file_path 「這個 $data 裡面放的是什麼？」當變數名稱不夠明確時，三個月後連自己都會忘記當初的設計。使用具描述性的變數名稱，可以讓程式碼自我說明，減少日後維護的困擾。  ** $data 可能代...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;避免的 coding 習慣&lt;br /&gt;
* 避免使用簡化的的變數名稱，例如 $sd 或 $d 也許一開始還會記得，但是過一陣子就會忘記這是什麼&lt;br /&gt;
&lt;br /&gt;
* 避免使用過於籠統的變數名稱，例如 $data 或 $file_path 「這個 $data 裡面放的是什麼？」當變數名稱不夠明確時，三個月後連自己都會忘記當初的設計。使用具描述性的變數名稱，可以讓程式碼自我說明，減少日後維護的困擾。&lt;br /&gt;
&lt;br /&gt;
** $data 可能代表任何資料，過一陣子就會忘記裡面存的是什麼內容。建議改成更具體的名稱，例如: (1) $user_data：使用者資料、(2) $order_list：訂單清單、(3)&lt;br /&gt;
 $product_info：產品資訊&lt;br /&gt;
** $file_path 建議改成能表達檔案用途的名稱，例如: (1) $config_file_path：設定檔路徑、(2) $upload_image_path：上傳圖片路徑&lt;br /&gt;
&lt;br /&gt;
* 重複複製貼上的內容，但是內容可能常被其他使用者更改，導致內容更新困難，需要修改多處的程式碼&lt;br /&gt;
&lt;br /&gt;
* 絕對路徑或絕對網址寫死在程式碼內，導致日後移機或對外公開網站服務時，需要修改多處的程式碼&lt;br /&gt;
&lt;br /&gt;
** 存取檔案時將完整路徑，例如 {{kbd | key= &amp;lt;nowiki&amp;gt;D:/AppServ/www/abc.csv&amp;lt;/nowiki&amp;gt;}} 寫死在程式碼內。可以改成使用相對路徑，例如 {{kbd | key= &amp;lt;nowiki&amp;gt;__DIR__&amp;lt;/nowiki&amp;gt;}}&amp;lt;ref&amp;gt;[https://www.php.net/manual/en/language.constants.magic.php PHP: Magic constants - Manual]&amp;lt;/ref&amp;gt; 代表檔案所在的資料夾。&lt;br /&gt;
** 將測試網址 (127.0.0.1 或 localhost) 寫死在程式碼內&lt;br /&gt;
&lt;br /&gt;
* 容易閱讀的錯誤訊息:除了 500 Error ，如果可以讓使用者自行處理，建議改成容易閱讀的錯誤訊息。&lt;br /&gt;
&lt;br /&gt;
* 「你那邊不能跑嗎？可是在我這邊跑起來是沒問題的。」通常問題出在開發者與程式執行的環境不同，需要檢查是否程式版本環境、相依套件版本。如果是網頁程式，則需要進一步檢查瀏覽器的快取與擴充套件是否衝突。&lt;br /&gt;
&lt;br /&gt;
* 「昨天下班前明明還好的啊，怎麼今天我還沒動它就壞了。」使用 Docker 重新建立執行環境，進行測試。&lt;br /&gt;
&lt;br /&gt;
* 「程式一直找不到問題出在哪裡？」請搜尋單元測試。將複雜的資訊系統拆解成可測試的模組。&lt;br /&gt;
&lt;br /&gt;
* 「Bug 不知道問題原因在那裡，但是這一版改完就可以動了。」請搜尋單元測試。&lt;br /&gt;
&lt;br /&gt;
[[Category: Programming]]&lt;/div&gt;</summary>
		<author><name>Planetoid</name></author>
	</entry>
</feed>