Abstraction, Modularity, & Stepwise Refinement
Ryan: FYS Computational Reasoning Fall 2025
The creative activity of programming - to be distinguished from coding - is ... here considered as a sequence of design decisions concerning the decomposition of tasks into subtasks and of data into structures.
The process of successive refinement of specifications is illustrated by a short but nontrivial example, from which a number of conclusions are drawn regarding the art and instruction of programming.
Focus not on what computers can do, but what humans can do:
The techniques of of creation are
FLOW
ABSTRACTION
DECOMPOSITION
MODULARITY
STEPWISE REFINEMENT
Every refinement step implies some design decision.
Solutions as leaves of a tree.
problem
subproblem
subproblem
subsubproblem
subsubproblem
subsubproblem
subsubproblem
subsubproblem
subsubproblem
DEFER DECISIONS!
Eight Queens

"Brute Force"
"Divide and Conquer"

"Divide and Conquer"

Text
"Divide and Conquer"

huh?





Ask AI
"Backtracking"






considerFirstColumn
setQueen
considerNextColumn
tryColumn
regress
tryColumn
regress
156
considerFirstColumn
setQueen
considerNextColumn
tryColumn
regress
tryColumn
regress
advancePointer
testSquare
157
considerFirstColumn
setQueen
considerNextColumn
tryColumn
regress
regress
157-8
considerFirstColumn
setQueen
considerNextColumn
tryColumn
regress
regress
reconsiderPriorCol
removeQueen
removeQueen
157-8


Ask AI
160
160


Challenge
Choreography a 32 Bar Routine
Break the Problem Down

Further Refinement

Refine Down to Step-Level

Just Learning to Adjust Focus
Stepwise Dinner
Let's Throw a Party

2020 Video
Stepwise Refinement
will take us
from this→

It's just
some food,
some games, and some dancing.
No biggie.
To this→
Let's Brainstorm
cheese
menu
chop veggies
toothpicks
rap
jazz
DJ
menu
appetizers
plates
forks
table cloth
board games
napkins
cards
chicken
kebabs
cleanup
shopping
spices
invites
games
condiments
snacks
cook
food
music
rock
cheese
menu
chop veggies
toothpicks
rap
jazz
DJ
menu
appetizers
plates
forks
table cloth
board games
napkins
cards
chicken
kebabs
cleanup
shopping
spices
invites
games
condiments
snacks
cook
food
music
rock
cheese
menu
chop veggies
toothpicks
rap
jazz
DJ
setup
appetizers
plates
forks
table cloth
board games
napkins
cards
chicken
kebabs
cleanup
shopping
spices
invites
games
condiments
snacks
cook
food
music
rock

Some Hierarchy Helps
STEPWISE REFINEMENT
HELPS
EVEN
MORE

NEXT TIME: Repetition
Archive
Guest Lecture! Donald Knuth
Black Boxes
outputs
inputs






Black Boxes Are Everywhere
What Did I Do?
To look up "concatenate" in the dictionary I open the dictionary to about the middle and look at the page. Determine whether the target word is in front, behind, or actually on the page I am looking at. If it is on this page, scan until I find it. If it is in front of this page I take the pages of the first half of the dictionary and let them fall open to about the middle. I look at the page I am on and if the target word is there I scan to locate it. Otherwise I figure out if it is in front of behind where I am. I then repeat this technique for the pages in front or behind.
What Did I Do?
- select a page about midway through the dictionary
- determine if target word is before, on, or after this page
- if on this page, scan to word, and you are done.
- hold pages in front or behind as appropriate
- select a page about midway through
- repeat from step 2 above
What Did I Do?
split pages about half-way if target word on page done otherwise if before grab front half of pages else grab back half of pages repeat

Instruct a Robot to Find the Largest Card
The robot can only
Point at the cards as card1, card2, etc.
Read the value of a card.
Remember things.
Compare things.
Pseudocode
Pseudocode
def: pseudocode is a convention for using everyday language infused with a programing language sensibility for describing how to solve a problem.
pseudocode is used to help you think and to help you communicate your ideas to other humans.
pseudocode is iterative. version 0 is free form, version n is relatively formal (but you get to make up the rules)
Pseudocode
one convention: use indentation to show hierarchical logic
if hot day
go to pool
otherwise
go for bike ride
Pseudocode
To Make Tea for Someone
boil water obtain tea obtain cup ask milk & sugar if yes milk add milk if yes sugar add sugar stir serve
boil water obtain tea obtain cup ask milk & sugar if yes milk add milk if yes sugar add sugar stir serve
Pseudocode
Determine if number is even or odd
get number divide number by 2 record remainder if remainder = 0 print EVEN else print ODD
get number divide number by 2 record remainder if remainder = 0 print EVEN else print ODD
Pseudocode
Yes/No Decisions
Multiple Case Decisions
if expression action else other action
case expression value1 : action1 value2 : action2 ... valuen : actionn otherwise : defaultAction other action
"Robot" Pseudocode

bold text are "keywords" - generic things code can do
italics are for "objects"
ordinary text is an explanation
"append" means to add to the end of a list of things
"percept" refers to the information the robot takes in about the world
SMALL-CAPS() is for actions
whiteboard
Pseudocode

whiteboard
Abstraction, Modularity, and Stepwise Refinement
By Dan Ryan
Abstraction, Modularity, and Stepwise Refinement
- 25