

Ask HN: Code Reuse or Just Plain Well-written Code? - rplevy

Someone said (or maybe it's not attributed to anyone) "great programmers reuse code".  Even if you change that to great programmers "write reusable code" it's still hard to see how it is true in practice, since both great and non-great programmers write reusable code. But I guess it takes a great programmer to do it well, so maybe that was the gist of the saying.<p>In my experience the only kind of reusable code that is immediately helpful is a library of functions.  Beyond that it seems like the effort required to integrate say, a pre-made javascript widget into an application you are creating, and then understand the widget code well enough to make it work perfectly with the application, is about the same amount of time it would take to write it yourself.<p>That is not to say I have no interest in a  pre-made widget, and in fact not being as good of a widget-maker (in the time I have available for the project) as the widget developer apparently is, it seems like a very appealing idea to reuse their code.  But reusing it will often result in something less than optimal.<p>So it seems to me that something approaching an ideal solution in cases like these is that code should be quasi-reusable, or perhaps it should break into discrete parts that could be reused.  More importantly, it should be possible to readily understand the code so that some part of it or all of it, could be integrated into the application you are creating, making changes to it that are not klugey but make sense with how the code is intended to be used.<p>This is of course an old topic, but I'm curious to hear what people think is currently the best way to approach this ages-old problem.
======
msg
At my work (C++/Qt) we do a bunch of GUIs for a set of several customer
applications that need the same look and feel. So we do end up reusing the
team's custom widgets wherever they answer our requirements.

I find I often write something as helper functions for a GUI or library, then
break it out when someone else needs to call it. It's definitely better from
my perspective to leave it sitting in the old class until you come up with
something more urgent than scenarios for how someone might use such a library
someday.

Coding standards are also extremely important to ensure that someone will be
able to look at your code and use it without deciding to rewrite it from
scratch.

------
schtog
I have found myself that I often reuse functional stuff(I write functions to
do stuff and continously add fucntions in different programs that kind of
belong together and then I realize I have a library) but I rarely reuse class-
oriented stuff. Sure sometimes you have a class that can be used in many
programs but I dont find it happening that often.

Seems logical as well, you reuse your hammers and screwdrivers, not your
house.

