DOC PREVIEW
Berkeley COMPSCI 61A - Lecture 7

This preview shows page 1-2-3-4-5-6-7-49-50-51-52-53-54-55-98-99-100-101-102-103-104 out of 104 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 104 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

61A Lecture 7Monday, September 12Sunday, September 11, 2011Pig Contest Rules•The score for an entry is the sum of win rates against every other entry.•All strategies must be deterministic functions of the current score! Non-deterministic strategies will be disqualified.•Winner: 3 points extra credit on Project 1•Second place: 2 points•Third place: 1 point•The real prize: honor and glory•To enter: submit a file pig.py that contains a function called final_strategy as assignment p1contest by Monday, 9/262Sunday, September 11, 2011Function Decorators(demo)3Sunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xSunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xFunction decoratorSunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xFunction decoratorDecorated functionSunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xis identical toFunction decoratorDecorated functionSunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xis identical todef triple(x): return 3 * xtriple = trace1(triple)Function decoratorDecorated functionSunday, September 11, 2011Function Decorators(demo)3@trace1def triple(x): return 3 * xis identical todef triple(x): return 3 * xtriple = trace1(triple)Function decoratorDecorated functionWhy not just use this?Sunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Sunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Practical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsPractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsTesting functions stay smallPractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsRevisions should require few code changesTesting functions stay smallPractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsRevisions should require few code changesIsolates problemsTesting functions stay smallPractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsRevisions should require few code changesWriting fewer lines of code saves you timeIsolates problemsTesting functions stay smallPractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsRevisions should require few code changesWriting fewer lines of code saves you timeIsolates problemsTesting functions stay smallCopy/Paste has a steep pricePractical guidanceSunday, September 11, 2011The Art of the FunctionEach function should have exactly one jobDon't repeat yourself (DRY)Functions should be defined generally4Separation of concernsRevisions should require few code changesWriting fewer lines of code saves you timeIsolates problemsTesting functions stay smallCopy/Paste has a steep priceThese are guidelines,not strict rules!Practical guidanceSunday, September 11, 2011Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5Practical guidanceSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5Practical guidanceSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5Practical guidanceboolean turn_is_overSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5Practical guidanceboolean turn_is_overd diceSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5Practical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5>>> from operator import mul>>> def square(let):Practical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5>>> from operator import mul>>> def square(let): return mul(let, let)Practical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5>>> from operator import mul>>> def square(let): return mul(let, let)Practical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5>>> from operator import mul>>> def square(let): return mul(let, let)Practical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011From: To:Choosing NamesNames typically don’t matter for correctnessbutthey matter tremendously for legibility5>>> from operator import mul>>> def square(let): return mul(let, let)Not stylishPractical guidanceboolean turn_is_overd diceplay_helper take_turnSunday, September 11, 2011Functional Abstractions6Sunday, September 11, 2011Functional Abstractions6def square(x): return mul(x, x)Sunday, September 11, 2011Functional Abstractions6def square(x): return mul(x, x)def sum_squares(x, y): return square(x) + square(y)Sunday, September 11, 2011Functional Abstractions6What does sum_squares need to know about square to use it?def square(x): return mul(x, x)def sum_squares(x, y): return square(x) + square(y)Sunday, September 11,


View Full Document

Berkeley COMPSCI 61A - Lecture 7

Documents in this Course
Lecture 1

Lecture 1

68 pages

Midterm

Midterm

5 pages

Midterm

Midterm

6 pages

Lecture 35

Lecture 35

250 pages

Lecture 14

Lecture 14

125 pages

Lecture 2

Lecture 2

159 pages

Lecture 6

Lecture 6

113 pages

Lecture 3

Lecture 3

162 pages

Homework

Homework

25 pages

Lecture 13

Lecture 13

117 pages

Lecture 29

Lecture 29

104 pages

Lecture 11

Lecture 11

173 pages

Midterm

Midterm

6 pages

Midterm

Midterm

6 pages

Lecture 8

Lecture 8

108 pages

Lab 4

Lab 4

4 pages

Lecture 7

Lecture 7

52 pages

Lecture 20

Lecture 20

129 pages

Lecture 15

Lecture 15

132 pages

Lecture 9

Lecture 9

95 pages

Lecture 30

Lecture 30

108 pages

Lecture 17

Lecture 17

106 pages

Load more
Download Lecture 7
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 7 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 7 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?