Skip to content

Commit ea99928

Browse files
committed
added listing to text
1 parent 1862bd7 commit ea99928

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

source/ch7_recursion.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class MTools {
129129

130130

131131
<p>
132-
First, let's see what happens if we try to write a recursive array sum function <em>without</em> using a helper method. In this approach, the user must provide the starting index, which is awkward and exposes implementation details:
132+
First, let's see what happens if we try to write a recursive array sum function <em>without</em> using a helper method. In this approach, the user must provide the starting index, which is awkward and exposes implementation details. <xref ref="array-sum-python-no-helper" text="type-global"/> shows a Python version.
133133
</p>
134134
<listing xml:id="array-sum-python-no-helper">
135135
<program interactive="activecode" language="python">
@@ -160,7 +160,7 @@ main()
160160
</listing>
161161

162162
<p>
163-
This approach has a significant problem, namely that users must remember to start with index 0. Hence, the method signature is cluttered with an implementation detail, and it's easy to make a mistake by passing the wrong starting index. The same awkward pattern appears in Java:
163+
<xref ref="array-sum-python-no-helper" text="type-global"/>'s approach has a significant problem, namely that users must remember to start with index 0. Hence, the method signature is cluttered with an implementation detail, and it's easy to make a mistake by passing the wrong starting index. The same awkward pattern appears in Java as shown in <xref ref="array-sum-java-no-helper" text="type-global"/>.
164164
</p>
165165
<listing xml:id="array-sum-java-no-helper">
166166
<program interactive="activecode" language="java">
@@ -191,7 +191,7 @@ public class ArrayProcessor {
191191
Both versions force users to understand and provide implementation details they shouldn't need to know about. Now let's see how helper methods solve this problem by providing a clean, user-friendly interface. Notice how the public method only requires the array itself, and the hidden recursive logic tracks the current index position.
192192
</p>
193193
<p>
194-
Here's the improved Python version using a helper method:
194+
<xref ref="array-sum-python-with-helper" text="type-global"/> shows the improved Python version using a helper method.
195195
</p>
196196
<listing xml:id="array-sum-python-with-helper">
197197
<program interactive="activecode" language="python">
@@ -234,7 +234,7 @@ main()
234234
</p>
235235

236236
<p>
237-
Now let's see the improved Java version using a helper method:
237+
The same helper method pattern can be applied in Java, as shown in <xref ref="array-sum-java-with-helper" text="type-global"/>. The public method <c>sumArray</c> provides a clean interface, while the private helper method <c>sumHelper</c> manages the recursion and index tracking.
238238
</p>
239239
<listing xml:id="array-sum-java-with-helper">
240240
<program interactive="activecode" language="java">

0 commit comments

Comments
 (0)