Re:Building a BitTorrent client from scratch in C#
by cheatdeath on Wednesday July 06, 2016 @02:52AM
(#12041582)
Thanks for the comments! I'm all for improved readability. I definitely wasn't aiming for much performance wise, at least initially. These were two areas (of many) that I felt could do with some improvement (especially the file IO). I will look into making some modifications like those suggested when I get a chance.
Take this for example:
You have an automatic property and two 'properties' that actually perform work every time you call the getter (might be smarter to make functions of those, so you know it's not just retrieval of data, but work is done).If you were to rewrite this a bit, you could make sure the 'work' is done only when needed, and the properties become actual simple data retrieval properties like:
Going further through the article, I spot many more items to improve; but let's not forget your did great work and the code is quite readable.One thing that might help; is building some indexes to know how files are fragmented; you have the following code multiple times:
If you'd build an index to know which piece hits which files, you don't have to enumerate this every time.Another general remark is to always 'retrieve' an indexed item from the array and use that instead of keep calling the 'indexed' record.
So; do:
The code becomes more readable and allows you to change the structure later on more easily since you don't have 100 references tot he same array now and only use an itermediate.