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...

<輕鬆的運算思維>一文閱讀心得

此文為閱讀 <輕鬆的運算思維> 一文的心得。

運算思維可以融入其他科目中,例如數學或國文。因為「預測與邏輯判斷」是運算思維的核心之一。

舉例來說,我們要用電腦來判斷兩個數字大小時,流程可能如下(以中文表示):
請輸入第一個數字。
請輸入第二個數字。
如果 第一個數字
大於 第二個數字 時
    顯示 【第一個數字比第二個數字大】
否則
    顯示 【第二個數字比第一個數字大】
可使用 Scratch 來完成:

將積木換成英文版:


也可以 Python 來達成:



最後以 C 程式語言當結尾:

簡言之,若不考慮用哪種程式語言時,可以用中文的句子來描述並訓練一些邏輯概念,邏輯有了之後,利用 Blockly 相關工具(例如陳會安的ArduBlockly中文離線版、Blockly的範例程式CodeEditor)來熟悉一些邏輯觀念與程式語言語法之間的轉換,最後再開始學習程式語言的語法(筆者就是曾經深受程式語言的語法所困擾)。數學的例子可參考第一式:必殺-剪刀石頭布

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

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

留言

這個網誌中的熱門文章