In recent days I've seen folks try to recreate functionality when they had access to code that already did effectively the same thing they needed done. In some cases other folks were able to convince them to look at the code they had in their hip pocket and in other cases they weren't. Usually the issue came down to what I've called (and heard called) "wasn't written here syndrome." Because the code was written by someone else, it immediately is distrusted. Now I remember being of that mindset when I was a young programmer, but as I've gotten older and wiser, I've come to understand that if someone else has already solved the problem, and solved it well, there is no real reason for me to try and find another solution. Thank you, Dr. Kanat Durgun, for teaching me that lesson through mathematics.

Some might say, "But you're giving up your creativity!" No, I'm not. If I can re-use code to solve the problems I must solve as part of my job, I have more time available to develop solutions to problems I'm really interested in. In other words, I give a greater outlet for my creativity because I get to work on the things I want to work on. It also means my life is less stressful because the quicker I can solve the problem, the sooner I get out of the critical path of a project or I get out of the glaring spotlight that is cast whenever a production system/process goes down or is impaired due to a bug. Less stress means healthier me. Healthier me means a better ability to work on the things I find interesting. In other words, if I can re-use existing, decently written code, I help myself out. So why wouldn't I do this? Yet I see folks hitting this wall all the time. I don't know whether it's pride (this was my problem early on), ignorance, or a desire to look busy or some combination of the three. But I can always find things to do with my time that benefits me and my organization.

So if you are faced with a problem you think someone has already solved, do a bit of research. If you find that they have, and you like the solution, see about using it to solve the problem that is before you. Obviously honor all licenses and intellectual property rights, And then spend that time you saved on something you really want to do!

Comments

Posted by Steve Jones on 21 February 2011

Good advice, and I try to reuse things as much as I can. Sometimes to the detriment of forcing an old piece of code to do something it wasn't designed to do.

I think you need to look to reuse, and consider having a repository, but don't blindly do so. Make sure you are reusing somethings that fits well for the new purpose.

Posted by Ralph Hightower on 21 February 2011

I reviewed code for a new project written in C++ and I saw repetive code in numerous functions. The functions all looked the same, just with different function names and internal variable names. I mentioned it to the lead programmer and he agreed with my comments on that programmer's programming style.

In a C# project I wrote for myself, I had to do time zone conversions from Houston TX to everywhere else. .Net 2.0 didn't have a method to do time zone conversions (just GMT-local time conversions); .Net 3.0 did, but that was in beta testing at the time. I found code on an MSDN blog to do the time zone conversions and incorporated that into the project. I included credit and the source for the time zone conversion in my open source project.

Posted by paul.knibbs on 22 February 2011

Back in the days I was a programmer I remember working on an application that had been developed by someone else. This application had various types of graphs it could render, each of which had a key at the bottom showing which colour represented which quantity. Every single different type of graph had its own slightly different code for rendering the key, even though it looked the same onscreen! One of the first things I did was split that out into a separate function...

Posted by emamet on 22 February 2011

I often find that "we" (SQL folks) are kind of bacwkard in many ways compared to "procedural" languages like C# ,etc and patterns is certainly a field that would greatly improve our productivity. Thanks for the SSIS / Patterns link!

Posted by tymberwyld on 22 February 2011

This goes beyond "coding" patterns. There are also database design patterns. Using the 3 books in the series "The Data Model Resource Book", you are able to see 80% of all your database design needs. What I hate is when organizations think they have this unique database design (or need for one). Once you've read these books, you'll realize you can spend less time in the database design phase and more time getting your applications out there. I have now successfully used the same database design for a telecommunications project, health care project, and soon an energy sector project. Sure there are "certain" tables that are unique between the industries, but about 80% is all reusable between all of them. It all comes down to terminology.

Posted by mike.frederick on 22 February 2011

Best advice for a coder to accept. It's best to concentrate on new problems and not the ones that have already been solved. Communication is a big thing as I've solved some issues and one of my coworkers is struggling to solve the same problem. Because we have daily scrums, I can point out the code he needs to move forward and get our project work done faster.

As a side for reasons why programmers constantly reinvent, somone I know can never remember where he did something and feels it is quicker to rewrite the code than try and search out where he did it before.

Posted by Tom Bakerman on 22 February 2011

Excellent advice. The bigger question, I feel, is why is this necessary to even mention? Why isn't this taught in schools? Is there some in our genetic makeup as software developers that makes us think that everything we do is unique? It's not "sql folks", it seems to me that all developers (and I include myself in this) have this issue. The "I can't remember where I did something, so I'll rewrite it" is one thing, but I've had experience where I've tried to show another developer a design pattern, and he ignored me. He has since left the company, I've inherited his code, and my wtf rate has gone through the roof.