Deep Coding is a methodology based on four principles: structural specification, generative conformance, recursive refinement with fixed premises, and skeleton‑tissue architecture. This document provides a technical translation of these principles into concrete C++ implementations, focusing on what is possible today (C++17/20) and near future (C++26). All philosophical framing is replaced with engineering constructs.
| Deep Coding Principle | C++ Technical Realization |
|---|---|
| Structural specification (interface constraints) | C++20 Concepts, requires clauses, pure abstract base classes |
| Generative conformance | Template metaprogramming (specialization, recursive instantiation) |
| Skeleton–tissue (static) | CRTP, Policy‑Based Design |
| Skeleton–tissue (dynamic) | Non‑Virtual Interface (NVI) idiom + private virtual functions |
| Physical boundary for specifications | C++20 Modules (.ixx / .cppm) |
| Fixed premises (phase checkpoints) | Git tags + CMake CODEGEN target isolation |
| Recursive refinement | Incremental builds, add_custom_command with dependency tracking |
A hybrid approach is required because C++ lacks a single standard “specification as code” mechanism.
| Strategy | Timing | Overhead | Use Case |
|---|---|---|---|
| Template metaprogramming | compile‑time | zero | Type‑level generation, static polymorphism |
| Clang LibTooling | build‑time (pre‑compile) | build time | AST analysis, code transformation, spec extraction |
| External generators | build‑time (pre‑compile) | build time | JSON Schema → C++ classes, OpenAPI → client/server |
| C++26 reflection | compile‑time | zero | Future: standardised code splicing from specs |
| LLM‑assisted | development time | human‑in‑loop | Rapid prototyping with validation gates |
Recommendation: Use TMP for type‑safe, zero‑overhead generation. Use external generators for data model and API binding code. Prepare for C++26 reflection to replace most external generators.
| Pattern | Skeleton Role | Tissue Role | Overhead | ABI Stability |
|---|---|---|---|---|
| NVI + Template Method | public non‑virtual I/F + pre/post processing | private virtual implementations | virtual call (minor) | medium |
| CRTP | template base class (static_cast<Derived>) |
derived class | zero | high |
| Pimpl + public I/F | opaque pointer only | hidden implementation class | one indirection | very high |
| Policy‑Based | host template class | independent policy classes | zero | high |
| Abstract base + virtual | pure virtual interface | derived class | virtual call | low |
Guideline:
add_custom_command(CODEGEN ...) creates a codegen target. Build only generation without full rebuild.FILE_SET CXX_MODULES to declare module interfaces. target_link_libraries automatically resolves BMI dependencies.phase-N-complete). Use Git worktrees to work on multiple phases in parallel.DEPENDS on structural specification files. CMake reruns generator only when inputs change.| Phase | Focus | Technical Actions |
|---|---|---|
| 1 | Assessment | Run Clang‑Tidy (modernize-*), extract header dependency graph, select pilot module. |
| 2 | Pilot module | Reverse‑engineer structural specification from headers (Clang LibTooling + manual validation). Generate implementation from spec. Build adapter/wrapper for legacy boundary. |
| 3 | Gradual expansion | New features implemented with Deep Coding. Replace legacy modules one by one, keeping both implementations until cut‑over. |
| 4 | Full standardisation | Entire codebase on Deep Coding. CMake + code generation unified. CI/CD gates (compilation, architecture tests). |
Tools: clang-modules-converter, importizer, Clang‑Tidy, CodeCompass, AI‑assisted spec inference (e.g., OOPS framework).
| Phase | Duration | Deliverable |
|---|---|---|
| 0 – Infrastructure | 1‑2 weeks | CMake 3.31+, compiler with C++20 modules, Git worktree training. |
| 1 – Structural specification | 2‑3 weeks | JSON Schema / OpenAPI definitions for a pilot module. Code generation pipeline (Avrotize or GTAD). |
| 2 – Skeleton‑tissue patterns | 2‑3 weeks | Base classes using NVI or CRTP. Tissue generation from specification. Validation tests. |
| 3 – Build integration | 1‑2 weeks | CMake CODEGEN target, module dependency management, incremental generation. |
| 4 – Legacy migration (iterative) | 2‑6 months per codebase | Strangler Fig replacement, adapter generation, CI/CD gates. |
| Constraint / Risk | Mitigation |
|---|---|
| No standard ABI guarantee | Use Pimpl or extern "C" wrappers for stable boundaries. |
| Compile‑time explosion from TMP | Limit TMP to small, hot paths. Use external generators for large data models. |
| LLM‑generated code may contain UB | Mandatory static analysis (Clang‑Tidy, UBSan) in validation gate. |
| C++20 module compiler differences | Test with at least GCC, Clang, MSVC. Prefer header‑based fallback for critical paths. |
| Team learning curve | Start with pilot module, document patterns, conduct internal workshops. |
| Build time increase | Use ccache, incremental builds, and CODEGEN target separation. |
Deep Coding is implementable in C++ today using a hybrid of template metaprogramming, C++20 Modules, Concepts, NVI/CRTP/Pimpl patterns, and CMake‑integrated code generation. C++26 reflection will further reduce external tool dependencies. The methodology is particularly suited for performance‑critical systems, libraries, and large monorepos. Legacy codebases can adopt Deep Coding incrementally via the Strangler Fig pattern without a big‑bang rewrite.
This plan provides a concrete, actionable technical foundation. No philosophical axioms are required; only engineering decisions grounded in existing C++ standards and tooling.