Skip to content

Commit 1a88b94

Browse files
committed
🎨 Make Workbench formatting changes for section 3
1 parent 7c22e79 commit 1a88b94

File tree

2 files changed

+90
-98
lines changed

2 files changed

+90
-98
lines changed

episodes/30-section3-intro.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,25 @@ and look at the bigger picture of software as a *process* of development.
2525

2626
> *"If you fail to plan, you are planning to fail."* - Benjamin Franklin
2727
28-
{% comment %}
29-
![](fig/section3-overview.png){alt='Software design and architecture' .image-with-shadow width="800px" }
30-
{% endcomment %}
28+
![](fig/section3-overview.svg){alt='Software design and architecture overview flowchart'}
3129

32-
![](fig/section3-overview.svg){alt='Software design and architecture' .image-with-shadow width="1000px" }
33-
{% comment %}
34-
flowchart LR
35-
A(1. Setting up
36-
software environment)
37-
\--> B(2. Verifying
38-
software correctness)
39-
\--> C(3. Software development
40-
as a process
41-
42-
```
43-
- Software requirements
44-
- Software architecture & design
45-
- Programming paradigms
46-
)
47-
```
48-
49-
\--> D(4. Collaborative
50-
development for reuse)
51-
\--> E(5. Managing software
52-
over its lifetime)
30+
<!---
31+
Source of the above image can be rendered in the Mermaid live editor:
5332
5433
<https://mermaid.live/edit#pako:eNplkU1rwzAMhv-K8WGk0Ab2dclhsLW9rTBW2GH4oiVKakikTJZTSul_n9M122A-2dKj95Wsoy25QlvYuuV9uQNR8_zq6DG7zs0WVT01JvaOAte6B0GDNHhh6pB05mixeDBP2U1u3lB8fUj0H7RkESyVMIQLusxuk-yUr3DAlvtRyhEEA6YXLhPtyJFJZ_HLCn5GLziy4V8SpNx5TVYxPa6SbvDNj8SLcCPQdeMkPQhUvukuEpeuVtldbpbctvDBAuoHdPSnN1OzJP8Y8MKvs_vcbICgGTWncR3xgGK8BtP6GtV3OLNz26F04Kv0w8fR1FndpSmcLdK1whpiq846OiUUovL2QKUtVCLObewrUFx5GPu3RQ1tSFGsvLJsvrd2Xt5Ers-ZqboHemee6k5flmapmQ>
55-
{% endcomment %}
34+
35+
The mermaid source (with one less dash in arrows than needed):
36+
37+
flowchart LR
38+
A(1. Setting up software environment)
39+
A -> B(2. Verifying software correctness)
40+
B -> C(3. Software development as a process
41+
- Software requirements
42+
- Software architecture & design
43+
- Programming paradigms)
44+
C -> D(4. Collaborative development for reuse)
45+
D -> E(5. Managing software over its lifetime)
46+
-->
5647

5748
## Writing Code vs Engineering Software
5849

episodes/34-code-refactoring.md

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -281,49 +281,52 @@ i.e. their tests are:
281281
- **easier to maintain** - if at some point the data format changes
282282
from CSV to JSON, the bulk of the tests need not be updated
283283

284-
> ## Exercise: Testing a Pure Function
285-
>
286-
> Add tests for `compute_standard_deviation_by_data()` that check for situations
287-
> when there is only one file with multiple rows,
288-
> multiple files with one row, and any other cases you can think of that should be tested.
289-
>
290-
> > ## Solution
291-
> >
292-
> > You might have thought of more tests, but we can easily extend the test by parametrizing
293-
> > with more inputs and expected outputs:
294-
> >
295-
> > ```python
296-
> > @pytest.mark.parametrize('data,expected_output', [
297-
> > ([[[0, 1, 0], [0, 2, 0]]], [0, 0, 0]),
298-
> > ([[[0, 2, 0]], [[0, 1, 0]]], [0, math.sqrt(0.25), 0]),
299-
> > ([[[0, 1, 0], [0, 2, 0]], [[0, 1, 0], [0, 2, 0]]], [0, 0, 0])
300-
> > ],
301-
> > ids=['Two patients in same file', 'Two patients in different files', 'Two identical patients in two different files'])
302-
> > def test_compute_standard_deviation_by_day(data, expected_output):
303-
> > from inflammation.compute_data import compute_standard_deviation_by_data
304-
> >
305-
> > result = compute_standard_deviation_by_data(data)
306-
> > npt.assert_array_almost_equal(result, expected_output)
307-
> > ```
284+
::: challenge
285+
## Exercise: Testing a Pure Function
308286

287+
Add tests for `compute_standard_deviation_by_data()` that check for situations
288+
when there is only one file with multiple rows,
289+
multiple files with one row, and any other cases you can think of that should be tested.
290+
291+
:::: solution
292+
293+
You might have thought of more tests, but we can easily extend the test by parametrizing
294+
with more inputs and expected outputs:
295+
296+
```python
297+
@pytest.mark.parametrize('data,expected_output', [
298+
([[[0, 1, 0], [0, 2, 0]]], [0, 0, 0]),
299+
([[[0, 2, 0]], [[0, 1, 0]]], [0, math.sqrt(0.25), 0]),
300+
([[[0, 1, 0], [0, 2, 0]], [[0, 1, 0], [0, 2, 0]]], [0, 0, 0])
301+
],
302+
ids=['Two patients in same file', 'Two patients in different files', 'Two identical patients in two different files'])
303+
def test_compute_standard_deviation_by_day(data, expected_output):
304+
from inflammation.compute_data import compute_standard_deviation_by_data
305+
306+
result = compute_standard_deviation_by_data(data)
307+
npt.assert_array_almost_equal(result, expected_output)
309308
```
310-
> {: .solution}
311-
{: .challenge}
312-
313-
> ## Functional Programming
314-
> **Functional programming** is a programming paradigm where programs are constructed by
315-
> applying and composing/chaining pure functions.
316-
> Some programming languages, such as Haskell or Lisp, support writing pure functional code only.
317-
> Other languages, such as Python, Java, C++, allow mixing **functional** and **procedural**
318-
> programming paradigms.
319-
> Read more in the [extra episode on functional programming](../functional-programming/index.html)
320-
> and when it can be very useful to switch to this paradigm
321-
> (e.g. to employ MapReduce approach for data processing).
322-
{: .callout}
323-
324-
325-
There are no definite rules in software design but making your complex logic out of
326-
composed pure functions is a great place to start when trying to make your code readable,
309+
310+
::::
311+
:::
312+
313+
::: callout
314+
315+
## Functional Programming
316+
317+
**Functional programming** is a programming paradigm where programs are constructed by
318+
applying and composing/chaining pure functions.
319+
Some programming languages, such as Haskell or Lisp, support writing pure functional code only.
320+
Other languages, such as Python, Java, C++, allow mixing **functional** and **procedural**
321+
programming paradigms.
322+
Read more in the [extra episode on functional programming](../learners/functional-programming.md)
323+
and when it can be very useful to switch to this paradigm
324+
(e.g. to employ MapReduce approach for data processing).
325+
326+
:::
327+
328+
There are no definite rules in software design but making your complex logic out of
329+
composed pure functions is a great place to start when trying to make your code readable,
327330
testable and maintainable. This is particularly useful for:
328331

329332
* Data processing and analysis
@@ -339,46 +342,46 @@ which are characteristics of (but not limited to) the object-oriented programmin
339342
In this episode, we mentioned [pure functions](./index.html#pure-functions)
340343
and Functional Programming.
341344

342-
These are examples of different [programming paradigms](/programming-paradigms/index.html)
345+
These are examples of different [programming paradigms](../learners/programming-paradigms.md)
343346
and provide varied approaches to structuring your code -
344347
each with certain strengths and weaknesses when used to solve particular types of problems.
345348
In many cases, particularly with modern languages, a single language can allow many different
346349
structural approaches and mixing programming paradigms within your code.
347-
Once your software begins to get more complex - it is common to use aspects of [different paradigm](../programming-paradigms/index.html)
350+
Once your software begins to get more complex - it is common to use aspects of [different paradigm](../learners/programming-paradigms.md)
348351
to handle different subtasks.
349-
Because of this, it is useful to know about the [major paradigms](../programming-paradigms/index.html),
352+
Because of this, it is useful to know about the [major paradigms](../learners/programming-paradigms.md),
350353
so you can recognise where it might be useful to switch.
351354
This is outside of scope of this course - we have some extra episodes on the topics of
352-
[procedural programming](../procedural-programming/index.html),
353-
[functional programming](../functional-programming/index.html) and
354-
[object-oriented programming](../object-oriented-programming/index.html) if you want to know more.
355-
356-
> ## So Which One is Python?
357-
> Python is a multi-paradigm and multi-purpose programming language.
358-
> You can use it as a procedural language and you can use it in a more object oriented way.
359-
> It does tend to land more on the object oriented side as all its core data types
360-
> (strings, integers, floats, booleans, lists,
361-
> sets, arrays, tuples, dictionaries, files)
362-
> as well as functions, modules and classes are objects.
363-
>
364-
> Since functions in Python are also objects that can be passed around like any other object,
365-
> Python is also well suited to functional programming.
366-
> One of the most popular Python libraries for data manipulation,
367-
> [Pandas](https://pandas.pydata.org/) (built on top of NumPy),
368-
> supports a functional programming style
369-
> as most of its functions on data are not changing the data (no side effects)
370-
> but producing a new data to reflect the result of the function.
371-
{: .callout}
355+
[procedural programming](../learners/procedural-programming.md),
356+
[functional programming](../learners/functional-programming.md) and
357+
[object-oriented programming](../learners/object-oriented-programming.md) if you want to know more.
358+
359+
::: callout
360+
361+
## So Which One is Python?
362+
363+
Python is a multi-paradigm and multi-purpose programming language.
364+
You can use it as a procedural language and you can use it in a more object oriented way.
365+
It does tend to land more on the object oriented side as all its core data types
366+
(strings, integers, floats, booleans, lists,
367+
sets, arrays, tuples, dictionaries, files)
368+
as well as functions, modules and classes are objects.
369+
370+
Since functions in Python are also objects that can be passed around like any other object,
371+
Python is also well suited to functional programming.
372+
One of the most popular Python libraries for data manipulation,
373+
[Pandas](https://pandas.pydata.org/) (built on top of NumPy),
374+
supports a functional programming style
375+
as most of its functions on data are not changing the data (no side effects)
376+
but producing a new data to reflect the result of the function.
377+
:::
372378

373379
## Software Design and Architecture
374380

375-
In this section so far we have been talking about **software design** - the individual modules and
376-
components of the software. We are now going to have a brief look into **software architecture** -
377-
which is about the overall structure that these software components fit into, a *design pattern*
378-
with a common successful use of software components.
379-
380-
{% include links.md %}
381-
```
381+
In this section so far we have been talking about **software design** - the individual modules and
382+
components of the software. We are now going to have a brief look into **software architecture** -
383+
which is about the overall structure that these software components fit into, a *design pattern*
384+
with a common successful use of software components.
382385

383386
:::::::::::::::::::::::::::::::::::::::: keypoints
384387

@@ -387,5 +390,3 @@ with a common successful use of software components.
387390
- Using pure functions that process data without side effects whenever possible makes the code easier to understand, test and maintain.
388391

389392
::::::::::::::::::::::::::::::::::::::::::::::::::
390-
391-

0 commit comments

Comments
 (0)