|
| 1 | +# Refactoring / Pythonic code |
| 2 | + |
| 3 | +In [this lesson's notebook](https://github.com/talkpython/100daysofcode-with-python-course/blob/master/days/34-36-refactoring/refactoring.ipynb) I will show you 10 ways to improve your Python code. |
| 4 | + |
| 5 | +This is by no means a complete list, just some tips to get you started. The more time you spend with Python the more patterns you start to recognize and the more elegant your code will become. |
| 6 | + |
| 7 | +## Day 1: Study the materials |
| 8 | + |
| 9 | +Go through the 10 refactoring tips: |
| 10 | + |
| 11 | +1. The problem with big if-elif-else constructs |
| 12 | +2. Counting inside a loop |
| 13 | +3. Use the with statement to deal with resources |
| 14 | +4. Use builtins (learn the stdlib!) |
| 15 | +5. Leverage tuple unpacking and namedtuples |
| 16 | +6. List comprehensions and generators |
| 17 | +7. String formatting and concatenation |
| 18 | +8. PEP8 and Zen |
| 19 | +9. Explicit is better than implicit |
| 20 | +10. (bonus) General coding best practices |
| 21 | + |
| 22 | +There are also some additional resources in the notebook. |
| 23 | + |
| 24 | +Ideally you combine this lesson with [Day 10-12 `pytest`](https://github.com/talkpython/100daysofcode-with-python-course/tree/master/days/10-12-pytest) to get in the habit of writing tests before doing any refactorings. |
| 25 | + |
| 26 | +## Day 2 and 3: Refactor your code |
| 27 | + |
| 28 | +Take our [Blog Code Challenge 30: The Art of Refactoring: Improve Your Code](https://codechalleng.es/challenges/30/) |
| 29 | + |
| 30 | +Check out [the notebook](https://github.com/talkpython/100daysofcode-with-python-course/blob/master/days/34-36-refactoring/refactoring.ipynb) for further instructions. |
| 31 | + |
| 32 | +## Time to share what you've accomplished! |
| 33 | + |
| 34 | +Be sure to share your last couple of days work on Twitter or Facebook. Use the hashtag **#100DaysOfCode**. |
| 35 | + |
| 36 | +Here are [some examples](https://twitter.com/search?q=%23100DaysOfCode) to inspire you. Consider including [@talkpython](https://twitter.com/talkpython) and [@pybites](https://twitter.com/pybites) in your tweets. |
| 37 | + |
| 38 | +See a mistake in these instructions? Please [submit a new issue](https://github.com/talkpython/100daysofcode-with-python-course/issues) or fix it and [submit a PR](https://github.com/talkpython/100daysofcode-with-python-course/pulls). |
0 commit comments