SlideServe
Menu
Préférences
© SlideServe · v2026

Advanced Functions: Understanding Callbacks, Parameters, and Scope in Programming

caitir avatar
17 diapositives · 306 Views · Aug 04, 2014

This lecture provides a comprehensive overview of advanced functions in programming, covering essential concepts such as calling other functions, parameters, return statements, and variable scope. It discusses the pros and cons of using functions to break problems into smaller steps, facilitating easier code organization and reordering. Key examples illustrate function definitions, including recursive functions and conditional logic. The lecture also addresses design challenges, including data management and debugging complexities, while highlighting effective programming patterns for complex problem-solving.

Advanced Functions: Understanding Callbacks, Parameters, and Scope in Programming - slide 1
01 / 17Advanced Functions: Understanding Callbacks, Parameters, and Scope in Programming
1 / 17

Télécharger la présentation

Advanced Functions: Understanding Callbacks, Parameters, and Scope in Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. ITEC 109 Lecture 15 Advanced functions

  2. Review • Functions • Parameters • Return statements • Variable scope

  3. Objectives • Functions calling other functions • Patterns • Examples

  4. Easy • Main to function and back def FunctionName(): printNow(“I am a function”) def FunctionTwo(): printNow(“I am the second”) FunctionName() FunctionTwo()

  5. Driver Driver Curve1 Curve2 Curve3

  6. Pro/Con • Pro • Breaks a problem into steps • Easy to re-order operations in the code • Con • Initial setup cost is high • Requires design, can’t just code it ™

  7. Application Driver IO Compute Output • Standard cycle pattern def getValue1(): return 3; def getValue2(): return 5; def compute(a, b) return a+b; def ouput(value) printNow(value) x =getValue1(); y= getValue2(); result = compute(x,y); output(result);

  8. Pro/Con • Pro • Separates parts of implementation (keyboard vs file) • Scaling of project • Con • Data management • Questions of what happens when you need to mix input / computation

  9. Chooser def getBalance(): return 55; def badCredit(): printNow(“Work harder”) def goodCredit(): printNow(“Keep it up”) amount = getBalance(); if (amount > 50): goodCredit(); else: badCredit(); Driver Choice Input Function2 Function3

  10. Stair step Driver Function 1 Function2 Function3 def function1(): function2(); def function2(): function3(); def function3(): printNow(“Complicated”) function1()

  11. Pro/Con • Pro • Models more complex problems • Con • What happens when something goes wrong? • If A calls B, which calls C, which calls A, what happens?

  12. Stair climbing Go back up Driver Function 1 Function2 Start Function3 *Warning*

  13. Example //Prints out sum of 4+3+2+1 def sum4(): return 4 + sum3(); def sum3(): return 3 +sum2(); def sum2(): return 2 + sum1(); def sum1(): return 1; answer =sum4(); printNow(answer)

  14. Pro/Con • Pro • Crazy and semi-useful tool • Brain bending mental exercise • Con • Algorithm design complexity • Debugging (100% CPU usage) • Recursion

  15. Combination Driver Function 1 Choice Function2 Function3 What kind of code would we need for this?

  16. Pro/Con • Pro • Divide and conqueror • Flexibility • Con • You have to figure it out • Requirements • Design • Implementation

  17. Review • Function review • Functions calling functions • Pattern review