Читать книгу Rethinking Prototyping - Группа авторов - Страница 107
5 Hybrid Associative-Imperative Programming
ОглавлениеDesignScript integrates both associative and imperative programming. In the following example (Fig. 9) the associative code (lines 32-56) are embedded in an imperative while loop. This effectively implements a simple solver which will re-compute the associative code, increasing the value of a driver variable (xHeight) until a test condition (volume <10) has been reached.
This example illustrates some important aspects of DesignScript. The designer can implement the same model building design logic in either imperative or associative code, but by harnessing the concept of replication associative code is often more compact and readable. However, a design computation system which only implements graph-based associative programming has difficulty expressing the concept of feedback, or iterative refinement and requires the use of specialised solver nodes. The disadvantage is that these solver nodes are not accessible or programmable by the designer and he cannot simply add his own solver, in an exploratory style of programing.
By contrast, DesignScript implements a hybrid imperative-associative approach to programming where code blocks from one style of programming can be nested within code blocks of another style of programming; both, associative blocks can be nested within imperative blocks and imperative blocks nested within associative blocks. This enables the designer to use and combine each style of programing where its unique strengths are relevant to the representation and execution of his design. In this example, associative programming has been used for model building, while imperative programming has been used for design iteration. Effectively, the designer has built his own custom design optimisation system.
Fig. 9 Associative-imperative programming, where the associative ‘model building’ code has been embedded within the Imperative ‘design iteration’ code.