As most of developers, I try to create as much reusable code as possible. But in reality, I rarely use my code again. I could easily say that less than 5% of my code will be reused in the future.<p>I wonder how it looks for other people, is it worth to make your code reusable in the first place?
Random Wordpress website - 50-75% reuse - most generic sites are the same - upload a theme I've used in the past, change colors, some layout, images, etc... saves a lot of time to have a vetted baseline<p>Custom CMS - 100% reuse - always start with a rolling base and constantly improving it though WP sites have cut into this - people think WP is better - get what you pay for.<p>Random 1-offs - how many times I've had to build a newsletter system... Base system gets copied and installed with specifics changed - where to pull the email list from, mailgun or aws for sending, etc...<p>Server config could be considered "code reuse" - I'll almost always refer to another server I built or run myself to copy apache / php / whatever config sections as a starting point.
How often? Daily!<p>I do a lot of HTML/CSS specialist stuff, writing a lot of front-end interactivity from scratch. I maintain a list of snippets that have helped me and others.<p><a href="https://gist.github.com/tomhodgins/27c29ecb4aceaefe5cdf" rel="nofollow">https://gist.github.com/tomhodgins/27c29ecb4aceaefe5cdf</a><p>Any code I have re-used three or four times ends up getting cleaner each time I work with it, and if it has proved useful a handful of times I add it to list of Snippets :)<p>Lately I have also been building teeny tiny HTML pages that illsutrate one concept clearly.<p>Here's my demo of how to harness multitouch cursors with plain JavaScript: <a href="http://staticresource.com/touches.html" rel="nofollow">http://staticresource.com/touches.html</a> or heres another demo that illustrates JavaScript's Math.random() <a href="http://staticresource.com/marbles.html" rel="nofollow">http://staticresource.com/marbles.html</a><p>Little pages like that serve as reminders, teaching tools, and provide a quick reference for me when I want to re-use similar concepts in another project, without looking up what other people are doing or grabbing the trendy Framework du jour.
Straight up reuse - very rarely. But fairly often I'll just go "ohhh i've done smth like that in that other project" and just go look at the code, paste it in, play around a bit. More about getting into the zone and having the past experiences pop back into the mind rather than reusing code.
Try to structure your problems as: If a pre-existing library existed to solve my problem, what would it look like?<p>Then, go and create that library. You'll get more reuse (and better test coverage, maintainability, open-source ability) than just making spaghetti code every time.
5% reuse is low, although it probably depends on what exactly you're working on. One approach is to make as much of your code into libraries as possible. This works especially well if you're making new applications using the same framework, although it's still valuable if you're maintaining an application. I've also found that separating the ui into partial views can save a lot of time, especially if you can reuse some of them for other projects. A third option is to make some functions that you use by convention. For example if you're using Selenium for testing there are 15+ ways to find something on a webpage. Choose 5 and only use those.
The huge advantage of making reusable code, even if you never reuse it, is that it's clean and decoupled from the other parts of your application.
Thus it'll be easier to understand and to deal with - you won't have to look over what dependencies might cause unwanted effects here or there or what might be able to go wrong in case X. With decoupled code you only need to make sure it does it's "one" (main) function properly.<p>It also prevents code from turning into spaghetti when adding "special" cases
I re-use my code less across projects in the web, but well designed MVC or MVVM can save you a lot of time. Just by having models available, I can re-use them on every page.<p>This turned out to be a life saver when I had to analyze / modify a bunch of data- I was able to get a node script up and running over one weekend re-using the existing javascript models and just focus on the analysis, instead of having to recreate everything in Java or Python.
Depends if I move across problem domains, but I spend a bit of time writing games with LibGDX, and do have a Java package with some basic stuff such as screen generation and asset loading.
It does end up saving me a good hour on getting a new game prototyped.<p>Though in Rails, very rarely, it's usually faster just rewriting it than trying to 'frankenstein' it from a set of piecemeal snippets.
In terms of desktop application development, I easily reuse 30% or more of my code, mostly in a linked fashion. I sometimes have to port between languages, but I still consider that reusing. When it comes to Web Dev, I reuse much less, perhaps only 5 or 10%. I also have less experience with Web Dev than Desktop development, which may be a part of the reason.
Depends on how you look at it. Arguably, I reuse my code every time I modify an application to make it do something it couldn't do before. That effort to make the code reusable helps (if done right) when I have to modify the program some time in the future.<p>But that's probably not the way you were looking at it when you asked the question...
If you count utilizing metaprogramming features within some of the more mainstream languages, my code re-use is sky-high.<p>If you aren't generalizing the problems you're solving in such a way that you can just use policy-types to customize behavior, you're probably not doing yourself any favors in the code re-use sense.
I'm not a professional developer, but for what it's worth, I have a Common Lisp utility module that I use in virtually every Lisp project of mine.<p>Also I often approach project planning in such a way that I can reuse solutions for problems I solved previously.
It remindes me of: <a href="http://blog.codinghorror.com/the-delusion-of-reuse/" rel="nofollow">http://blog.codinghorror.com/the-delusion-of-reuse/</a>