DEV Community

Cover image for Lab 5 - Improving my code through refactoring
Jason
Jason

Posted on

Lab 5 - Improving my code through refactoring

Before refactoring, I learned the code structure of other students. I want to improve four features, but I only finished 3 of them before the due time. I have to upload them and the rest I will continue to do it.

  1. split the main file. Before that, all my code was stored in one file. I split it to two files, one store the main function named ssg_main.py. Another is assist file, and it stores all helper functions. Image description
  2. merge get file function. There were two similar functions named get_md_files and get_txt_files. They read two different type files. I merged them into one function, and about 10 lines of statements were saved.Image description
  3. merge output result function. There were two similar functions named output_md_result and output_txt_result. I merged them into one function, and about 5 lines of statements were saved. Image description
  4. Try to use pathlib instead of working with path names as strings. It's not a good idea to work with paths as regular strings because I have to be careful with lots of cross-platform issues, and all of this has been solved with pathlib — Object-oriented filesystem paths. I learned the pathlib, but I didn't modify it successfully before due day. I will continue to do it. Image description
  5. How to rebase. Use $git rebase main -i command, edit 94613fd, 3e7ecc2, 9593d95 from pick to squash. Then use $git commit --amend to combine four commits to one. The last step is merged refactoring to main and push to origin main. Image description
  6. Reflection. At the beginning, I don't fully understand rebase command. I use $ git rebase refactoring -i command, and the terminal can't display all the commit. I should use the main branch to rebase. Image description

Top comments (0)