The solution is now available below

DDI can be a harsh mistress sometimes, and mistakes can sometimes be made when trying to use it. As a data format it is flexible enough to handle most situations, but this flexibility can sometimes be a shortcoming.

Below is a poorly written chunk of DDI I’ve written, that forms part of a survey instrument. The good news it can be written in a much better way. The challenge is how to rewrite it:

<d:Sequence id="MainSequence">
    <d:ComputationItem id="CompItem1">
        <d:Code>
            <r:Code programmingLanguage="pseudoCode">SET X = X + 1</r:Code>
        <d:Code>
    </d:ComputationItem>
    <d:IfThenElse id="ifblock1">
        <d:IfCondition>
            <d:Code>
                <r:Code programmingLanguage="pseudoCode">X == Y</r:Code>
            <d:Code>
        <d:IfCondition>
        <d:ThenConstructReference>
            <r:ID>A_different_sequence</r:ID>
            <r:ID>MainSequence</r:ID>
        </d:ThenConstructReference>
    </d:IfThenElse>
</d:Sequence>

If you think you can correct this code, email a solution to theodore.therone at gmail.com. At the end of the week (When I wake up this Saturday AEST) I’ll select a solution at random and give away a $15 voucher for 5senses coffee.

If you need clarification on anything in the example code, post it in the comments and I’ll clear it up.

 


Unfortunately, there were no correct responses, so the voucher will go to the next challenge, but the answer is still available below.

Solution – this was a simple computer science riddle wrapped in a layer of DDI. It was a loop rewritten as a recursive if-branch. Rewritten as a loop it comes out as this:

<d:Loop id="MainLoop">
    <d:LoopWhile >
            <d:Code>
                <r:Code programmingLanguage="pseudoCode">X == Y</r:Code>
            <d:Code>
    <d:LoopWhile>
    <d:StepValue>
        <d:Code>
            <r:Code programmingLanguage="pseudoCode">SET X = X + 1</r:Code>
        <d:Code>
    </d:StepValue>
    <d:ControlConstructReference>
        <r:ID>A_different_sequence</r:ID>
    </d:ControlConstructReference>
</d:Sequence>

A much cleaner solution!