SlideShare a Scribd company logo
1 of 18
Download to read offline
From last time…
•

Quiz 2: Variables, Conditionals, & Loops!

•

We started to organize our sketches by defining
functions and simplifying our draw loop!

•

I sent out / posted expectations for Iteration 1!

•

I’ve cancelled class next Monday, 10 Feb 2014
Iteration 1

CAP
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…)
Feedback
•

What works? What do you like?!

•

What doesn’t work? How could it be improved?!

•

Any other thoughts or comments?
Ideate

Empathize

Define

Prototype

Test

The Iterative Design Process
Functions II

CAP
Functions
•

Functions allow Modularity and Reusability!

•

They allow us to have code which follows the
principle of DRY: “Don’t Repeat Yourself”
“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)
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…
Functions
returnType functionName( argumentList )
{
// the function code is here
}

•

Memorize the structure of a function!!

•

You need to be able to “read” functions
Random Fill Color
void setRandomRGBFillColor() {
fill(random(255),random(255),random(255);
}
“This function takes no arguments, sets the fill color
to a random RGB color, and returns nothing.”
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 float.”
Demo!
Square & Circle
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
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
Demo!
Passing An Argument
Quiz 2

CAP
For next time…
•

Read Shiffman, p. 121–130 (Objects I)!

•

Two weeks until Iteration 1 is due

More Related Content

What's hot

Ruby object model
Ruby object modelRuby object model
Ruby object modelmbeizer
 
Learn Ruby 2011 - Session 3
Learn Ruby 2011 - Session 3Learn Ruby 2011 - Session 3
Learn Ruby 2011 - Session 3James Thompson
 
Dependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableDependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableJack Fox
 
Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2James Thompson
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in RubyVolodymyr Byno
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design PatternAdeel Riaz
 

What's hot (8)

Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Learn Ruby 2011 - Session 3
Learn Ruby 2011 - Session 3Learn Ruby 2011 - Session 3
Learn Ruby 2011 - Session 3
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
Decorator pattern
Decorator patternDecorator pattern
Decorator pattern
 
Dependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableDependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentable
 
Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 

Viewers also liked

Social media jones
Social media jonesSocial media jones
Social media jonesjoness_jaida
 
MoretonSmith Receivables Management Intro
MoretonSmith Receivables Management IntroMoretonSmith Receivables Management Intro
MoretonSmith Receivables Management IntroMoretonSmith
 
rory reyes
rory reyesrory reyes
rory reyesmamayay
 
20140220pln final2
20140220pln final220140220pln final2
20140220pln final2pguenthe
 
Wc unit 3 work place commuication
Wc unit 3 work place commuicationWc unit 3 work place commuication
Wc unit 3 work place commuicationGanesha Pandian
 
Social media fox
Social media foxSocial media fox
Social media foxtucker6
 
15. Final Project - Iteration 1
15. Final Project - Iteration 115. Final Project - Iteration 1
15. Final Project - Iteration 1Joseph Murphy
 
การคิดราคาต้นทุน
การคิดราคาต้นทุนการคิดราคาต้นทุน
การคิดราคาต้นทุนJirawat Laiyung
 
09 tajuk 1 إعداد خطة التدريس
09 tajuk 1 إعداد خطة التدريس09 tajuk 1 إعداد خطة التدريس
09 tajuk 1 إعداد خطة التدريسLutfi Hakimi
 

Viewers also liked (18)

1. Pixels
1. Pixels1. Pixels
1. Pixels
 
Q the music
Q the musicQ the music
Q the music
 
Presentation1
Presentation1Presentation1
Presentation1
 
28. Video II
28. Video II28. Video II
28. Video II
 
Adachris
AdachrisAdachris
Adachris
 
Social media jones
Social media jonesSocial media jones
Social media jones
 
MoretonSmith Receivables Management Intro
MoretonSmith Receivables Management IntroMoretonSmith Receivables Management Intro
MoretonSmith Receivables Management Intro
 
rory reyes
rory reyesrory reyes
rory reyes
 
20140220pln final2
20140220pln final220140220pln final2
20140220pln final2
 
Wc unit 3 work place commuication
Wc unit 3 work place commuicationWc unit 3 work place commuication
Wc unit 3 work place commuication
 
Social media fox
Social media foxSocial media fox
Social media fox
 
15. Final Project - Iteration 1
15. Final Project - Iteration 115. Final Project - Iteration 1
15. Final Project - Iteration 1
 
HUMAN RIGHTS
HUMAN RIGHTSHUMAN RIGHTS
HUMAN RIGHTS
 
การคิดราคาต้นทุน
การคิดราคาต้นทุนการคิดราคาต้นทุน
การคิดราคาต้นทุน
 
La brújula
La brújulaLa brújula
La brújula
 
4. Interaction
4. Interaction4. Interaction
4. Interaction
 
09 tajuk 1 إعداد خطة التدريس
09 tajuk 1 إعداد خطة التدريس09 tajuk 1 إعداد خطة التدريس
09 tajuk 1 إعداد خطة التدريس
 
Evaluation 4
Evaluation 4Evaluation 4
Evaluation 4
 

Similar to 11. Functions II

Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013Gary Short
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerLuis Atencio
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understandingmametter
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
The disaster of mutable state
The disaster of mutable stateThe disaster of mutable state
The disaster of mutable statekenbot
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in PharoPharo
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almostQuinton Sheppard
 
Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented ParadigmHüseyin Ergin
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!Gautam Rege
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Pythonlearn-04-Functions (1).pptx
Pythonlearn-04-Functions (1).pptxPythonlearn-04-Functions (1).pptx
Pythonlearn-04-Functions (1).pptxleavatin
 
Hacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingHacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingDan Chudnov
 
Teaching Constraint Programming, Patrick Prosser
Teaching Constraint Programming,  Patrick ProsserTeaching Constraint Programming,  Patrick Prosser
Teaching Constraint Programming, Patrick ProsserPierre Schaus
 

Similar to 11. Functions II (20)

10. Function I
10. Function I10. Function I
10. Function I
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
9. Loops II
9. Loops II9. Loops II
9. Loops II
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced Beginner
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
The disaster of mutable state
The disaster of mutable stateThe disaster of mutable state
The disaster of mutable state
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented Paradigm
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
Javascript
JavascriptJavascript
Javascript
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Pythonlearn-04-Functions (1).pptx
Pythonlearn-04-Functions (1).pptxPythonlearn-04-Functions (1).pptx
Pythonlearn-04-Functions (1).pptx
 
Hacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/ProcessingHacker 101/102 - Introduction to Programming w/Processing
Hacker 101/102 - Introduction to Programming w/Processing
 
Teaching Constraint Programming, Patrick Prosser
Teaching Constraint Programming,  Patrick ProsserTeaching Constraint Programming,  Patrick Prosser
Teaching Constraint Programming, Patrick Prosser
 

More from Joseph Murphy

More from Joseph Murphy (20)

33. Input II
33. Input II33. Input II
33. Input II
 
32. Input I
32. Input I32. Input I
32. Input I
 
30. Text II
30. Text II30. Text II
30. Text II
 
29. Text I
29. Text I29. Text I
29. Text I
 
27. Video I
27. Video I27. Video I
27. Video I
 
26. Images II
26. Images II26. Images II
26. Images II
 
25. Images I
25. Images I25. Images I
25. Images I
 
24. Translation & Rotation II
24. Translation & Rotation II24. Translation & Rotation II
24. Translation & Rotation II
 
23. Final Project Iteration II
23. Final Project Iteration II23. Final Project Iteration II
23. Final Project Iteration II
 
34. Final Project Iteration 3
34. Final Project Iteration 334. Final Project Iteration 3
34. Final Project Iteration 3
 
22. Translation & Rotation I
22. Translation & Rotation I22. Translation & Rotation I
22. Translation & Rotation I
 
21. Mathematics II
21. Mathematics II21. Mathematics II
21. Mathematics II
 
19. Algorithms II
19. Algorithms II19. Algorithms II
19. Algorithms II
 
20. Mathematics I
20. Mathematics I20. Mathematics I
20. Mathematics I
 
A. Design Thinking Lecture
A. Design Thinking LectureA. Design Thinking Lecture
A. Design Thinking Lecture
 
18. Algorithms
18. Algorithms18. Algorithms
18. Algorithms
 
14. Arrays I
14. Arrays I14. Arrays I
14. Arrays I
 
13. Objects II
13. Objects II13. Objects II
13. Objects II
 
8. Loops I
8. Loops I8. Loops I
8. Loops I
 
7. Conditionals II
7. Conditionals II7. Conditionals II
7. Conditionals II
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

11. Functions II

  • 1. From last time… • Quiz 2: Variables, Conditionals, & Loops! • We started to organize our sketches by defining functions and simplifying our draw loop! • I sent out / posted expectations for Iteration 1! • I’ve cancelled class next Monday, 10 Feb 2014
  • 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. Feedback • What works? What do you like?! • What doesn’t work? How could it be improved?! • Any other thoughts or comments?
  • 7. Functions • Functions allow Modularity and Reusability! • They allow us to have code which follows the principle of DRY: “Don’t Repeat Yourself”
  • 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. 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. Functions returnType functionName( argumentList ) { // the function code is here } • Memorize the structure of a function!! • You need to be able to “read” functions
  • 11. Random Fill Color void setRandomRGBFillColor() { fill(random(255),random(255),random(255); } “This function takes no arguments, sets the fill color to a random RGB color, and returns nothing.”
  • 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 float.”
  • 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. 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
  • 18. For next time… • Read Shiffman, p. 121–130 (Objects I)! • Two weeks until Iteration 1 is due