Lesson 21. Achieving modularity and abstraction with functions

 

After reading lesson 21, you’ll be able to

  • Write code that uses functions
  • Write functions with (zero or more) parameters
  • Write functions that (may or may not) return a specified value
  • Understand how variable values change in different function environments

In lesson 20, you saw that dividing larger tasks into modules can help you to think about problems. The process of breaking up the task leads to two important ideas: modularity and abstraction. Modularity is having smaller (more or less independent) problems to tackle, one by one. Abstraction is being able to think about the modules themselves at a higher level, without worrying about the details of implementing each. You already do this a lot in your day-to-day life; for example, you can use a car without knowing how to build one.

These modules are most useful for decluttering your larger tasks. They abstract certain tasks. You have to figure out the details of how to implement a task only once. Then you can reuse a task with many inputs to get outputs without having to rewrite it again.

21.1. Writing a function

 
 

21.2. Using functions

 
 
 

21.3. Documenting your functions

 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage