DEV Community

Discussion on: Do you even refactor, bro?

bluebird1 profile image

This may be a project I have written.I use golang+gin+mysql,But I successfully refactored.

1.extract duplicate code
fisrt extract html templates/css duplicate code,As a separate file. in my project,extract site head and tail. Then use the template to render the code.

Facing confused and duplicate JavaScript code,I used the vue framework,Packaged into components.

2.shorter function
Split/Extract existing big functions,I think the duplicate part of each function is a good target.


duplicate code Means they may need a common parent class (if you don't use an object-oriented language, you should have the same effect).Duplicate code should be moved to the parent class

The best way to code quality is a good architecture.If the current architecture is a junk, try better.

marcus profile image
Marcus Müller

Regarding "1.extract duplicate code":
You can use static code analyzers, most of them free for Open Source Projects, for finding larger blocks of duplicate.
Most of them are very helpful for standard things like missing null checks etc.