This plan translates the four principles of Deep Coding – structural specification, generative conformance, recursive refinement, and skeleton‑tissue architecture – into MATLAB‑compatible constructs. MATLAB’s dynamic typing and object‑oriented overhead prevent full implementation. The plan therefore defines a partial, lightweight version using function handles, MVC patterns, and existing static analysis tools.
| Deep Coding Principle | MATLAB Realization |
|---|---|
| Structural specification | JSON Schema + ansatz27 or functionSignatures.json |
| Generative conformance | Function handle injection + matlab.unittest verification |
| Skeleton‑tissue separation | Template method (abstract class) or function handle injection |
| Recursive refinement | Git tags + FIXED_PREMISE.md + dependency analysis |
Define machine‑readable contracts using:
ansatz27 (third‑party) to validate MATLAB structs against the schema.functionSignatures.json – function argument types and return values.validateFunctionSignaturesJSON.mustBeNumeric, mustBeFinite, etc., inside classdef.Example JSON Schema (specification/game_state.schema.json):
{
"type": "object",
"properties": {
"score": { "type": "integer", "minimum": 0 },
"lives": { "type": "integer", "minimum": 0, "maximum": 5 }
},
"required": ["score", "lives"]
}
Implementation code is generated from the specification. MATLAB lacks native code generation from JSON Schema, so the AI produces MATLAB code that is verified against the specification.
Pipeline:
checkcode – syntax errors.miss_hit (mh_lint, mh_style) – static quality.matlab.unittest – runtime conformance test using schema validator.Example conformance test:
function testConformsToSchema(testCase)
import matlab.unittest.constraints.IsEqualTo;
data = tissueFunction(); % generated tissue
schema = jsondecode(fileread('specification/game_state.schema.json'));
% ansatz27 validation
isValid = ansatz27.validate(data, schema);
testCase.verifyTrue(isValid, 'Generated data does not conform to schema');
end
Two patterns support separation of invariant skeleton (human‑maintained) from generated tissue.
Skeleton owns execution flow, tissue is a pure function.
Skeleton (manual, immutable):
classdef ProcessorSkeleton < handle
properties (Access = private)
tissueFn
end
methods
function obj = ProcessorSkeleton(tissueFn)
obj.tissueFn = tissueFn;
end
function result = process(obj, input)
validated = obj.validate(input);
result = obj.tissueFn(validated);
result = obj.postprocess(result);
end
end
methods (Access = private)
function out = validate(~, in), out = in; end
function out = postprocess(~, in), out = in; end
end
end
Tissue (AI‑generated from specification):
% Generated from JSON Schema
myTissue = @(x) struct('score', x.score + 10, 'lives', x.lives);
processor = ProcessorSkeleton(myTissue);
Use when multiple tissue implementations share the same skeleton.
Skeleton:
classdef (Abstract) GameLoopSkeleton < handle
methods (Abstract)
update(obj, dt)
render(obj)
end
methods
function run(obj)
while true
dt = toc;
tic;
obj.update(dt);
obj.render();
drawnow;
end
end
end
end
Tissue (concrete subclass generated by AI):
classdef MyGame < GameLoopSkeleton
methods
function update(obj, dt)
% generated logic
end
function render(obj)
% generated logic
end
end
end
Development proceeds in phases. After each phase, commit a fixed premise – a snapshot of the current specification and skeleton.
Fixed premise structure (FIXED_PREMISE.md):
# Fixed Premise – Phase N
- Git tag: phase-N-complete
- Specification hash: (commit hash of specification/ folder)
- Skeleton hash: (commit hash of skeleton/ folder)
- Validation gate results: checkcode 0 errors, test pass 100%
- Next phase allowed changes: [list of spec sections modifiable]
Workflow:
phase-N-complete.phase-N+1-complete.Dependency analysis – Use MATLAB Dependency Analyzer to detect accidental tissue→skeleton reverse dependencies. Export graph and enforce direction in CI.
All generated code must pass the following automated checks before phase completion.
| Gate | Tool | Command | Pass Condition |
|---|---|---|---|
| Syntax | checkcode |
checkcode('tissue/','-config=onlyErrors.txt') |
0 errors |
| Style & complexity | miss_hit |
mh_style tissue/ && mh_metric --ci tissue/ |
0 violations, cyclomatic complexity < 10 |
| Unit tests | matlab.unittest |
runtests('test/') |
100% pass |
| Schema conformance | ansatz27 + custom test |
Custom test class | All structs validate |
| Dependency direction | Custom script | grep -r "+skeleton" tissue/ (allowed) and grep -r "+tissue" skeleton/ (forbidden) |
No reverse dependency |
Phase template:
checkcode + miss_hit.matlab.unittest runs conformance tests.FIXED_PREMISE.md. Create Git tag.Example phase sequence (game engine):
| Phase | Specification Change | Generated Tissue |
|---|---|---|
| 1 | JSON Schema for Player (position, speed) |
Function handle movePlayer |
| 2 | Schema for Enemy (type, spawn pattern) |
Subclass of EnemySkeleton |
| 3 | Schema for Stage (layout, enemy waves) |
JSON loader + stage iterator |
| Constraint | Mitigation |
|---|---|
| No static type checking | Runtime validation with matlab.unittest + schema checks |
| OOP overhead (100× slower) | Use function handle injection instead of abstract classes for performance‑critical paths |
| No native code generation from JSON Schema | AI generates code; validation gates reject non‑conforming output |
| Dynamic dependencies not detected | Encode all external file names in specification as literals |
| CI license restrictions | Use batch licensing tokens or MATLAB Compiler standalone executables |
| No built‑in fixed premise management | Git tags + FIXED_PREMISE.md + custom CI scripts |
A partial implementation of Deep Coding in MATLAB is feasible for greenfield modules, configuration systems, and Simulink‑based development. The recommended approach uses:
FIXED_PREMISE.md for recursive refinement.checkcode, miss_hit, and matlab.unittest for validation gates.Performance‑critical numerical code and large legacy scripts are not suitable targets. Start with a pilot module, use the lightweight function handle pattern, and expand only after validation gates are stable.