3 ms·
Many years ago, when I was first learning game programming, I insisted on implementing everything myself, including low level 3-d math and writing to video memo
by phaedrus 16y ago
Many years ago, when I was first learning game programming, I insisted on implementing everything myself, including low level 3-d math and writing to video memory manually. Now, I'm working on a new game and I've created a script-binding technology that makes it very easy for me to incorporate third party C/C++ libraries into the game's scripting engine, like the way the Borg assimilates technologies. So I've had experience at both extremes of NIH.
Here's what I've found: using someone else's library is NOT faster than implementing the code yourself just to do a certain task at hand. The code you write for yourself does no more than you need it to, and you implicitly understand how it works. When you're trying to use someone else's library to accomplish a simple task at hand, you have to learn all the library's concepts tangentially related to what you want to do, and then you can spend days tracking down a silly bug because you misunderstood some small detail of what the library is doing (i.e. the library violated the law of least astonishment). At best, it takes THE SAME time to learn/debug code with a dependency as it does to implement it yourself, provided you're a good programmer.
But, I still recommend learning to reuse code from elsewhere. The benefit of hooking up to and learning a third party framework or library comes after the task at hand, which is that once you've made the initial investment, incrementally enabling other features the library provides begins to cost less and less than reimplementing them yourself, because the initial investment of learning and debugging the foreign code begins to pay back.
So you have to look at it as being like an investment which loses money in the short term but has the potential for earning back interest in the long term.
But here's the most important reason to drop NIH and embrace code reuse: Do you want to push the boundaries of what is possible? If you envision program-space as the set of all possible programs, it must be clear that there are programs on that space that lie outside what one team or one man can write by himself in a lifetime. If all you're doing is accomplishing one task at hand, by all means make the cost-benefit analysis and choose reuse or not pragmatically. But if you're interested in pushing the boundaries of the state of the art, then to reach the "interesting programs" that lie in program-space outside the boundaries of what one man can write in his lifetime, you must do it by extending the work of others who have gone before you, just as all progress in science is accomplished.
- jasonkester 16y agoYou're right. It amazes me how people are so willing to drop 3rd party code into a project to accomplish the most trivial things. You can put together a class to do, for example, ASP.NET URL Rewriting in a single sitting if you want to. And the thing you end up with will do exactly what you need and nothing else. It's like 50 lines of code. And still Junior Dev Jimmy will go find something on somebody's blog that sorta does it and pollute your project with it. It adds up quickly, and if you're not careful you'll find yourself with 2 dozen random pieces of CodeProject wackiness interacting it unexpected ways and throwing you into maintenance mode. In my experience it's just not worth it. If you're bringing in a 3rd party library, make sure it's for something big and complicated that you just don't want to deal with. Credit Card processing, Amazon Web Services integration, that sort of thing. Otherwise, take half a day and roll your own. Your life will be a lot nicer.
- _delirium 16y ago> If you're bringing in a 3rd party library, make sure it's for something big and complicated that you just don't want to deal with. It should also imo be one that appears to have a decent track record of active maintenance. If it doesn't, sooner or later you're going to be the one maintaining it, which might not turn out to be much easier than having rolled your own. I've seen more than one project that eventually did roll their own once their unmaintained 3rd-party library bit-rotted so much that it wasn't worth saving.
- phaedrus 16y agoAbsolutely! That's one of the top criteria (right up there with type of license) when I evaluate whether to include a library in my game: is this library actively maintained? Incidently, it's one of the things that worries me about the pthreads for Windows library: it hasn't been updated in quite some time.