tanaponpiti / google-search

0 stars 0 forks source link

Source code organization improvement #21

Closed longnd closed 5 months ago

longnd commented 5 months ago

Issue

This function does the following things:

It results in a lengthy function, making it hard to read. It is sacrificing the readability, maintainability & reusability & testability. By separating the above concerns, each piece of functionality becomes clearer, easier to maintain, easier to test, and more reusable. This also allows other functions to potentially leverage the same sub-functions when needed.

Note that the name of the function CreateKeywordJob is inappropriate as it does not create any jobs, but the keywords and their search results records.

Similar cases can be found at https://github.com/tanaponpiti/google-search/blob/07f6fabc905b388f7d3859a950c95d73a4edc70f/api/service/keyword_service.go#L55

tanaponpiti commented 5 months ago

You are absolutely right. It's a shame that my code violate single responsibility principle, have bad function naming, and multiple validation from place to place. If you wish for me to refactor it, I will try my best.

longnd commented 5 months ago

As mentioned in the first issue

If we are aligned on any issue, and you would like to correct them, please address the issue using a proper git flow (creating a new branch, opening a Pull Request (PR) per issue, and merging the code when you are ready), and I will follow up on those fixes

it's up to you to decide whether to work on a fix. However, in this case I think it isn't too important so no need to spend more time on it.