Upcoming SlideShare
×

# 11. Functions II

161 views

Published on

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total views
161
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 11. Functions II

1. 1. From last time… • Quiz 2: Variables, Conditionals, & Loops! • We started to organize our sketches by deﬁning functions and simplifying our draw loop! • I sent out / posted expectations for Iteration 1! • I’ve cancelled class next Monday, 10 Feb 2014
2. 2. Iteration 1 CAP
3. 3. Expectations We will have 5 groups:! ! 1 GenArt, 1 DataViz, and 3 Game groups! • • Mon, 17 Feb: you will show Iteration 1 to your group and take notes (4–5 minutes per student)! • Wed, 19 Feb: you will submit your code, the notes you took in class, and an Iteration 2 plan before class (probably via Sakai…)
4. 4. Feedback • What works? What do you like?! • What doesn’t work? How could it be improved?! • Any other thoughts or comments?
5. 5. Ideate Empathize Deﬁne Prototype Test The Iterative Design Process
6. 6. Functions II CAP
7. 7. Functions • Functions allow Modularity and Reusability! • They allow us to have code which follows the principle of DRY: “Don’t Repeat Yourself”
8. 8. “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” The Pragmatic Programmer! Hunt & Thomas on the Principle of Don’t Repeat Yourself (DRY)
9. 9. DRY vs. WET • Non-DRY coding is often called WET coding:! ! - Write Everything Twice! ! - We Enjoy Typing!! • If you are repeating yourself in code, you should automatically start thinking about functions…
10. 10. Functions returnType functionName( argumentList ) { // the function code is here } • Memorize the structure of a function!! • You need to be able to “read” functions
11. 11. Random Fill Color void setRandomRGBFillColor() { fill(random(255),random(255),random(255); } “This function takes no arguments, sets the ﬁll color to a random RGB color, and returns nothing.”
12. 12. Random Positions float randomXPosition() { return random(width); } ! float randomYPosition() { return random(height); } “This function takes no arguments, generates a random value based on width, and returns a ﬂoat.”
13. 13. Demo! Square & Circle
14. 14. Arguments • When need a function to use a value that we give to it, we give it arguments! • size(400,300); has two arguments! • Arguments are said to be “passed” to the function, and must follow some rules:! ! - they must have the correct number of arguments! ! - they must have the correct type of arguments
15. 15. Passed by Copy • When arguments are passed, they are said to be “passed by copy”! • This means that your argument is duplicated (copied) and the copy is handed to the function! • The function can use/abuse the copy and return a value, without ever affecting the original value passed in
16. 16. Demo! Passing An Argument
17. 17. Quiz 2 CAP
18. 18. For next time… • Read Shiffman, p. 121–130 (Objects I)! • Two weeks until Iteration 1 is due