Questions tagged [code-reuse]

The use of existing code for creating new software.

Questions with this tag should be about best practices and strategies for creating code that can used by different pieces of software, as well as using already existing code.

178 questions
113
votes
12 answers

Best practices for sharing tiny snippets of code across projects

I always try to follow the DRY principle strictly at work; every time I've repeated code out of laziness it bites back later when I need to maintain that code in two places. But often I write small methods (maybe 10 - 15 lines of code) that need to…
George Powell
  • 1,386
  • 2
  • 11
  • 11
84
votes
11 answers

Shouldn't unit tests use my own methods?

Today I was watching a "JUnit basics" video and the author said that when testing a given method in your program, you shouldn't use other of your own methods in the process. To be more specific, he was talking about testing some record-creation…
carlossierra
  • 1,395
  • 2
  • 13
  • 17
81
votes
9 answers

How do huge open source libraries get maintained while having code far from "clean code" practices?

I'm still inexperienced to write high quality code, so I read books addressing the issue such as Clean Code by Robert C. Martin, and keep checking code of well-known libraries to improve my skills. Although many open source libraries have been…
58
votes
19 answers

Does OOP fulfill the promise of code reuse? What alternatives are there to achieve code reuse?

Perhaps the greatest promise of using object-oriented paradigm is the code reuse. Some dispute that this was achieved. Why was it (not) achieved? Does code reuse as OOP defines it, make projects more productive? Or more manageable? Or easier to…
Maniero
  • 10,826
  • 14
  • 80
  • 133
47
votes
5 answers

What did Rich Hickey mean when he said, "All that specificity [of interfaces/classes/types] kills your reuse!"

In Rich Hickey's thought-provoking goto conference keynote "The Value of Values" at 29 minutes he's talking about the overhead of a language like Java and makes a statement like, "All those interfaces kill your reuse." What does he mean? Is that…
GlenPeterson
  • 14,890
  • 6
  • 47
  • 75
46
votes
16 answers

Are there concrete reasons not to use libraries and code snippets heavily?

Overall I'm in programming for about 8 years now and it seems to me that I'm relying more and more on open source libraries and snippets (damn you GitHub!) to "get the job done". I know that in time I could write me own implementation but I like to…
Henrik P. Hessel
  • 885
  • 1
  • 8
  • 13
44
votes
8 answers

Why shouldn't classes be designed to be "open"?

When reading various Stack Overflow questions and others' code the general consensus of how to design classes is closed. This means that by default in Java and C# everything is private, fields are final, some methods are final, and sometimes classes…
TheLQ
  • 13,478
  • 7
  • 55
  • 87
43
votes
7 answers

How do you keep track of what classes and functions your team has written?

When working on code, I face many of the same challenges that my teammates do, and I have written some helpful functions and classes, and so have they. If there is good communication, I'll hear about some great thing someone put together, and six…
changokun
  • 491
  • 4
  • 9
39
votes
9 answers

How do I overcome paralysis by analysis when coding?

When I start a new project, I often times immediately start thinking about the details of implementation. "Where am I gonna put the DataBaseHandler? How should I use it? Should classes that want to use it extend from some Abstract superclass..?…
36
votes
5 answers

Are there any actual case studies on rewrites of software success/failure rates?

I've seen multiple posts about rewrites of applications being bad, people's experiences about it here on Programmers, and an article I've ready by Joel Spolsky on the subject, but no hard evidence or case studies. Other than the two examples Joel…
user39741
32
votes
16 answers

Do you have your own 'misc utils' library? What part are you most proud of?

I know that many of us maintain our own little personal library with tools and utilities that we use often. I've had mine since I was 16 years old so it has grown to quite a considerable size. Some of the stuff I've written has since been added to…
Nobody
  • 2,613
  • 1
  • 22
  • 25
32
votes
11 answers

Is it wrong to take code you have produced at work and re-use it for personal projects?

Throughout my various workplaces I always wrote code which made me think "this would be really useful in other situations". Indeed, I intentionally write code, even if it takes me longer write, which I know will help me in the future (e.g. custom…
Arj
  • 539
  • 4
  • 10
29
votes
9 answers

What's your view on using other people's code?

As per this question: I decided to implement the BitTorrent spec to make my own client/tracker. Now, I was going through the spec, I was about 70% done implementing the BEncoding when I found a link to an implementation of BEncoding in C# written by…
Steven Evers
  • 28,200
  • 10
  • 75
  • 159
25
votes
7 answers

Does software reuse preclude process repeatability

Code Reuse as a Problem I was thinking about this question on software delivery, and I kept coming back to the issue of repeatability and / or reproducibility. They matter, because if you don’t repeat a project then it becomes more difficult to…
user53019
25
votes
9 answers

Adding complexity to remove duplicate code

I have several classes that all inherit from a generic base class. The base class contains a collection of several objects of type T. Each child class needs to be able to calculate interpolated values from the collection of objects, but since the…
Phil
  • 3,660
  • 26
  • 29
1
2 3
11 12