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

惡搞嘻語言第五嘻:嘻函式

函式在嘻語言裡無所不在,例如printf就是一個函式,為標準函式之一,若沒提供一些積木的函式給開發者使用,那不就要開發者自行做積木嗎?
若要自行撰寫函式又要如何鑽寫呢?函式的定義如下:
傳回值型態 函數名稱(參數一型態 參數一名稱, 參數二型態 參數二名稱, ....)
{
變數宣告
程式碼
return 傳回值;
}

例如下面是y=x^2的函式:
intpower(int x) {
inty = x * x;
returny;
}

範例:

參考網址:


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

留言

這個網誌中的熱門文章