Code Maintenance & Programming Rules

 This guide outlines essential best practices spanning code style, architectural design, debugging, testing, performance, and portability—all aimed at reducing the long-term cognitive load of code maintenance. 🎨 1. Style Code is written for humans to read, and only incidentally for computers to execute. Variable Naming : Use descriptive names for global variables, and short names for local variables. Precision and Consistency : Use active names for functions (e.g., calculateTotal ). Above all, keep your coding style consistent throughout the project. Structure & Expressions : Use a consistent indentation and brace ( {} ) style to show program structure visually. Use the natural form for expressions. Use parentheses to make the semantics unambiguous. Break up overly complex expressions to keep them clear. Side Effects & Macros : Beware of functions with side effects. Avoid function-like macros; if unavoidable, parenthesize the macro body and arguments carefully. Magic Numbe...

Python IDLE Debugger

本部落格底下的幾篇文章:
介紹 Python 環境建立與基本操作,尚未介紹 Python 內建 IDLE 的除錯器(Debugger)如何使用。本篇文章就是要來說明如何使用 IDLE 中的 Debugger。

步驟一:開啟 IDLE

步驟二:開啟要除錯(Debug)的程式碼檔案

步驟三:開啟除錯器(Debugger)
從IDLE 的 Shell 視窗選單中的 [Debug ==> Debugger] 來開啟除錯器(Debugger)

會看到如下圖的視窗,也會在IDLE Shell 看到 [DEBUG ON]的文字。

步驟四:設定中斷點(Set Breakpoint)
在程式碼編輯視窗中,移到要設定中斷點的那一行程式碼,按下滑鼠右鍵,選擇 [Set Breakpoint]

有設定中斷點的那一行顏色會不一樣,例如下圖就有三行有設定中斷點:

步驟五:執行程式碼
在程式碼編輯視窗選單選擇[Run ==> Run Module] (或按下 F5 按鍵)

就會看到程式進入到除錯的模式了

步驟六:使用除錯器功能來進行除錯
在Debug Control視窗(見下圖),可看到[Go]、[Step]、[Over]、[Out]、[Quit]。

此五個按鈕功能說明如下:
[Go]:跳到下一個中斷點。
[Step]:一行一行執行。若有函式呼叫,則會進入到函式實作的程式碼裡。
[Over]:跳過(略過)函式呼叫。
[Out]:跳出(離開)函式。
[Quit]:結束除錯。

以上五個功能按鈕請讀者自行操作看看,親自體會功能上的不同。

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

留言

這個網誌中的熱門文章