Improving a Bit by Bit
Tags: java, opensource, staticsitegenerator, refactoring
Published: 2022-09-26 22:21:25

### My Code Has Too much of Duplicates and Poor Readability 
One of my concerns about my code was that I had many overloading functions that took one to three user inputs. They did the same job with little variations. It was very difficult to find an error and update all overloading functions when I add a new functionality. And my `FileUtilities` class got over 400 lines already. Since I'm implementing more option, I decided to do refactoring. Otherwise the code will drive me crazy. 

### Passing an Object to Reduce Overloading Functions
The first task was to create Options class to get rid of overloading functions. After I created the class, I updated all my functions to replace arguments with Options object. Then, I compared my old functions and new functions that is simplified with `Options` class to see where to reuse and what to add. I felt I was fixing machine's old parts with new parts. It was a pretty fun task, although I needed some determination to change my working code. I know Working code is not enough. After a couple of hours, my code got much more streamlined. I was very happy that I could remove many lines of those overloading functions. 

### Try to Make the Class Do One Job
And the next task is to split some of `FileUtilities` functions so that my `FileUtilities` class does only one job. So I created `Parser` class and moved the translation parts to that class. Now my `FileUtilities` class became almost half of what it was. It's much easier to read as I have only one function to do the job. Also I moved all implementation files to `/src` folder. I did some tests to make sure everything is working fine, then I pushed my updated code to GitHub with a lot of job. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grrcb15zyl3i5hf6ywet.png)*Now my code split down to more manageable size!*

### Refactoring Makes the Job Easier
So now adding a new feature becomes much easier. I didn't have to write duplicate code all over. Also, I broke down HTML element strings so that anyone can easily understand what is being written to the file. This way it will be easier  where to look at to add a certain element or attribute to the HTML. 

### Still in the Way of Learning Git...
I opened three issues to add `--lang` option, markdown code and horizontal parsing capabilities. These issues are small enough to implement. I completed and tested each issue and moved on to next. So it's time to merge these issues! First issue didn't have any problem, but the second one had a conflict. I had some experiences of fixing conflict. I used GitHub desktop and VS Code to handle conflicts. But somehow I couldn't get a conflict info pop-up on GitHub desktop app. Then I accidentally pulled remote repo code. I know I should understand what I'm doing before forcing it to do something in Git. I make similar Git mistakes often times. I had to manually recover my test file folders and IntelliJ config files since they are not in the remote repo, either in my local. I have learned much better knowledge about Git, but I still need to have more fundamentals to better use Git.