A cost of code is defined by assigning a total expected cost functional to the mappings considering all the structures to be designed using the code. Code optimization is formulated as a minimization of this scalar point function and is shown to be reducible to a problem in nonlinear programming.