DEV Community

Yuan-Hsi Lee
Yuan-Hsi Lee

Posted on

Review, and write something better

This post will be mainly talking about fixing my old PR. In my previous blog posts, I mentioned that I plan to redo a previous PR that I submitted but didn't get merged.

I've started coding for about 2 years. In these 2 years, I focused more about giving the solution and make the program work. I seldom look back to my code and review it. However, to become a developer, having the ability to write clean, quality code is critical.

In my last blog post, I mentioned that my old commit in this PR was duplicate and messy. The changes I make in the new commit accomplish the same functionalities, but it improves the code to be more maintainable and understandable. For example, instead of using letters 'l', 'e', 'i', to represent the image sizes of 'large', 'medium', and 'icon', I use an array object to store the value of these 3 image sizes. It is more readable and better for trouble-shooting.

// store the value into an array of objects
const sizeOptions = {
  LARGE: { value: 0, name: 'Large', code: 'l' },
  MEDIUM: { value: 1, name: 'Medium', code: 'e' },
  ICON: {value: 2, name: 'Icon', code: 'i' }
};
// call the object.code value to replace the old letter 'l'
switch (size) {
  // case 'l': // <-- the old one
  case sizeOptions.LARGE.code: // <-- the improved one
  // ...
}
Enter fullscreen mode Exit fullscreen mode

After graduation, we'll be working on real projects instead of school work. For school work, we usually don't need to maintain the code after the submission. However, that's not how the system work. When we're doing a real project, we need to keep the application work until the client doesn't need it, which means we'll be facing different issues and be required to fix them often. That's why we need to keep our code easy to maintain. Moreover, we'll be working with other developers. We'll need to follow certain coding style and convention, and we certainly don't want to make other developers waste their time to understand our code logic or style.


Compare with the last time, the repo owner seems to be satisfied with my new changes instead of asking for many change requests. I believe my PR will be merged this time. In the future, I'll spend more time studying about writing quality code and reviewing my code.

Top comments (0)