Nasa inspired coding rules

From mouadja02/skills · View interactive version

Nasa inspired coding rules is an AI agent skill from the GitHub repository mouadja02/skills. Use when writing, reviewing, or refactoring production code where reliability, portability, maintainability, explicit contracts, resource safety, and cross-language coding standards matter across Python, TS/JS, C, C++, Rust, or Go.

How to use this skill

Skill file

NASA-Inspired Coding Rules

Use these rules to make code harder to break and easier to maintain. They are generalized from NASA Glenn Research Center's NPARC Alliance programming guideline for Fortran 90:

https://www.grc.nasa.gov/www/winddocs/guidelines/pgmstds.pdf

Source note: the linked document is language-specific and Fortran-oriented. Apply the practices, not the syntax. Do not present this skill as an official NASA standard for every language.

Priority Order

When rules compete, optimize in this order:

  1. Maintainability: another engineer can understand, modify, and extend it.
  2. Portability: it behaves consistently across supported platforms, runtimes, compilers, and dependency versions.
  3. Efficiency: it uses CPU, memory, IO, and network resources responsibly after correctness is protected.

Do not trade maintainability for clever speed unless profiling proves it is necessary and tests protect the behavior.

Core Rules

1. Stay Inside Standard, Supported Language Features

Language cues:

| Language | Prefer | Avoid unless isolated |

| --- | --- | --- |

| Python | Current stable syntax, typing, stdlib protocols | Runtime monkey-patching, broad metaclass tricks |

| TS/JS | Strict TypeScript, standard Web/Node APIs | any, prototype mutation, nonstandard globals |

| C | C11/C17-compatible code per project policy | Compiler-only extensions in shared logic |

| C++ | Modern standard C++, RAII, standard containers | Raw ownership, preprocessor-heavy logic |

| Rust | Safe Rust, explicit feature flags | unsafe without a narrow proof and tests |

| Go | Standard library conventions, go vet clean code | Build tags that hide divergent behavior |

2. Organize by Purpose and Keep Modules Small

Good modules can be tested in isolation and explained in one sentence.

3. Make Types, Shapes, and Interfaces Explicit

Language cues:

| Language | Contract tools |

| --- | --- |

| Python | Type hints, dataclasses, Pydantic or validators at IO boundaries |

| TS/JS | strict, discriminated unions, runtime validation for external data |

| C | Header declarations, fixed-width types, explicit casts, const |

| C++ | const, references, RAII types, concepts or static assertions when useful |

| Rust | Strong domain types, Result, Option, traits with clear bounds |

| Go | Small interfaces, struct tags used deliberately, explicit error returns |

4. Control Ownership, Memory, and Resources

Review question: "What owns this, and when is it released?"

5. Keep Functions Boring, Single-Entry, and Side-Effect-Aware

Functions should be easy to test without constructing the whole system.

6. Make Control Flow Obvious

If a reader has to simulate the control flow to understand it, simplify.

7. Handle Input, Output, and Errors Deliberately

Language cues:

| Language | Error discipline |

| --- | --- |

| Python | Catch narrow exceptions; use context-rich errors; avoid bare except |

| TS/JS | Handle rejected promises; validate unknown JSON before trust |

| C | Check return codes; define ownership on error paths |

| C++ | Define exception policy; keep destructors safe; avoid partial states |

| Rust | Use ? with contextual errors; reserve panic! for invariants |

| Go | Check err; wrap with context; avoid swallowing errors |

8. Prefer Readable Formatting and Naming

Readable code should make domain intent visible before implementation mechanics.

9. Comment Intent, Constraints, and Surprises

A good comment prevents a future "cleanup" from reintroducing the bug.

10. Compile, Analyze, and Test With Production-Like Settings

Minimum tool expectations:

| Language | Baseline checks |

| --- | --- |

| Python | tests, type checker if used, linter/formatter |

| TS/JS | tests, tsc --noEmit, linter/formatter |

| C | compiler warnings, tests, sanitizer or static analysis for risky code |

| C++ | compiler warnings, tests, sanitizer or static analysis for risky code |

| Rust | cargo test, cargo clippy, cargo fmt |

| Go | go test, go vet, gofmt |

Review Checklist

Use this checklist before merging reliability-sensitive code:

Common Mistakes

| Mistake | Safer practice |

| --- | --- |

| "This helper is small, so hidden global state is fine." | Pass dependencies explicitly until a real lifecycle owner emerges. |

| "The type checker knows enough." | Validate untrusted runtime data before converting it into trusted types. |

| "The test passed in debug mode." | Re-test with production flags, optimization, feature gates, and concurrency settings. |

| "The language has memory safety." | Still manage files, sockets, locks, tasks, cancellations, caches, and subscriptions. |

| "The code is self-documenting." | Self-documenting code still needs comments for domain constraints and non-obvious tradeoffs. |

Output Pattern

When applying this skill, structure feedback as:

  1. Reliability risks: concrete breakage risks first.
  2. Portability and build risks: platform, runtime, compiler, and dependency assumptions.
  3. Maintainability issues: naming, organization, contracts, comments, and complexity.
  4. Recommended changes: minimal edits that improve safety without over-engineering.
  5. Verification: exact tests, static checks, or runtime diagnostics to run.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.