Sunday, November 9, 2008

Don't Reinvent the Wheel

What University Missed

One of the main real world lessons that I found missing in University was, "don't reinvent the wheel." University gives you an understanding of the principles and theory behind software. This is why we created our own array implementations or wrote our own memory management systems. As you learn more, you find that there already exist various array implementations in the standard library, so you use them. But the standard library is not the be-all end-all of the language. The Java programming language isn't particularly great, but what makes it great is the large ecosystem of libraries and tools centered around it.

I think a lot of new programmers reinvent the wheel because they just don't know that anything else exists out there. Another reason might be that new programmers just want to jump in and start coding. But before you start creating some general library to solve a particular problem you are having, take a look around to see if it has already been done. In almost all cases, the problem has already been solved by a mature and solid library or framework.

Think of it as an investment (not the subprime kind)

One of the main complaints with using an existing library, or framework, is that it takes some time to learn. It can take several weeks to get the hang of some frameworks. However, you need to think of this as an investment. Once you have learned how to use this library, you'll be able to use it in all your future projects. If you recreate the same functionality, you'll have to test and maintain it yourself. When you use an existing library, you have many developers testing, optimizing and improving it. You also have many people using it and reporting bugs. So I ask, how can your solution compete?

A good example is security. Instead of implementing your own security framework utilizing the rather rudimentary tools available in the standard Java library, you could have a look around and find that an excellent framework named Spring Security already exists. Scanning through the Spring Security's documentation, you'll find that it'll take you a week or more to learn it. But don't forget, Spring Security is used by thousands of companies, it is developed and maintained by a large team, and it is thoroughly tested. You would end up spending at least 1 week writing something that would meet your current simple needs. But as you expand your application/web site, you'll find that you want to add OpenID integration, a remember me feature, role based security, and so forth. If you were to implement your own solution, you would end up recreating this functionality and taking substantially longer then the week it would have taken to learn how to use Spring Security.

There are many people working on similar projects all over the world, your problem is probably not unique. Learn to use existing libraries so you can focus on your project instead of side endeavors like your own security implementation.

No comments:

 
Wikipedia Affiliate Button