Skip to content

Commit 4289e5b

Browse files
committed
fix(links): more broken links
1 parent 891b4e8 commit 4289e5b

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed
File renamed without changes.

clean-modular-code/python-functions.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ Modularity means that code is separated into independent units that can be reuse
4646

4747
:::{figure} /images/clean-code/functions-for-all-things.png
4848
:alt: You can implement strategies such as loops and functions in your code to replace tasks that you are performing over and over. Source: Francois Michonneau.
49-
:target: /images/clean-code/write-functions-for-all-things.png
49+
:target: /images/clean-code/functions-for-all-things.png
5050

5151
You can use loops and functions in your code to replace repeating tasks.
5252
Source: Francois Michonneau.
5353
:::
5454

55-
## The Benefits of Functions
55+
## The benefits of functions
5656

5757
* Modularity: Functions only need to be defined once in a workflow. Functions that you write for specific tasks can be used over and over, without needing to redefine the function again. A function that you write for one **Python** workflow can also be reused in other workflows especially if you make your code installable.
5858

@@ -64,7 +64,7 @@ Source: Francois Michonneau.
6464

6565
* Tests & checks: Writing functions allows you you to your code to handle issues and edge cases in your code. It also can make it easier to write tests for your code.
6666

67-
### Write Modular Functions and Code
67+
### Write modular functions and code
6868

6969
A well-defined function only does one thing, but it does it well and often in various contexts. Often, the operations contained in a good function are generally useful for many tasks.
7070

@@ -84,58 +84,57 @@ np.mean(arr)
8484
```
8585

8686
<!-- #region editable=true slideshow={"slide_type": ""} -->
87-
The `np.mean()` function is modular, and it can be easily combined with other functions to accomplish a variety of tasks.
87+
The `np.mean()` function is modular, and it can be easily combined with other functions to accomplish various tasks.
8888

8989
When you write modular functions, you can reuse them for other workflows and projects. Some people even write their own **Python** packages for personal and professional use that contain custom functions for tasks that they have to complete regularly.
9090

91-
### Functions Create Fewer Variables
91+
### Variables produced in functions are discarded after the function runs
9292

93-
When you code tasks line by line, you often create numerous intermediate variables that you do not need to use again.
93+
When coding tasks step by step, you are likely creating many intermediate variables that are not needed again but are
94+
stored in your computer's memory.
9495

95-
This is inefficient and can cause your code to be repetitive, if you are constantly creating variables that you will not use again.
96+
By using functions, these intermediate variables are confined to the function’s local scope. Once the function finishes executing, the variables created within the function are discarded making your code cleaner and more efficient
9697

97-
Functions allow you to focus on the inputs and the outputs of your workflow, rather than the intermediate steps, such as creating extra variables that are not needed.
98+
## Reasons why functions improve code readability
9899

99-
## Reasons Why Functions Improve Code Readability
100+
### Functions help you document your code
100101

101-
### Functions Can Result in Better Documentation
102+
Ideally, your code is easy to understand and is well-documented with **Python** comments (or **Markdown** in **Jupyter Notebook**). However, what might seem clear to you now might not be clear 6 months from now, or even 3 weeks from now.
102103

103-
Ideally, your code is easy to understand and is well-documented with **Python** comments (and **Markdown** in **Jupyter Notebook**). However, what might seem clear to you now might not be clear 6 months from now, or even 3 weeks from now.
104+
Well-written functions help you document your workflow if:
104105

105-
Well-written functions help you document your workflow because:
106+
* They have clear docstrings that outline the function's inputs and outputs.
107+
* They use descriptive names that clearly describe the task that the function performs.
106108

107-
* They are well-documented by clearly outlining the inputs and outputs.
108-
* They use descriptive names that help you better understand the task that the function performs.
109-
110-
### Expressive Function Names Make Code Self-Describing
109+
### Expressive function names make code self-describing
111110

112111
When writing your own functions, you should name functions using verbs and/or clear labels to indicate what the function does (i.e. `in_to_mm` for converting inches to millimeters).
113112

114113
This makes your code more expressive (or self-describing), and in turn, makes it easier to read for you, your future self, and your colleagues.
115114

116-
### Modular Code is Easier to Maintain and Edit
115+
### Modular code is easier to maintain and edit
117116

118117
If all your code is written line by line (with repeated code in multiple parts of your document) it can be challenging to maintain and edit.
119118

120119
Imagine having to fix one element of a line of code that is repeated many times. You will have to find and replace that code to implement the fix in EVERY INSTANCE it occurs in your code!
121120

122-
You may also be duplicating your comments where you duplicate parts of your code. So how do you keep the duplicated comments in sync?
121+
Repeated code cause you to duplicated comment. So how do you keep the duplicated comments in sync?
123122

124-
A comment that is misleading because the code changed is actually worse than no comment at all.
123+
A comment that is misleading because the code changed is worse than no comment.
125124

126125
Organizing your code using functions from the beginning allows you to explicitly document the tasks that your code performs, as all code and documentation for the function is contained in the function definition.
127126

128-
### You Can Incorporate Testing To Ensure Code Runs Properly
127+
### Functions and tests
129128

130-
While you will not learn about testing in this chapter, note that functions are also very useful for testing.
129+
While you will not learn about testing in this lessons, note that functions are also very useful for testing.
131130

132131
As your code gets longer and more complex, it is more prone to mistakes. For example, if your analysis relies on data that gets updated often, you may want to make sure that all the columns in your spreadsheet are present before performing an analysis. Or, that the new data are not formatted in a different way.
133132

134133
Changes in data structure and format could cause your code to not run. Or, in the worse case scenario, your code may run but return the wrong values!
135134

136135
If all your code is made up of functions (with built-in tests to ensure that they run as expected), then you can control the input to the function and test that the output returned is correct for that input. It is something that would be difficult to do if all of your code is written line by line with repeated steps.
137136

138-
## Summary of Writing Modular Code with Functions
137+
## Summary of writing modular code with functions
139138

140139
It is a good idea to learn how to:
141140

0 commit comments

Comments
 (0)