From c9213002cee7dc89be4be670889cb7893ca3750a Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Tue, 16 Mar 2021 15:18:19 +0200 Subject: [PATCH] refactoring --- python/examples/refactor/bad_variable.py | 4 ++++ python/examples/refactor/good_variable.py | 4 ++++ python/python.json | 2 +- python/refactor.md | 8 -------- python/refactoring.md | 22 ++++++++++++++++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 python/examples/refactor/bad_variable.py create mode 100644 python/examples/refactor/good_variable.py delete mode 100644 python/refactor.md create mode 100644 python/refactoring.md diff --git a/python/examples/refactor/bad_variable.py b/python/examples/refactor/bad_variable.py new file mode 100644 index 000000000..cee999b1c --- /dev/null +++ b/python/examples/refactor/bad_variable.py @@ -0,0 +1,4 @@ +data = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'] +for i in data: + print(i) + diff --git a/python/examples/refactor/good_variable.py b/python/examples/refactor/good_variable.py new file mode 100644 index 000000000..ad71ba1ad --- /dev/null +++ b/python/examples/refactor/good_variable.py @@ -0,0 +1,4 @@ +celestical_objects = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn'] +for planet in celestical_objects: + print(planet) + diff --git a/python/python.json b/python/python.json index 57d32d9f8..28c6a7153 100755 --- a/python/python.json +++ b/python/python.json @@ -109,7 +109,7 @@ "algorithm.md", "scapy.md", "turtle.md", - "refactor.md", + "refactoring.md", "other.md" ] } diff --git a/python/refactor.md b/python/refactor.md deleted file mode 100644 index 4cac4969d..000000000 --- a/python/refactor.md +++ /dev/null @@ -1,8 +0,0 @@ -# Refactor -{id: refactor} - -## Exercise: Fix deep indentation -{id: exercise-fix-deep-indentation} - -![](examples/refactor/remove_deep_indentation.py) - diff --git a/python/refactoring.md b/python/refactoring.md new file mode 100644 index 000000000..ebd8809f4 --- /dev/null +++ b/python/refactoring.md @@ -0,0 +1,22 @@ +# Refactor +{id: refactor} + +## Refactoring example - change variable name +{id: refactoring-change-variable-name} + +![](examples/refactor/bad_variable.py) + +![](examples/refactor/good_variable.py) + +## How to Refactor +{id: how-to-refactor} + +* Write tests that will verify the behaviour (or at least compare the new behavior to the old behavior) +* Make a small change. +* Run the tests. + +## Exercise: Fix deep indentation +{id: exercise-fix-deep-indentation} + +![](examples/refactor/remove_deep_indentation.py) +