DEV Community

cychu42
cychu42

Posted on

Make It Better: Refacotring Code

What was I up to?

I tried to refactor my code for my static site generator, with this commit.

Changes

  • Rename main file as index.js and update README.md
  • Number options in README.md
  • Improve comments in index.js
  • Change some var to let
  • Rename one of extension variables
  • Use path module for parsing file names
  • Turn html writing closing code into a function
  • Split config variables into config.js
  • Split some functions to parser.js
  • Split html functions to htmlFormat.js
  • Split html writing code to writer.js
  • Move config file to a folder for separation
  • Fix tag missing toward end of html files

Process

I tried to keep a list of things I want to improve and follow it, after going back to look at my code for improvement.
Some items are suggested by other, while some are kept on the list from before. (Sometimes other things take priority and you find yourself out of time to do the improvements for the moment.)

I tried to do interactive rebase to keep the commit history clean for this task. It's fairly smooth as I had some experience before from working in other people's open source projects.
Rebase is where you "re-base" your commits on a specific commit or version of the program, usually in the main branch. Interactive rebase lets you customize how that is handled, such as combining commits together or fixing their messages.
What I did was that I combined all the commits for this task into one single commit in history, using git.

Because I was turning exist code into functions for re-usability and splitting them into different modules, sometimes I just noticed I forgot to supple some variables or functions for the new code blocks. Of course, that broke the program so I had to find out what I was missing and fix that. There's even one time where I supplied some variables from the wrong module and caused the values to be incorrect.

Top comments (0)