AlexNavarroLlecha / lab-code-simplicity-efficiency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ironhack logo

Lab | Code Simplicity and Efficiency

Introduction

In the lesson we have learnt a lot of principles and techniques about how to make codes simple and efficient. But it takes a lot of effort to achieve true code simplicity and efficiency. Below are several tips useful for you:

  • Read a lot of source code from community websites such as GitHub and Stack Overview. Learn how top programmers write simple and efficient codes.

  • Iterate your own code. When you are done writing a piece of code, you should always try to improve it even if it's functioning perfectly. Ask yourself whether you can make the code more clean and readable? Whether you can make it more efficient?

  • To make your code perfect is impossible because it will prevent you from delivering the project on time. There is a balance point of how much time you spend on improving the code versus delivering the project. As your programming skills improve, you will spend less and less time on iterating your code.

  • Deepen your knowledge of programming algorithms and keep practicing. A great programmer must possess exellent mathematical and logical thinking abilities which are developed gradually with intensive practice. Use websites such as LeetCode and CodeWars to challenge yourself and improve your solution by comparing with other programmers' solutions.

In this exercise, you will undertake several challenges to practice cleaning code and improving code efficiency. Remeber the tips we gave you above. In certain challenges you may want to google what the more efficient ways are to refactor the code.

Getting Started

Complete the challenges in order in the your-code directory.

Challenge 1-3

In these three challenges you will improve some poorly written Python codes. Reflect on what you have learned in the lesson about code simplicity and efficiency then revamp the codes. Please use comments between the Python lines to explain why you refactor the code that way.

Despite the poor practice in those Python codes, they are fully functional. To run the Python code in command line, navigate to the your-code directory containing the Python files, then execute (note we are using Python 3 interpreter instead of 2):

python3
>>> exec(open("challenge-1.py").read())

After refactoring the code you should test your solution to make sure it is still working as expected.

Deliverables

  • challenge-1.py, challenge-2.py and challenge-3.py that contain your refactored code.

  • Make sure you explain your solutions in the deliverables.

Submission

  • Add the deliverables to git
  • Commit your code
  • Push to your fork
  • Create a pull request to the class repo

About


Languages

Language:Python 100.0%