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

Refactor the MFAssignCHO module #19

Open
hechth opened this issue Dec 11, 2023 · 0 comments
Open

Refactor the MFAssignCHO module #19

hechth opened this issue Dec 11, 2023 · 0 comments
Assignees

Comments

@hechth
Copy link
Member

hechth commented Dec 11, 2023

As the function is really long and the code is hard to read, the function should be refactored so that it also becomes easier to re-use code and extend the module in the future.

It also seems that some code from the IsoFiltR is copy-pasted in the MFAssignCHO module, so it is worth checking where code was potentially taken from or whether some steps might already be contained in other functions.

While refactoring, the following procedure often makes sense. After every change, unit tests should be run to make sure that the code still does the same

  • format the code
  • remove not used variables - the vscode syntax highlighting can help with this
  • try to reduce the number of temporary variables used etc.
  • rename variables which have bad names!
  • extract functions - this can be sometimes a bit tricky
    • often there are pieces of code which as a result, change a single variable. many new variables might be defined in that section but never used again. These pieces of code are great candidates to be extracted into functions. Start checking for those first. You can see whether a symbol (aka variable) is used using the "find all references" operation in vscode.
    • large if/else blocks often as a result should be two functions. If they return the same variable, you could use ternary assignment to initialize the variable.
    • contents of loops. this can be tricky due to the way how results are combined.

When extracting functions. the best way is to refactor layer by layer. Look at the top level function and see if you can see multiple things happening at the same level which are the overarching steps. Basically, try to split the highest layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants