You look at it till
a solution occurs
Brandon Rhodes
@brandon_rhodes
PyCon IE
Dublin, Ireland
2017 October 21
Patterns are everywhere
social-media.png
address-bar.png
spreadsheet-bad.png
spreadsheet-good.png

McIlroy

tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
Pipes!
Clipboard?

Clipboard transforms

Pattern ↔ Search

──┬─> close the channel
──┬─> close the channel
  
  └────┬─> fixed length
──┬── close the channel
  
  └────┬── fixed length
       
       
       ├── delimit ──┤
──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
HTTP Header
Content-Type: text/html␍␊
──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
ASCII: , , TAB, but also offers
SOH, STX, ETX, EOT, EM, FS, GS, RS, US
──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
"You have $count ${noun}s"
→ “You have 5 apples”

“But what if the gym is on fire?”

──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
                    ()─┬── encode
>> b64encode('Null \0 SOH \001 DEL \177')
'TnVsbCAAIFNPSCABIERFTCB/'
──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
                    ()─┬── encode
                        
                        └── escape
In SQL: 'I Won''t Back Down'
Python: 'I Won\'t Back Down'
pride-and-prejudice.png
──┬── close the channel
  
  └────┬── fixed length
       
                   (<)──── literal
       ├── delimit ──┤
                   ()─┬── encode
                       
                       └── escape
       
       └── length prefix
FORTRAN 66 — 100 FORMAT (11HHELLO WORLD)

But…

How many bytes does it
take to express a length?
──┬── close the channel
  
  └────┬── fixed length
    ^  
                  (<)──── literal
      ├── delimit ──┤
                  ()─┬── encode
                      
                      └── escape
      
      └── length prefix  ─┐
                          
    └──────────────────────┘
HTTP/1.1 200 OK␍␊
Content-Type: text/html; charset=UTF-8␍␊
Content-Encoding: UTF-8␍␊
Content-Length: 39␍␊
␍␊
<html><body>Hello, world!</body></html>
──┬──
  
  └────┬──
       
           ┌─────
       ├────┤
           └──┬──
              
              └──
       └──

Pattern ↔ Search

General Physics I — Dr. Wiesenfeld

kwiesenfeld_0_2.jpg
formula.png
loudspeaker.png
Applied Combinatorics
Understanding & Constructing Proofs
Calculus IV
Calculus V

Derivative ≪ Integral ≪ Differential Equations

George Pólya

“In order to solve this
differential equation you look at it

George Pólya

“In order to solve this
differential equation you look at it
till a solution occurs to you.”

Pattern ↔ Search ↔ ?

Zen and the Art
of Motorcycle Maintenance
Robert M. Pirsig
zen-flyleaf.jpg
stuck1.png
stuck2.png

Pattern ↔ Search ↔ Stuck

Claim

Novices generate programs
by Pattern and Search



Claim

Novices generate programs
by Pattern and Search
but once something goes wrong
they start debugging from
a default state of Stuck

Why?

Because anything could
have gone wrong —
nothing constrains the error to be in
a part of the system they understand!
Example: getting sidetracked by
a problem outside the code itself

scientific method

“The real purpose of
the scientific method
is to make sure nature hasn’t
misled you into thinking you know
something you actually don’t know.”

— Robert Pirsig

Novices get stuck

Corollary:

The default emotions of computer
programming are hope and misery
“Test-driven development is a way of
managing fear during programming.”
— Kent Beck,
Test Driven Development By Example
How can we support novice programmers?
  1. Encourage writing one line at a time
  2. Version control + frequent commits
  3. Encourage them to call for backup!
  4. Let them write things twice

Fred Brooks

“plan to throw one away;
you will, anyhow”

Fred Brooks

“plan to throw one away;
you will, anyhow”

(but not always the first!)

DjangoCon 2014:

Once my code
is finally working
it is probably better
described as barely working
Once new code works,
I am probably about
halfway done
“Even fairly good students,
when they have obtained the solution of the
problem and written down neatly the argument,
shut their books and look for something else.
Doing so, they miss an important
and instructive phase of the work.”

— George Pólya, How to Solve It

Encourage novice programmers to
explore past their first solution
Why?
Search is the programmer’s
defense against stuck
“Your problem may be modest,
but if it challenges your curiosity
and brings into play your inventive faculties,
and if you solve it by your own means,
you may experience the tension and
enjoy the triumph of discovery.”

— George Pólya, How to Solve It

Pattern ↔ Search ↔ Stuck



Pattern ↔ Search ↔ Stuck

Thank you!
@brandon_rhodes