Coffeehouse Post

Single Post Permalink

View Thread: General Programmer Question : how much do you reuse code/classes?
  • User profile image

    @Dr Herbie:

    Hi Herbie,

    I think the type of projects you work on can have a more than small influence on how reusable your code is.

    For example, at my company, I run the development teams and we're a large e-commerce operation. So we have our main e-commerce sites, additional micro-ecommerce sites, internal merchandising/reporting apps etc, our main back end order processing apps as well as web api's for additional vendor apps and other things all of which talk to each other to a greater or lesser extent.

    So, we have built layers of reusability across a lot of our software. Essentially we've thrown the most common things we do into a set of internal API's that are fully documented.
    At the basic level we have things like simple helper classes that wrap up the most commonly used areas of, caching of data, putting things into Azure blob storage, etc. The idea there is our developers can connect to one of our databases, call a stored procedure and get back a dataset with a single line of code and as long as that particular API is used, vs. doing it all manually through then we have consistency. We know that there's going to be try... catch... finally around the actual work, that the correct data connection is used etc.

    On top of that we have an additional layer for getting/putting data - so if the developer needs to get XX products in a group or do a keyword search for YYY items, then he/she calls the data request layer. This layer worries about if the data is already cached or not, if not then it knows where to get the data (database/blob storage/table storage/etc), put it into the cache for the correct amount of time and return it to the developer as the correct collection type expected and not just a dataset.

    All of this allows us to make sure that we have standard consistent ways of doing our most common things - so the end developer doesn't have to worry as much about the runtime performance of getting their data - if there's a method in our API for getting what they need, then we've already done the performance work on it. It's more work up front, but it covers around 75% of what our developers need to do - so it's been worth it and allows them to focus on the other 25% and give more attention to Win UI/web design work.

    As for my own personal projects - I have a fair bit of reusable classes I dip into as well for very common things I do a lot. Once again, data access, caching are covered there along with things like editing images, putting things into Azure blob storage and so on. I have a few websites, mobile apps and other things I work on in my free time, so code reuse makes sense for me. If I were just working on one large project only though, I probably wouldn't have so much reuse in there.