Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^28) | Introduction to Object-Oriented Programming
values, we can combine them. If we first do the summing and then do the counting, how-
ever, we have to read the list twice. We can save steps by merging these two solutions: read
a value and then add it to the running total and add 1 to our count before going on to the next
value. When you’re writing a method for a class, and existing methods can be used but par-
tially duplicate each other’s actions, think about merging the steps they perform instead of
simply calling them one after the other.


Mental Blocks: The Fear of Starting


Writers are all too familiar with the experience of staring at a blank page, not knowing where
to begin. Programmers often have the same difficulty when they first tackle a big problem.
They look at the problem and it seems overwhelming (see Figure 1.18).

Figure 1.18 Mental Block.
Free download pdf