Code simplicity and forethought for reuse. It requires more effort up front, but boy does it ever pay off in the long run! It’s the easiest way to simplify and maintain solutions and along with clever refactoring, is the easiest way to understand the code and make changes or add additional functionality in the future.
I’ve been a personal witness to clean refactored code which has been copied and pasted in each and every Unity Script that requires it. Using the example of 10 Unity Scripts, this means that if a change needs to be made to the common “GetKeywordValue” Extension Method, then you would have to make that change 10 times. Unless you’re paid hourly and enjoy repetitive, time consuming tasks with a high probability for error, you need to become familiar with using Library scripts.
Again, the same lines of code should never be repeated in different codebases. Instead, put these lines of code in a shared library. Library scripts allow you to create a single method which can be called from multiple sources. They allow you to REDUCE the amount of code in that source code and they allow you to efficiently REUSE generic code.
Think now into the future: You are assigned another project which requires you to get the value of a few Keywords on the document. Rather than trying to remember the exact OnBase Unity API methods to call in order to get the Keyword Value or having to rewrite code you’ve already written previously, you can easily call your own “GetKeywordValue” Extension Method that you created back in 2014. Or let’s say you get a new developer on the team that takes on the project. Refactoring and reusing code ensures that all developers in an organization follow the same development pattern and allows these same developers to easily pick up another team member’s code and understand it or make changes.
Sure this specific “GetKeywordValue” example Extension Method is pretty simplistic, but imagine the same concept applied to something more elaborate. You can build a library method that accepts an image document and returns a data stream of a PDF document. You can build another library method that accepts an OnBase document and an n-length Dictionary of Keyword Types and Values and adds those values to the document. In fact, the development team at Kiriworks has already done the latter. We are committed to our own philosophy of reducing, reusing, and refactoring code and it has made a huge impact on our efficiency.