Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRefactor lib/torrent.js #436
Comments
This comment has been minimized.
This comment has been minimized.
|
I agree that Improving method naming would help. We don't need to worry about renaming private methods that start with A larger, but more impactful task would be to pull out the torrent downloading "strategies" into their own npm packages. There are currently two strategies ("sequential" and "rarest-first") and that code is some of the messiest. Another advantage, we can send a PR to |
This comment has been minimized.
This comment has been minimized.
|
@feross I have been working on documenting all the methods of torrent.js so that I can more easily follow whats happening. Perhaps after that I'll attempt to refactor the strategies. I need to keep looking through to figure out how everything works before I would feel comfortable pulling everything out. I'll do a PR on the docs, first though. |
This comment has been minimized.
This comment has been minimized.
|
@ericwooley Great, happy to look at that PR and merge it if it makes things easier to understand. |

I have spent a few hours tonight digging through torrent.js attempting to learn enough to change the hashing algorithm, for #430 (comment)
Torrent.js is 1264 lines long, and many of the methods are named after what calls them instead of what they do. I would recommend refactoring and renaming the methods to describe what they do instead of what calls them. Normally this wouldn't be too much of an issue, but given the vastness of the file, it becomes very hard to follow the algorithm when the method names describe what calls them instead of what they do.
I would recommend splitting the file up, but you guys have already done a great job of abstracting functions. A large file may be something that needs to be lived with.
I am not sure what the ramifications would be in renaming the methods, in terms of breaking changes. Many of them are named with an _ implying they are private. But maybe they are used elsewhere anyway?
Maybe defining them like
Would be an acceptable means of renaming the methods, without introducing breaking changes?