Commit 0a9f7fea authored by David Benn's avatar David Benn Committed by Maxim Belkin
Browse files

06-func.md: rename analyze() to visualize() (#712)

The function called `analyze` performs visualization tasks. Following our own suggestion ("function names usually describe what they do"), we rename the function to `visualize`.
parent 6a5b3a63
...@@ -146,10 +146,10 @@ or the next person who reads it won't be able to understand what's going on. ...@@ -146,10 +146,10 @@ or the next person who reads it won't be able to understand what's going on.
Now that we know how to wrap bits of code up in functions, Now that we know how to wrap bits of code up in functions,
we can make our inflammation analysis easier to read and easier to reuse. we can make our inflammation analysis easier to read and easier to reuse.
First, let's make an `analyze` function that generates our plots: First, let's make a `visualize` function that generates our plots:
~~~ ~~~
def analyze(filename): def visualize(filename):
data = numpy.loadtxt(fname=filename, delimiter=',') data = numpy.loadtxt(fname=filename, delimiter=',')
...@@ -193,7 +193,7 @@ def detect_problems(filename): ...@@ -193,7 +193,7 @@ def detect_problems(filename):
Wait! Didn't we forget to specify what both of these functions should return? Well, we didn't. Wait! Didn't we forget to specify what both of these functions should return? Well, we didn't.
In Python, functions are not required to include a `return` statement and can be used for In Python, functions are not required to include a `return` statement and can be used for
the sole purpose of grouping together pieces of code that conceptually do one thing. In such cases, the sole purpose of grouping together pieces of code that conceptually do one thing. In such cases,
function names usually describe what they do, _e.g._ `analyze`, `detect_problems`. function names usually describe what they do, _e.g._ `visualize`, `detect_problems`.
Notice that rather than jumbling this code together in one giant `for` loop, Notice that rather than jumbling this code together in one giant `for` loop,
we can now read and reuse both ideas separately. we can now read and reuse both ideas separately.
...@@ -204,7 +204,7 @@ filenames = sorted(glob.glob('inflammation*.csv')) ...@@ -204,7 +204,7 @@ filenames = sorted(glob.glob('inflammation*.csv'))
for f in filenames[:3]: for f in filenames[:3]:
print(f) print(f)
analyze(f) visualize(f)
detect_problems(f) detect_problems(f)
~~~ ~~~
{: .language-python} {: .language-python}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment