بنقرة واحدة
pow10-rule-06-minimum-scope
NASA Power of 10 Rule 6 — Declare data at smallest possible scope. Severity: medium.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
NASA Power of 10 Rule 6 — Declare data at smallest possible scope. Severity: medium.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
NASA Power of 10 Rule 1 — Restrict control flow to simple constructs (no goto, setjmp/longjmp, recursion). Severity: blocker.
NASA Power of 10 Rule 2 — Every loop must have a statically determinable upper bound. Severity: blocker.
NASA Power of 10 Rule 3 — No dynamic memory allocation after initialization. Severity: blocker.
NASA Power of 10 Rule 4 — Functions ≤60 lines (one printed page). Severity: high.
NASA Power of 10 Rule 5 — Average ≥2 runtime assertions per function. Severity: high.
NASA Power of 10 Rule 7 — Check every non-void return value; validate every parameter. Severity: blocker.
| name | pow10-rule-06-minimum-scope |
| description | NASA Power of 10 Rule 6 — Declare data at smallest possible scope. Severity: medium. |
Severity: medium
Variables declared at the narrowest scope where they are used. No mutable globals or file-scope statics. When unavoidable, mark them const or guard with documented access protocols.
Narrow scope makes data hiding explicit, simplifies debugging, prevents accidental cross-scope mutation, and helps the compiler optimize register allocation. Globals hide ownership and create implicit coupling.
static/var mutated from multiple functionscompanion object / static class fields with varEncapsulate state in an instance owned by a single object. Pass dependencies explicitly. Declare locals at the point of first use. Prefer immutable bindings (const/final/val) over mutable.
const/final/val)Mark them clearly:
// Configuration loaded at init; immutable thereafter.
var config = mustLoadConfig()