jwjacobson / jazztunes

a jazz repertoire management app
https://jazztunes.org
GNU General Public License v3.0
3 stars 1 forks source link

Move basic search to helper function? #108

Closed jwjacobson closed 8 months ago

jwjacobson commented 10 months ago

I've reduplicated the same long block of code in my list and play views, it might be nice just to isolate that out as a basic_search() function that is then called by the relevant views. Is there any downside to this?

bbelderbos commented 10 months ago

Yes, any duplicated code should ideally be abstracted into functions, classes, etc.

Related: Extract Method Refactoring Example in Python: https://www.youtube.com/watch?v=N9sqd1-0_qk

Although checking it now, this video is more about breaking out code into multiple functions, but the principle is the same: take the duplicated code, move it into a new function, remove the other copy, then call the new function in both places.