remove classtool from Address, VersionedData, EncodedData #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Classtool provides two particularly useful features: 1) allowing to overload dependencies in a class, 2) allowing a default instance of a class. However, it is unfriendly to new developers. One solution to this is to make classtool itself a little bit friendlier, as in @gasteve's soop. Another solution, explored here, is to remove classtool and rely on more traditional solutions to the same problems that do not require any dependencies at all.
In this PR I have removed classtool from Address, VersionedData, and EncodedData, which are all related classes. I have also updated the code to fix all tests. I have not removed classtool from other classes. The purpose of this PR is to demonstrate the feasibility of removing classtool and spark a discussion about removing classtool in the interests of making bitcore more friendly to new developers. This PR should not actually be pulled in unless we can all agree that removing classtool is the best option, and in that case the entire codebase should be updated to remove the classtool dependency.
For the record, here is an example of code that overloads dependencies of a class in a way that does not require classtool and is familiar to all javascript developers. The dependency being overloaded here is the database, which is replaced with a mockup database for the purpose of a test:
Hat tip to @kyledrake for suggesting this option and writing some proof-of-concept code.