SlideShare uma empresa Scribd logo
1 de 102
Think Like A Programmer
#UtahDigiCon#UtahDigiCon
#thinklikeaprogrammer#thinklikeaprogrammer
“Cover Slides” that didn't make the final draft...
Think Like a ProgrammerThink Like a Programmer
Think Like a ProgrammerThink Like a Programmer
Think Like a ProgrammerThink Like a Programmer
Think Like a ProgrammerThink Like a Programmer
Think Like a ProgrammerThink Like a Programmer
Think Like a ProgrammerThink Like a Programmer
Twitter
● #UtahDigiCon ● #thinklikeaprogrammer
The Twitter Disadvantage?
chomp( my @hashtags = <DATA> );
my @by_length = sort { length $b <=> length $a || $a cmp $b } @hashtags;
print "$_n" for @by_length;
print length, "n" for @by_length[0,1];
__DATA__
#agilegames
#startbusiness
#dba
#gamedesignroad
#getrich
#gamedesign
#factsoflife
#mathmyths
#makeagame
#careercode
#pathfinding
#girlsgonetech
#networking
#networkdevices
#anyonecancode
#thinklikeaprogrammer
#netduino
#tweetme
The Twitter Disadvantage!
#thinklikeaprogrammer
#gamedesignroad
#networkdevices
#anyonecancode
#girlsgonetech
#startbusiness
#factsoflife
#pathfinding
#agilegames
#careercode
#gamedesign
#networking
#makeagame
#mathmyths
#netduino
#getrich
#tweetme
#dba
21
15
The Twitter Disadvantage!
#thinklikeaprogrammer
(140 - 21 = 119)
Now add in #UtahDigiCon
(140 - 21 – 14 - 2 = 103)
You have 103 keystrokes to say something nice...
(or not).
Twitter
● #UtahDigiCon ● #thinklikeaprogrammer
Who am I?
● Dave Oswald
Who am I?
● Dave Oswald – A Propetual Hobbiest.
Who am I?
● Dave Oswald – A Propetual Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, and self-guided.
Who am I?
● Dave Oswald – A Propetual Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, and self-guided.
● Independent software developer and consultant.
– Focus on Perl, C++, and server-side development.
Who am I?
● Dave Oswald – A Propetual Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, and self-guided.
● Independent software developer and consultant.
– Focus on Perl, C++, and server-side development.
● Solving problems is my hobby. Surprisingly, people pay
me to do it.
Who am I?
● Dave Oswald – A Propetual Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, and self-guided.
● Independent software developer and consultant.
– Focus on Perl, C++, and server-side development.
● Solving problems is my hobby. Surprisingly, people pay me to do it.
● daoswald@gmail.com
● Salt Lake Perl Mongers
– http://saltlake.pm.org
Our Goal
● Learn programming in one hour.
Our Goal
● Learn programming in one hour.
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
● Get out of class for four hours.
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX
● Learn simple thought processes useful to
programmers.
Our Goal
● Learn programming in one hour.
● Sit around and tweet / text / play Temple Run
for one hour.
● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX
●
Learn simple thought processesLearn simple thought processes
useful to programmers.useful to programmers.
Attributes
Let's try this...
The Three Virtues...
● “The Triumph of the
Virtues”
– Andrea Mantegna,
1497
● Justice!
● Temperance!
● Fortitude!
The Three Virtues...
● “The Triumph of the
Virtues”
– Andrea Mantegna,
1497
● Justice!
● Temperance!
● Fortitude!
The Three Virtues...of Programmers
The Three Virtues...of Programmers
● Laziness
The Three Virtues...of Programmers
● Laziness
– The quality that
makes you go to
great effort to
reduce overall
energy
expenditure.
The Three Virtues...of Programmers
● Laziness
– Working hard to
avoid even more
hard work in the
future.
Impatience!
The Three Virtues...of Programmers
● Laziness
● Impatience
The Three Virtues...of Programmers
● Laziness
● Impatience
– The anger you feel
when the computer
is being lazy, which
happens when
another
programmer is not
lazy.
The Three Virtues...of Programmers
● Laziness
● Impatience
● Hubris
The Three Virtues...of Programmers
● Laziness
● Impatience
● Hubris
– The pride that
makes you write
and maintain
programs that you
can be proud of,
and that your
peers will admire.
The Three Virtues...of Programmers
● Laziness
– ...makes you go to great effort to reduce
your overall energy expenditure.
– …makes you write robust, modular, well-
documented programs so you can reuse
[the effort].
● Impatience
– ...anger you feel when the computer is being lazy, which
happens when another programmer is not lazy.
– ...makes you write programs that use minimal code so they’re
fast, efficient, and anticipate what needs to be done.
● Hubris
– ...pride that makes you write
and maintain programs that you
and your peers will admire.
– ...uncontrolled or undeserved, it
can also get you in trouble.
So... Who am I?
● Dave Oswald – Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, Independent.
● Independent developer and consultant.
– Focus on Perl, C++, and server-side development.
● Solving problems is my hobby. Surprisingly, people pay me to do it.
● daoswald@gmail.com
● Salt Lake Perl Mongers
– http://saltlake.pm.org
I am...
● Dave Oswald – Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, Independent.
● Independent developer and consultant.
– Focus on Perl, C++, and server-side development.
● Solving problems is my hobby. Surprisingly, people pay me to do it.
● daoswald@gmail.com
● Salt Lake Perl Mongers
– http://saltlake.pm.org
● Aspiring to be:
– Lazy
– Impatient
– Hubristic
Mental Tools of the Trade
Abstraction
● An emphasis on the idea, qualities and
properties rather than the particulars (a
suppression of detail).
Abstraction
● An emphasis on the
idea, qualities and
properties rather than
the particulars (a
suppression of detail).
● Goat
– Small Livestock.
– Horns.
– Horizontal Pupils.
– Eat almost anything.
– Curious.
– Used in Production of
Milk, Cheese, Meat.
My abstraction: Dave Oswald
● Hobbiest.
● Studied Economics and Computer Science at U of U.
– Also CS in High School, SLCC, LAVC, Independent.
● Independent developer and consultant.
– Focus on Perl, C++, and server-side development.
● Solving problems is my hobby. Surprisingly, people pay me to do it.
● daoswald@gmail.com
● Aspiring to be:
– Lazy
– Impatient
– Hubristic
“All problems in computer science can be solved
by another level of indirection [or abstraction]...”
– David Wheeler
Generalization
● A broadening of application to encompass a
larger domain of objects of the same or
different type.
Generalization
● A broadening of
application [or tool] to
encompass a larger
domain of objects of
the same or different
type.
● Dremel Tool
– Spins a bit receptical
really fast.
– Has a hand grip.
Generalization
● A broadening of
application to
encompass a larger
domain of objects of
the same or different
type.
● Dremel Tool
– Spins a bit receptical
really fast.
– Has a hand grip.
Not a generalized tool
A generalized tool
Substitution
● To put something in the place of another.
● Example: Factorial.
n! = n * ( n – 1 ) * … * 2 * 1.
Substitution
● To put something in the place of another.
● Example: Factorial.
n! = n * ( n – 1 ) * … * 2 * 1.
Substitution
● To put something in the place of another.
● Example: Factorial.
● 2! + 3!
● ( ( 2 * ( 2 – 1 ) ) + ( 3 * ( 3 – 1 ) * (3 – 2 ) )
Encapsulation
● To completely enclose.
Encapsulation
● To completely enclose.
Algorithms
Algorithms
● Step by step procedures for solving calculations
or problems.
Algorithms
● Get ready for school.
– If alarm hasn't rung, continue to sleep.
– Alarm rings
● Wake up.
● Turn off alarm.
– Pee.
– Drink some water.
– Undress.
– Shower
● Lather, rinse, repeat.
– Dry off.
– Dress.
– Comb hair.
– Eat breakfast.
– Brush teeth.
Algorithms
Abstraction, Generalization, and Substitution
allow us to develop algorithms.
And then encapsulate them, and forget about their
internals.
Number Guessing Game
Rules
● I choose a random number between 1 and 100.
● You try to guess the number by asking, “Is it
X?”
● I respond with either “Yes”, “Higher”, or “Lower”.
How would you solve it with pencil and paper?How would you solve it with pencil and paper?
Write down the steps
Rules
● I choose a random
number between 1
and 100.
● You try to guess the
number by asking,
“Is it X?”
● I respond with either
“Yes”, “Higher”, or
“Lower”.
● Step 1:
– Ask is it X?
● Step 2:
– ??????
The Blind Guess Algorithm
● Steps
– Call one person on the phone. Person guesses 23.
● Higher.
● Hang up.
– Call another person. Ask, “Is it 19?”
● Higher.
● Hang up.
● Worst case: It could take an infinite amount of guesses.
● There's only a 63% chance that it will be guessed within
100 tries.
● There's a 1% chance that it will not be guessed even after
450 tries.
The brute force algorithm.
● Steps
– Is it 1?
● Higher.
– Is it 2?
● Higher.
– Is it 3?
● Higher.
– Is it 4?
● Higher
● Worst case: Linear.
Divide and Conquer
● Is it 50?
– Lower
● Is it 25?
– Higher
● Is it 38?
– Lower.
● Each question bisects the remaining range.
● Each answer constrains the remaining range.
Divide and Conquer
● Secret number is between 1 and 10: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
– Is it 5?
● Higher.
● The secret is between 6 and 10: [ 6, 7, 8, 9, 10 ]
– Is it 8?
● Lower.
● The secret is between 6 and 7: [ 6, 7 ]
– Is it 6?
● Higher.
●
The secret number is between 7 and 7: [ 7 ]
– Is it 7?
● Yes.
How good is divide and conquer?
● Order of growth:
– As 'n' (the size of the data set) grows toward infinity,
queries needed to find an item grows at log2
(n).
● log2
(n), rounded up to nearest integer:
– n = 100, guesses = 7
– n = 1,000, guesses = 10.
– n = 1,000,000, guesses = 20.
– n = 1,000,000,000, guesses = 30.
– n = 1,000,000,000,000, guesses = 40.
– n = 1 Googol (10e100, or ten duotrigintillion), guesses = 336.
Putting it in perspective
● A computer can do 338 guesses 100 times for
each time your heart beats.
Putting it in perspective
● A computer can do 338 guesses 100 times for
each time your heart beats.
– A totally made-up statistic.
Putting it in perspective
● A computer can do 338 guesses 100 times for
each time your heart beats.
– A totally made-up statistic.
● 1.33e80 atoms in the universe.
– 266 guesses.
– ( If only the atoms
were all lined up
in order. )
Generalization
● “Divide and Conquer” number
guessing can be generalized.
– Is “oxter” is in the dictionary?
– Search 171,476 words in the
Oxford dictionary.
● 18 divide and conquer
steps.
Generalization
● “Divide and Conquer” number
guessing can be generalized.
– Is “oxter” is in the dictionary?
– Search 171,476 words in the
Oxford dictionary
● 18 divide and conquer
steps.
● n – Outdated word
meaning “armpit”.
● “Oxter” is in the dictionary.
Generalization
● “Divide and Conquer” number
guessing can be generalized.
– Find if “oxter” is in the
dictionary.
– Find if we have a 19 year old
on the roster.
– Find the address from John
Doe's directory listing.
– ...and about a million other
uses.
● “Binary Search”
A Generalized Binary Search
●
found = binary_search( [target], [big_list], [comparator] )
● What does our black-box Binary Search need?
– Something to find: a target.
– Somewhere to find it: a big list.
– Some means of comparing items: a comparator.
What is a comparator?
● Another black box.
– comparator( a, b )
● Return -1 if a < b
● Return 1 if b < a
● Otherwise return 0.
● Dan < David
– D == D
– a == a
– n < v
● 7 > 5
● 2.71828 < 3.14151
A Generalized Binary Search
●
found = binary_search( [target], [big_list], [how_to_compare] )
● What does our black-box Binary Search need?
– Something to find: a target.
– Somewhere to find it: a sorted big list.
– Some means of comparing items: a comparator.
● An item comparer black-box.
sub comparator {
  my( $a, $b ) = ( shift, shift );
  return $a <=> $b; # ( returns ­1, 0, or 1 )
}
my $found 
  = bsearch( $target, @list, &comparator );
A Generalized Binary Search
Implementation
sub binsearch (&$@) {
my ( $code, $target, $aref ) = @_;
my $min = 0;
my $max = $#{$aref};
while ( $max > $min ) {
my $mid = int( ( $min + $max ) / 2 );
no strict 'refs'; ## no critic(strict)
local ( ${caller() . '::a'}, ${caller() . '::b'} )
= ( $target, $aref->[$mid] );
if ( $code->( $target, $aref->[$mid] ) > 0 ) {
$min = $mid + 1;
}
else {
$max = $mid;
}
}
{
no strict 'refs'; ## no critic(strict)
local ( ${caller() . '::a'}, ${caller() . '::b'} )
= ( $target, $aref->[$min] );
return $min if $code->( $target, $aref->[$min] ) == 0;
}
return;
}
Guessing numbers programatically
use List::BinarySearch 'binsearch';
use IO::Prompt::Hooked 'prompt';
print "Please think of a number between 1 and 10...nnn";
my $tries = 0;
binsearch {
++$tries;
my $response = prompt(
message => "Is the number $b? (higher, lower, or yes):",
validate => qr/higher|lower|yes/i,
error => sub { "Bad input: $_[0] .Try again.n" },
);
return 1 if $response =~ /higher/i;
return -1 if $response =~ /lower/i;
print "Found $b in $tries guesses.n";
exit(0);
} undef, @{[1 .. 10]};
Generalization, Abstraction,
Encapsulation
● We generalized the Binary Search algorithm.
Generalization, Abstraction,
Encapsulation
● We generalized the Binary Search algorithm.
– It doesn't care what a target, or comparator look like
inside.
Generalization, Abstraction,
Encapsulation
● We generalized the Binary Search algorithm.
– It doesn't care what a target, or comparator look like
inside.
● Our target and list items are abstractions on their
underlying characteristics.
Generalization, Abstraction,
Encapsulation
● We generalized the Binary Search algorithm.
– It doesn't care what a target, or comparator look like
inside.
● Our target and list items are abstractions on their
underlying characteristics.
● Our comparator specializes our Binary Search algorithm.
– Black box (encapsulation of functionality).
Generalization, Abstraction,
Encapsulation
● We generalized the Binary Search algorithm.
– It doesn't care what a target, or comparator look like
inside.
● Our target and list items are abstractions on their underlying
characteristics.
● Our comparator specializes our Binary Search algorithm.
– Black box (encapsulation of functionality).
● We can use it anywhere.
– Just provide a target, a list, and a means to compare.
– Never re-invent it again.
– Fewer bugs, through code re-use.
We turned the number guessing
game into a Dremel tool.
A good programmer should seek opportunities to
apply generalized solutions to specific problems.
A good programmer should seek to make
solutions general, so that they can be reused by
providing a specialization to them.
A good programmer needs to learn where and
how to find these opportunities.
Laziness, Impatience, Hubris
The Virtues You Should Seek
● Be Lazy
– Work hard now to
make it possible.
● Be Impatient
– The status quo is
never good enough
● Be Hubristic
– Write code you can be
proud of.
...and...
Love What You Do
Think Like A Programmer
● #UtahDigiCon
● #thinklikeaprogrammer
● David Oswald
● daoswald@gmail.com
● Salt Lake Perl Mongers
● http://saltlake.pm.org
Algorithms should place as few requirements on
the data they work with as practical.

Mais conteúdo relacionado

Destaque

Growing an open participative horizontal and based on trust company
Growing an open participative horizontal and based on trust companyGrowing an open participative horizontal and based on trust company
Growing an open participative horizontal and based on trust companyHernan Wilkinson
 
A new object oriented model of the gregorian calendar
A new object oriented model of the gregorian calendarA new object oriented model of the gregorian calendar
A new object oriented model of the gregorian calendarHernan Wilkinson
 
Programming Language Technical debt and their influence in Thinking and Desgin
Programming Language Technical debt and their influence in Thinking and DesginProgramming Language Technical debt and their influence in Thinking and Desgin
Programming Language Technical debt and their influence in Thinking and DesginHernan Wilkinson
 
Augmenting Smalltalk Syntax
Augmenting Smalltalk SyntaxAugmenting Smalltalk Syntax
Augmenting Smalltalk SyntaxHernan Wilkinson
 
Técnicas y herramientas para que la computadora haga más y el programador m...
Técnicas y herramientas para que la computadora haga más y el programador m...Técnicas y herramientas para que la computadora haga más y el programador m...
Técnicas y herramientas para que la computadora haga más y el programador m...Hernan Wilkinson
 
Como escribir buenos tests al hacer TDD
Como escribir buenos tests al hacer TDDComo escribir buenos tests al hacer TDD
Como escribir buenos tests al hacer TDDHernan Wilkinson
 
Desarrollando sistemas con metodologías y técnicas agiles
Desarrollando sistemas con metodologías y técnicas agilesDesarrollando sistemas con metodologías y técnicas agiles
Desarrollando sistemas con metodologías y técnicas agilesHernan Wilkinson
 
Continous Integration For The Lazy Programmer
Continous Integration For The Lazy ProgrammerContinous Integration For The Lazy Programmer
Continous Integration For The Lazy ProgrammerGiovanni Intini
 
Programming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingProgramming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingHernan Wilkinson
 
Child Internet Safety summit: online safety and inspection
Child Internet Safety summit: online safety and inspectionChild Internet Safety summit: online safety and inspection
Child Internet Safety summit: online safety and inspectionOfsted
 

Destaque (12)

Things programmers know
Things programmers knowThings programmers know
Things programmers know
 
Algorithms KS1 & KS2
Algorithms KS1 & KS2Algorithms KS1 & KS2
Algorithms KS1 & KS2
 
Growing an open participative horizontal and based on trust company
Growing an open participative horizontal and based on trust companyGrowing an open participative horizontal and based on trust company
Growing an open participative horizontal and based on trust company
 
A new object oriented model of the gregorian calendar
A new object oriented model of the gregorian calendarA new object oriented model of the gregorian calendar
A new object oriented model of the gregorian calendar
 
Programming Language Technical debt and their influence in Thinking and Desgin
Programming Language Technical debt and their influence in Thinking and DesginProgramming Language Technical debt and their influence in Thinking and Desgin
Programming Language Technical debt and their influence in Thinking and Desgin
 
Augmenting Smalltalk Syntax
Augmenting Smalltalk SyntaxAugmenting Smalltalk Syntax
Augmenting Smalltalk Syntax
 
Técnicas y herramientas para que la computadora haga más y el programador m...
Técnicas y herramientas para que la computadora haga más y el programador m...Técnicas y herramientas para que la computadora haga más y el programador m...
Técnicas y herramientas para que la computadora haga más y el programador m...
 
Como escribir buenos tests al hacer TDD
Como escribir buenos tests al hacer TDDComo escribir buenos tests al hacer TDD
Como escribir buenos tests al hacer TDD
 
Desarrollando sistemas con metodologías y técnicas agiles
Desarrollando sistemas con metodologías y técnicas agilesDesarrollando sistemas con metodologías y técnicas agiles
Desarrollando sistemas con metodologías y técnicas agiles
 
Continous Integration For The Lazy Programmer
Continous Integration For The Lazy ProgrammerContinous Integration For The Lazy Programmer
Continous Integration For The Lazy Programmer
 
Programming Languages and their influence in Thinking
Programming Languages and their influence in ThinkingProgramming Languages and their influence in Thinking
Programming Languages and their influence in Thinking
 
Child Internet Safety summit: online safety and inspection
Child Internet Safety summit: online safety and inspectionChild Internet Safety summit: online safety and inspection
Child Internet Safety summit: online safety and inspection
 

Semelhante a Think Like a Programmer

Is there a future for devops ?
Is there a future for devops ?Is there a future for devops ?
Is there a future for devops ?Kris Buytaert
 
Its not about the tooling
Its not about the toolingIts not about the tooling
Its not about the toolingBram Vogelaar
 
How to be a 10x Engineer
How to be a 10x EngineerHow to be a 10x Engineer
How to be a 10x EngineerNick Sullivan
 
OSMC 2015 | Testing in Production by Devdas Bhagat
OSMC 2015 | Testing in Production by Devdas BhagatOSMC 2015 | Testing in Production by Devdas Bhagat
OSMC 2015 | Testing in Production by Devdas BhagatNETWAYS
 
OSMC 2015: Testing in Production by Devdas Bhagat
OSMC 2015: Testing in Production by Devdas BhagatOSMC 2015: Testing in Production by Devdas Bhagat
OSMC 2015: Testing in Production by Devdas BhagatNETWAYS
 
Hacking - Breaking Into It
Hacking - Breaking Into ItHacking - Breaking Into It
Hacking - Breaking Into ItCTruncer
 
Devops, The future is here, it's just not evenly distributed
Devops, The future is here, it's just not evenly distributedDevops, The future is here, it's just not evenly distributed
Devops, The future is here, it's just not evenly distributedKris Buytaert
 
VRDC 2016 Talk: Kite & Lightning's VR Production Workflow
VRDC 2016 Talk: Kite & Lightning's VR Production WorkflowVRDC 2016 Talk: Kite & Lightning's VR Production Workflow
VRDC 2016 Talk: Kite & Lightning's VR Production WorkflowIkrima Elhassan
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deckMikeBegley
 
Jason Yee - Chaos! - Codemotion Rome 2019
Jason Yee - Chaos! - Codemotion Rome 2019Jason Yee - Chaos! - Codemotion Rome 2019
Jason Yee - Chaos! - Codemotion Rome 2019Codemotion
 
Adopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenchesAdopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenchesKris Buytaert
 
Devops its not about the tooling
Devops its not about the toolingDevops its not about the tooling
Devops its not about the toolingBram Vogelaar
 
User Story Mapping - mini iad 2014 (Armani, Rodriguez)
User Story Mapping - mini iad 2014 (Armani, Rodriguez)User Story Mapping - mini iad 2014 (Armani, Rodriguez)
User Story Mapping - mini iad 2014 (Armani, Rodriguez)Fabio Armani
 
How to Automate Yourself out of a Job (7/9/19)
How to Automate Yourself out of a Job (7/9/19)How to Automate Yourself out of a Job (7/9/19)
How to Automate Yourself out of a Job (7/9/19)judy (fink) johnson
 
OSDC 2012 | Devops and Open Source by Kris Buyaert
OSDC 2012 | Devops and Open Source by Kris BuyaertOSDC 2012 | Devops and Open Source by Kris Buyaert
OSDC 2012 | Devops and Open Source by Kris BuyaertNETWAYS
 
OSDC 2012 | Devops and Open Source by Kris Buytaert
OSDC 2012 | Devops and Open Source by Kris BuytaertOSDC 2012 | Devops and Open Source by Kris Buytaert
OSDC 2012 | Devops and Open Source by Kris BuytaertNETWAYS
 
Microsoft Research's Leslie Lamport at Build2014 - Thinking for Programmers
Microsoft Research's Leslie Lamport at Build2014 - Thinking for ProgrammersMicrosoft Research's Leslie Lamport at Build2014 - Thinking for Programmers
Microsoft Research's Leslie Lamport at Build2014 - Thinking for ProgrammersIshit Makwana
 
Passionate Programmer
Passionate ProgrammerPassionate Programmer
Passionate ProgrammerMagmaConf
 

Semelhante a Think Like a Programmer (20)

Is there a future for devops ?
Is there a future for devops ?Is there a future for devops ?
Is there a future for devops ?
 
Its not about the tooling
Its not about the toolingIts not about the tooling
Its not about the tooling
 
How to be a 10x Engineer
How to be a 10x EngineerHow to be a 10x Engineer
How to be a 10x Engineer
 
OSMC 2015 | Testing in Production by Devdas Bhagat
OSMC 2015 | Testing in Production by Devdas BhagatOSMC 2015 | Testing in Production by Devdas Bhagat
OSMC 2015 | Testing in Production by Devdas Bhagat
 
OSMC 2015: Testing in Production by Devdas Bhagat
OSMC 2015: Testing in Production by Devdas BhagatOSMC 2015: Testing in Production by Devdas Bhagat
OSMC 2015: Testing in Production by Devdas Bhagat
 
Hacking - Breaking Into It
Hacking - Breaking Into ItHacking - Breaking Into It
Hacking - Breaking Into It
 
Devops, The future is here, it's just not evenly distributed
Devops, The future is here, it's just not evenly distributedDevops, The future is here, it's just not evenly distributed
Devops, The future is here, it's just not evenly distributed
 
VRDC 2016 Talk: Kite & Lightning's VR Production Workflow
VRDC 2016 Talk: Kite & Lightning's VR Production WorkflowVRDC 2016 Talk: Kite & Lightning's VR Production Workflow
VRDC 2016 Talk: Kite & Lightning's VR Production Workflow
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deck
 
Jason Yee - Chaos! - Codemotion Rome 2019
Jason Yee - Chaos! - Codemotion Rome 2019Jason Yee - Chaos! - Codemotion Rome 2019
Jason Yee - Chaos! - Codemotion Rome 2019
 
Adopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenchesAdopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenches
 
Devops its not about the tooling
Devops its not about the toolingDevops its not about the tooling
Devops its not about the tooling
 
User Story Mapping - mini iad 2014 (Armani, Rodriguez)
User Story Mapping - mini iad 2014 (Armani, Rodriguez)User Story Mapping - mini iad 2014 (Armani, Rodriguez)
User Story Mapping - mini iad 2014 (Armani, Rodriguez)
 
How to Automate Yourself out of a Job (7/9/19)
How to Automate Yourself out of a Job (7/9/19)How to Automate Yourself out of a Job (7/9/19)
How to Automate Yourself out of a Job (7/9/19)
 
Technical Interviewing
Technical InterviewingTechnical Interviewing
Technical Interviewing
 
OSDC 2012 | Devops and Open Source by Kris Buyaert
OSDC 2012 | Devops and Open Source by Kris BuyaertOSDC 2012 | Devops and Open Source by Kris Buyaert
OSDC 2012 | Devops and Open Source by Kris Buyaert
 
OSDC 2012 | Devops and Open Source by Kris Buytaert
OSDC 2012 | Devops and Open Source by Kris BuytaertOSDC 2012 | Devops and Open Source by Kris Buytaert
OSDC 2012 | Devops and Open Source by Kris Buytaert
 
Microsoft Research's Leslie Lamport at Build2014 - Thinking for Programmers
Microsoft Research's Leslie Lamport at Build2014 - Thinking for ProgrammersMicrosoft Research's Leslie Lamport at Build2014 - Thinking for Programmers
Microsoft Research's Leslie Lamport at Build2014 - Thinking for Programmers
 
Mlw
MlwMlw
Mlw
 
Passionate Programmer
Passionate ProgrammerPassionate Programmer
Passionate Programmer
 

Mais de daoswald

Perl: Setting Up An Internal Darkpan
Perl: Setting Up An Internal DarkpanPerl: Setting Up An Internal Darkpan
Perl: Setting Up An Internal Darkpandaoswald
 
Speaking at Tech Events
Speaking at Tech EventsSpeaking at Tech Events
Speaking at Tech Eventsdaoswald
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-linersdaoswald
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perldaoswald
 
Perls Functional functions
Perls Functional functionsPerls Functional functions
Perls Functional functionsdaoswald
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPANdaoswald
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 

Mais de daoswald (7)

Perl: Setting Up An Internal Darkpan
Perl: Setting Up An Internal DarkpanPerl: Setting Up An Internal Darkpan
Perl: Setting Up An Internal Darkpan
 
Speaking at Tech Events
Speaking at Tech EventsSpeaking at Tech Events
Speaking at Tech Events
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 
Perls Functional functions
Perls Functional functionsPerls Functional functions
Perls Functional functions
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Think Like a Programmer

  • 1. Think Like A Programmer #UtahDigiCon#UtahDigiCon #thinklikeaprogrammer#thinklikeaprogrammer
  • 2. “Cover Slides” that didn't make the final draft...
  • 3. Think Like a ProgrammerThink Like a Programmer
  • 4. Think Like a ProgrammerThink Like a Programmer
  • 5. Think Like a ProgrammerThink Like a Programmer
  • 6. Think Like a ProgrammerThink Like a Programmer
  • 7. Think Like a ProgrammerThink Like a Programmer
  • 8. Think Like a ProgrammerThink Like a Programmer
  • 9. Twitter ● #UtahDigiCon ● #thinklikeaprogrammer
  • 12. The Twitter Disadvantage! #thinklikeaprogrammer (140 - 21 = 119) Now add in #UtahDigiCon (140 - 21 – 14 - 2 = 103) You have 103 keystrokes to say something nice... (or not).
  • 13. Twitter ● #UtahDigiCon ● #thinklikeaprogrammer
  • 14. Who am I? ● Dave Oswald
  • 15. Who am I? ● Dave Oswald – A Propetual Hobbiest.
  • 16. Who am I? ● Dave Oswald – A Propetual Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, and self-guided.
  • 17. Who am I? ● Dave Oswald – A Propetual Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, and self-guided. ● Independent software developer and consultant. – Focus on Perl, C++, and server-side development.
  • 18. Who am I? ● Dave Oswald – A Propetual Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, and self-guided. ● Independent software developer and consultant. – Focus on Perl, C++, and server-side development. ● Solving problems is my hobby. Surprisingly, people pay me to do it.
  • 19. Who am I? ● Dave Oswald – A Propetual Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, and self-guided. ● Independent software developer and consultant. – Focus on Perl, C++, and server-side development. ● Solving problems is my hobby. Surprisingly, people pay me to do it. ● daoswald@gmail.com ● Salt Lake Perl Mongers – http://saltlake.pm.org
  • 20. Our Goal ● Learn programming in one hour.
  • 21. Our Goal ● Learn programming in one hour.
  • 22. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour.
  • 23. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour.
  • 24. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour. ● Get out of class for four hours.
  • 25. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour. ● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX
  • 26. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour. ● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX ● Learn simple thought processes useful to programmers.
  • 27. Our Goal ● Learn programming in one hour. ● Sit around and tweet / text / play Temple Run for one hour. ● Get out of class for four hours.XXXXXXXXXXXXXXXXXXXXX ● Learn simple thought processesLearn simple thought processes useful to programmers.useful to programmers.
  • 30. The Three Virtues... ● “The Triumph of the Virtues” – Andrea Mantegna, 1497 ● Justice! ● Temperance! ● Fortitude!
  • 31.
  • 32. The Three Virtues... ● “The Triumph of the Virtues” – Andrea Mantegna, 1497 ● Justice! ● Temperance! ● Fortitude!
  • 33. The Three Virtues...of Programmers
  • 34. The Three Virtues...of Programmers ● Laziness
  • 35. The Three Virtues...of Programmers ● Laziness – The quality that makes you go to great effort to reduce overall energy expenditure.
  • 36. The Three Virtues...of Programmers ● Laziness – Working hard to avoid even more hard work in the future.
  • 38. The Three Virtues...of Programmers ● Laziness ● Impatience
  • 39. The Three Virtues...of Programmers ● Laziness ● Impatience – The anger you feel when the computer is being lazy, which happens when another programmer is not lazy.
  • 40. The Three Virtues...of Programmers ● Laziness ● Impatience ● Hubris
  • 41. The Three Virtues...of Programmers ● Laziness ● Impatience ● Hubris – The pride that makes you write and maintain programs that you can be proud of, and that your peers will admire.
  • 42. The Three Virtues...of Programmers ● Laziness – ...makes you go to great effort to reduce your overall energy expenditure. – …makes you write robust, modular, well- documented programs so you can reuse [the effort]. ● Impatience – ...anger you feel when the computer is being lazy, which happens when another programmer is not lazy. – ...makes you write programs that use minimal code so they’re fast, efficient, and anticipate what needs to be done. ● Hubris – ...pride that makes you write and maintain programs that you and your peers will admire. – ...uncontrolled or undeserved, it can also get you in trouble.
  • 43.
  • 44. So... Who am I? ● Dave Oswald – Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, Independent. ● Independent developer and consultant. – Focus on Perl, C++, and server-side development. ● Solving problems is my hobby. Surprisingly, people pay me to do it. ● daoswald@gmail.com ● Salt Lake Perl Mongers – http://saltlake.pm.org
  • 45. I am... ● Dave Oswald – Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, Independent. ● Independent developer and consultant. – Focus on Perl, C++, and server-side development. ● Solving problems is my hobby. Surprisingly, people pay me to do it. ● daoswald@gmail.com ● Salt Lake Perl Mongers – http://saltlake.pm.org ● Aspiring to be: – Lazy – Impatient – Hubristic
  • 46. Mental Tools of the Trade
  • 47. Abstraction ● An emphasis on the idea, qualities and properties rather than the particulars (a suppression of detail).
  • 48. Abstraction ● An emphasis on the idea, qualities and properties rather than the particulars (a suppression of detail). ● Goat – Small Livestock. – Horns. – Horizontal Pupils. – Eat almost anything. – Curious. – Used in Production of Milk, Cheese, Meat.
  • 49. My abstraction: Dave Oswald ● Hobbiest. ● Studied Economics and Computer Science at U of U. – Also CS in High School, SLCC, LAVC, Independent. ● Independent developer and consultant. – Focus on Perl, C++, and server-side development. ● Solving problems is my hobby. Surprisingly, people pay me to do it. ● daoswald@gmail.com ● Aspiring to be: – Lazy – Impatient – Hubristic
  • 50. “All problems in computer science can be solved by another level of indirection [or abstraction]...” – David Wheeler
  • 51. Generalization ● A broadening of application to encompass a larger domain of objects of the same or different type.
  • 52. Generalization ● A broadening of application [or tool] to encompass a larger domain of objects of the same or different type. ● Dremel Tool – Spins a bit receptical really fast. – Has a hand grip.
  • 53. Generalization ● A broadening of application to encompass a larger domain of objects of the same or different type. ● Dremel Tool – Spins a bit receptical really fast. – Has a hand grip.
  • 56. Substitution ● To put something in the place of another. ● Example: Factorial. n! = n * ( n – 1 ) * … * 2 * 1.
  • 57. Substitution ● To put something in the place of another. ● Example: Factorial. n! = n * ( n – 1 ) * … * 2 * 1.
  • 58. Substitution ● To put something in the place of another. ● Example: Factorial. ● 2! + 3! ● ( ( 2 * ( 2 – 1 ) ) + ( 3 * ( 3 – 1 ) * (3 – 2 ) )
  • 62. Algorithms ● Step by step procedures for solving calculations or problems.
  • 63. Algorithms ● Get ready for school. – If alarm hasn't rung, continue to sleep. – Alarm rings ● Wake up. ● Turn off alarm. – Pee. – Drink some water. – Undress. – Shower ● Lather, rinse, repeat. – Dry off. – Dress. – Comb hair. – Eat breakfast. – Brush teeth.
  • 65. Abstraction, Generalization, and Substitution allow us to develop algorithms. And then encapsulate them, and forget about their internals.
  • 67. Rules ● I choose a random number between 1 and 100. ● You try to guess the number by asking, “Is it X?” ● I respond with either “Yes”, “Higher”, or “Lower”.
  • 68. How would you solve it with pencil and paper?How would you solve it with pencil and paper?
  • 69. Write down the steps
  • 70. Rules ● I choose a random number between 1 and 100. ● You try to guess the number by asking, “Is it X?” ● I respond with either “Yes”, “Higher”, or “Lower”. ● Step 1: – Ask is it X? ● Step 2: – ??????
  • 71. The Blind Guess Algorithm ● Steps – Call one person on the phone. Person guesses 23. ● Higher. ● Hang up. – Call another person. Ask, “Is it 19?” ● Higher. ● Hang up. ● Worst case: It could take an infinite amount of guesses. ● There's only a 63% chance that it will be guessed within 100 tries. ● There's a 1% chance that it will not be guessed even after 450 tries.
  • 72. The brute force algorithm. ● Steps – Is it 1? ● Higher. – Is it 2? ● Higher. – Is it 3? ● Higher. – Is it 4? ● Higher ● Worst case: Linear.
  • 73. Divide and Conquer ● Is it 50? – Lower ● Is it 25? – Higher ● Is it 38? – Lower. ● Each question bisects the remaining range. ● Each answer constrains the remaining range.
  • 74. Divide and Conquer ● Secret number is between 1 and 10: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] – Is it 5? ● Higher. ● The secret is between 6 and 10: [ 6, 7, 8, 9, 10 ] – Is it 8? ● Lower. ● The secret is between 6 and 7: [ 6, 7 ] – Is it 6? ● Higher. ● The secret number is between 7 and 7: [ 7 ] – Is it 7? ● Yes.
  • 75. How good is divide and conquer? ● Order of growth: – As 'n' (the size of the data set) grows toward infinity, queries needed to find an item grows at log2 (n). ● log2 (n), rounded up to nearest integer: – n = 100, guesses = 7 – n = 1,000, guesses = 10. – n = 1,000,000, guesses = 20. – n = 1,000,000,000, guesses = 30. – n = 1,000,000,000,000, guesses = 40. – n = 1 Googol (10e100, or ten duotrigintillion), guesses = 336.
  • 76. Putting it in perspective ● A computer can do 338 guesses 100 times for each time your heart beats.
  • 77. Putting it in perspective ● A computer can do 338 guesses 100 times for each time your heart beats. – A totally made-up statistic.
  • 78. Putting it in perspective ● A computer can do 338 guesses 100 times for each time your heart beats. – A totally made-up statistic. ● 1.33e80 atoms in the universe. – 266 guesses. – ( If only the atoms were all lined up in order. )
  • 79. Generalization ● “Divide and Conquer” number guessing can be generalized. – Is “oxter” is in the dictionary? – Search 171,476 words in the Oxford dictionary. ● 18 divide and conquer steps.
  • 80. Generalization ● “Divide and Conquer” number guessing can be generalized. – Is “oxter” is in the dictionary? – Search 171,476 words in the Oxford dictionary ● 18 divide and conquer steps. ● n – Outdated word meaning “armpit”. ● “Oxter” is in the dictionary.
  • 81. Generalization ● “Divide and Conquer” number guessing can be generalized. – Find if “oxter” is in the dictionary. – Find if we have a 19 year old on the roster. – Find the address from John Doe's directory listing. – ...and about a million other uses. ● “Binary Search”
  • 82. A Generalized Binary Search ● found = binary_search( [target], [big_list], [comparator] ) ● What does our black-box Binary Search need? – Something to find: a target. – Somewhere to find it: a big list. – Some means of comparing items: a comparator.
  • 83. What is a comparator? ● Another black box. – comparator( a, b ) ● Return -1 if a < b ● Return 1 if b < a ● Otherwise return 0. ● Dan < David – D == D – a == a – n < v ● 7 > 5 ● 2.71828 < 3.14151
  • 84. A Generalized Binary Search ● found = binary_search( [target], [big_list], [how_to_compare] ) ● What does our black-box Binary Search need? – Something to find: a target. – Somewhere to find it: a sorted big list. – Some means of comparing items: a comparator. ● An item comparer black-box. sub comparator {   my( $a, $b ) = ( shift, shift );   return $a <=> $b; # ( returns ­1, 0, or 1 ) } my $found    = bsearch( $target, @list, &comparator );
  • 85. A Generalized Binary Search Implementation sub binsearch (&$@) { my ( $code, $target, $aref ) = @_; my $min = 0; my $max = $#{$aref}; while ( $max > $min ) { my $mid = int( ( $min + $max ) / 2 ); no strict 'refs'; ## no critic(strict) local ( ${caller() . '::a'}, ${caller() . '::b'} ) = ( $target, $aref->[$mid] ); if ( $code->( $target, $aref->[$mid] ) > 0 ) { $min = $mid + 1; } else { $max = $mid; } } { no strict 'refs'; ## no critic(strict) local ( ${caller() . '::a'}, ${caller() . '::b'} ) = ( $target, $aref->[$min] ); return $min if $code->( $target, $aref->[$min] ) == 0; } return; }
  • 86. Guessing numbers programatically use List::BinarySearch 'binsearch'; use IO::Prompt::Hooked 'prompt'; print "Please think of a number between 1 and 10...nnn"; my $tries = 0; binsearch { ++$tries; my $response = prompt( message => "Is the number $b? (higher, lower, or yes):", validate => qr/higher|lower|yes/i, error => sub { "Bad input: $_[0] .Try again.n" }, ); return 1 if $response =~ /higher/i; return -1 if $response =~ /lower/i; print "Found $b in $tries guesses.n"; exit(0); } undef, @{[1 .. 10]};
  • 87. Generalization, Abstraction, Encapsulation ● We generalized the Binary Search algorithm.
  • 88. Generalization, Abstraction, Encapsulation ● We generalized the Binary Search algorithm. – It doesn't care what a target, or comparator look like inside.
  • 89. Generalization, Abstraction, Encapsulation ● We generalized the Binary Search algorithm. – It doesn't care what a target, or comparator look like inside. ● Our target and list items are abstractions on their underlying characteristics.
  • 90. Generalization, Abstraction, Encapsulation ● We generalized the Binary Search algorithm. – It doesn't care what a target, or comparator look like inside. ● Our target and list items are abstractions on their underlying characteristics. ● Our comparator specializes our Binary Search algorithm. – Black box (encapsulation of functionality).
  • 91. Generalization, Abstraction, Encapsulation ● We generalized the Binary Search algorithm. – It doesn't care what a target, or comparator look like inside. ● Our target and list items are abstractions on their underlying characteristics. ● Our comparator specializes our Binary Search algorithm. – Black box (encapsulation of functionality). ● We can use it anywhere. – Just provide a target, a list, and a means to compare. – Never re-invent it again. – Fewer bugs, through code re-use.
  • 92. We turned the number guessing game into a Dremel tool.
  • 93. A good programmer should seek opportunities to apply generalized solutions to specific problems.
  • 94. A good programmer should seek to make solutions general, so that they can be reused by providing a specialization to them.
  • 95. A good programmer needs to learn where and how to find these opportunities.
  • 96.
  • 98. The Virtues You Should Seek ● Be Lazy – Work hard now to make it possible. ● Be Impatient – The status quo is never good enough ● Be Hubristic – Write code you can be proud of.
  • 101. Think Like A Programmer ● #UtahDigiCon ● #thinklikeaprogrammer ● David Oswald ● daoswald@gmail.com ● Salt Lake Perl Mongers ● http://saltlake.pm.org
  • 102. Algorithms should place as few requirements on the data they work with as practical.