Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] refactor to remove duplicated code #65

Open
galyfray opened this issue Nov 4, 2021 · 3 comments
Open

[FEATURE] refactor to remove duplicated code #65

galyfray opened this issue Nov 4, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@galyfray
Copy link
Collaborator

galyfray commented Nov 4, 2021

there is inside of the api many times the same-ish code :

let data = this.someCall()
if(data.status){
    // work
} else {
   // return the error 
}

or

if(this.connectLevel >n){
   //work
}else {
   // return generic error
}

those kind of code are everywhere sometimes in both the api and the application using the api thus finding a way to avoid this duplicated code will improve code clarity as well as quality

proposals :

  • the return object could be enhanced with generic methods like then and else to setup handlers this might have some side effect as sometimes the existence of a then method is used to know if the object can used like a promise
  • a method factory can be used to wrap methods and handle basic tests like the connect level although this will probably be complicated hard to maintain and be a bug factory instead of a method factory. This way may also cause trouble for documentation and completion helper inside some IDEs.
@galyfray galyfray added the enhancement New feature or request label Nov 4, 2021
@lmichel
Copy link
Owner

lmichel commented Nov 4, 2021

I would be cautious with this sort of simplification which could often fall down with specific use cases.
I prefer to push this issue to the lowest priority level.

@lmichel
Copy link
Owner

lmichel commented Nov 4, 2021

The current code is duplicated for sure but it is perfectly readable, which is not necessary the case whith handler subscription.

@galyfray
Copy link
Collaborator Author

galyfray commented Nov 4, 2021

I would be cautious with this sort of simplification which could often fall down with specific use cases.

the main idea is to provide helpers for generic use cases but stay backward compatible so not removing anything thus if a specific use case can be currently achieved it would (and should) still be achievable after the addition of the helpers.

The current code is duplicated for sure but it is perfectly readable, which is not necessary the case with handler subscription.

yes finding a good way to remove duplicated code while keeping it easy to read is easier said than done and might require test of multiple possibilities

@galyfray galyfray changed the title [FEATURE] refacotr to remove duplicated code [FEATURE] refactor to remove duplicated code Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants