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

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
 

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

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
NETWAYS
 
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
Ikrima Elhassan
 
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
 
Passionate Programmer
Passionate ProgrammerPassionate Programmer
Passionate Programmer
MagmaConf
 

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 (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

Último (20)

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 

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.