Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/ch7_recursion.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def main():
main()
</code>
</program>
</listing>

<p><idx>separation of concerns</idx>
The key insight here is called the <term>separation of concerns</term>. The public <c>sum_array</c> method provides a user-friendly interface—callers just pass an array and get the sum. Users don't need to know about indexes or how the recursion works internally. The private <c>_sum_helper</c> method handles the recursive logic with the extra parameter needed to track progress through the array.
Expand Down
21 changes: 12 additions & 9 deletions source/ch8_filehandling.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@


<p>
We will now create a <c>File</c> object. It is important to create a meaningful name for the <c>File</c> object. We will call ours <c>myFile</c>, and we will call our class <c>CreateFileObject</c>.
We will now create a <c>File</c> object. It is important to create a meaningful name for the <c>File</c> object. We will call ours <c>myFile</c>, and we will call our class <c>CreateFileObject</c>. <xref ref="create-file-object-java" text="type-global"/> shows the code to create a <c>File</c> object in Java.
</p>

<program xml:id="create-file-object-java" interactive="activecode" language="java" add-files="myfile-created">
<listing xml:id="create-file-object-java">
<program interactive="activecode" language="java" add-files="myfile-created">
<code>
import java.io.File;

Expand All @@ -90,6 +90,7 @@ public class CreateFile {
}
</code>
</program>
</listing>

<note>
<p>
Expand All @@ -103,10 +104,10 @@ public class CreateFile {
</p>

<p>
First, lets look at the equivalent Python code:
<xref ref="create-file-python" text="type-global"/> shows the equivalent code to create a file in Python.
</p>

<program xml:id="create-file-python" interactive="activecode" language="python">
<listing xml:id="create-file-python">
<program interactive="activecode" language="python">
<code>
filename = "newfile.txt"
print("Attempting to write to '" + filename + "' using 'w' mode...")
Expand All @@ -120,12 +121,13 @@ public class CreateFile {

</code>
</program>
</listing>

<p>
Now, let's look at Java code that accomplishes the same task:
<xref ref="create-file-java" text="type-global"/> shows the equivalent code to create a file in Java.
</p>

<program xml:id="create-file-java" interactive="activecode" language="java">
<listing xml:id="create-file-java">
<program interactive="activecode" language="java">
<code>
import java.io.File;
import java.io.IOException;
Expand All @@ -148,6 +150,7 @@ public class CreateFile {
}
</code>
</program>
</listing>

<note>
<p>
Expand Down