3 ms·
Why not write an interface for getting the radius and a radius sorter for sorting on that interface? I made a modified version of your code to illustrate. http
by jhalderman 10y ago
Why not write an interface for getting the radius and a radius sorter for sorting on that interface? I made a modified version of your code to illustrate.
https://play.golang.org/p/Ya7tUhDnO2 https://play.golang.org/p/Ya7tUhDnO2
*edited a typo
- junke 10y agoThanks a lot for your example. I would certainly take this approach and I am happy that you took the time to write it. I feel a little sorry for you because I put a trap for the parent poster in the original code. I wrote "a[j] < a[i]". You "fixed" it while refactoring, which would be the good thing to do if I made a typo. If however I really wanted to sort circles differently from planets, then you made an error while refactoring what looked like copy-pasta but wasn't. My original point was that when you "have" to copy-paste, you cannot clearly see what is or isn't part of the copy and what is new. You found a way to rewrite the code without much copy- pasting, and I am happy to see that. Still, in other places where code duplication arise, there could be similar problems from a maintenance point of view.