Skip to main content
184 votes
Accepted

Shouldn't unit tests use my own methods?

The spirit of his claim is indeed correct. The point of unit tests is to isolate code, test it free of dependencies, so that any erroneous behavior can be quickly recognized where it is happening. ...
whatsisname's user avatar
  • 27.7k
159 votes

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

The principles stated in "Clean Code" are not always generally agreed upon. Most of it is common sense, but some of the author's opinions are rather controversial and not shared by everybody. In ...
JacquesB's user avatar
  • 59.6k
83 votes
Accepted

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

Good answer here already, but let me say a word about your butterknife example: though I have no idea what the code does, at a first glance, it does not look really unmaintainable to me. Variables and ...
Doc Brown's user avatar
  • 208k
44 votes

Why should we reuse code as binary modules instead of copy/pasting?

Copying code (causing duplication) and sharing code (de-duplicating it via shared modules, classes, libraries, whatever) each have their benefits and drawbacks. In my opinion, the key difference is in ...
Alexander's user avatar
  • 4,904
36 votes

Shouldn't unit tests use my own methods?

I think this comes down to terminology. To many, a "unit test" is a very specific thing, and by definition cannot be have a pass/fail condition that depends on any code outside of the unit (method, ...
Eric King's user avatar
  • 10.9k
34 votes

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

Summary As JacquesB writes, not everybody agrees with Robert C. Martin's "Clean Code". The open source projects that you found to be "violating" the principles you expected are likely to simply have ...
Jens Bannmann's user avatar
28 votes

Too much abstraction making code hard to extend

If I try to make a new method to handle B differently, it gets called out for code duplication. Not all code duplication is created equal. Say you have a method that takes two parameters and adds ...
candied_orange's user avatar
20 votes

Why should we reuse code as binary modules instead of copy/pasting?

You can copy and paste code. There are times when it is the right thing to do. We are taught not to do it because, more often than when it is the right thing to do, it is the lazy thing to do. It is ...
candied_orange's user avatar
14 votes
Accepted

Proper design for a class with one method that can vary between customers

I have a class used to process customer payments. All but one of the methods of this class are the same for every customer, except for one that calculates (for example) how much the customer's user ...
Tanner Swett's user avatar
  • 1,359
14 votes

Why should we reuse code as binary modules instead of copy/pasting?

You can talk about untested code, brittleness, etc. That's just going to fly over their head. The simplest way to describe it is to explain that if you need to make a change to the behavior of that ...
GrandmasterB's user avatar
  • 39.3k
13 votes
Accepted

Is it better to try and implement incomplete code, or write your own?

Reusing code is not about resurrecting old unused and abandoned code and putting it to use. Reusing code is about making the same code fulfill multiple purposes (perhaps within the same project) by ...
Erik Eidt's user avatar
  • 33.8k
13 votes

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

Many open source libraries do in fact suffer from objectively poor coding practices and are maintained with difficulty by a small group of long-term contributors who can deal with the poor readability ...
Kafein's user avatar
  • 436
13 votes

Why should we reuse code as binary modules instead of copy/pasting?

You can share source code files between projects without copy & paste, so sharing binary modules vs. copy & paste is a false dichotomy / false dilemma. Copy & paste offers no built-in ...
Erik Eidt's user avatar
  • 33.8k
12 votes
Accepted

How to avoid duplication of data structures when parts of an app are written in different languages?

You do not. Or really, you should not. If you think of app, your server and your website as separate contexts, then it makes sense there to be duplicate structures. Reasons why it might be a good ...
Euphoric's user avatar
  • 37.4k
10 votes

Proper design for a class with one method that can vary between customers

You might want to look into writing the custom calculations as "plug-ins" for your application. Then, you'd use a configuration file to tell you program which calculation plugin should be used for ...
FrustratedWithFormsDesigner's user avatar
10 votes

Should we put small, potentially often-used pieces of code into tool methods in a shared library?

Save me from published junk drawers. If you want to put small, potentially often used piece of code in a shared library then that library needs a good organizing principle. That is, it needs a good ...
candied_orange's user avatar
9 votes
Accepted

Is 'Keep it looks similar to sample code' a valid reason to prefer WET over DRY principle?

No. Indeed, following the DRY principle can sometimes make very simple code look a little bit more complex (which might be here the case, with emphasis on "a little bit"). However, this is a small ...
Doc Brown's user avatar
  • 208k
9 votes

Why should we reuse code as binary modules instead of copy/pasting?

Every line of code is future maintenance cost. Make three copies of your library as source code and you just tripled your maintenance cost. Now what’s really bad is to have the same code three times ...
gnasher729's user avatar
  • 45.4k
8 votes

How to provide Java libraries internally?

Setup a Maven repository and manage your dependencies with Maven or Ivy. Maven seems to have more market and is a more complete tool for builds. Its main downside is that it relies in convention, ...
SJuan76's user avatar
  • 2,532
8 votes

In which programming paradigm can't code reuse be (easily) achieved?

For my own sanity, I've shortened "paradigms that promote code reuse" to "paradigms". In scope of this answer, all mentioned paradigms are paradigms that promote code reuse. What ...
Flater's user avatar
  • 50.1k
8 votes

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

Most open source projects are badly managed. There are obviously exceptions to that, but you will find a lot of junk in the open-source world. This is not a critique of all the project owners/...
Stig Hemmer's user avatar
8 votes

Too much abstraction making code hard to extend

The usual saying that we all read here and there is: All problems can be solved by adding another layer of abstraction. Well, this is not true ! Your example shows it. I’d therefore propose the ...
Christophe's user avatar
  • 77.3k
8 votes
Accepted

Does a programming language with ML-style modules need packages?

Modules and packages solve different problems, though they certainly overlap, and can be made nearly synonymous. Packages provide a critical source of namespacing. Modules aren't guaranteed unique ...
Kenogu Labz's user avatar
7 votes

Refactoring Atrocious Java Code

If the code base was in perfect shape you wouldn't have a job there. I've seen enough developer turn over to notice the usual trend is to rewrite everything because it is a mess and rewriting it would ...
Thomas Carlisle's user avatar
6 votes
Accepted

Reusing a top-level DTO as a child in another DTO

Re-use existing DTO, Create new parent DTO and Flatten class structure Choosing between reusable code (sometimes it makes us feel like squaring the circle) or customization (sometimes it makes us ...
Laiv's user avatar
  • 14.6k
6 votes

Using GNU GPL V3 on a project. Reuse and modify foreign code

The original owner is the copyright owner, GPL or not. Replacing his copyright notice with your own means you are making a fraudulent claim that you are the copyright owner. Apart from that it's a ...
gnasher729's user avatar
  • 45.4k
6 votes

Best practices on sharing code between open source libraries

The obvious and correct solution is (2): make B a client of A. Sure, B will import more than it needs, but that is the case for 99% of library clients. You're just misled because you know the ...
Kilian Foth's user avatar
6 votes
Accepted

How to avoid code duplication in two similar projects?

Best practice is to put your common code in a library, compile it and distribute the binary to both projects via a package manager. However, If the first website is end of life, you probably dont ...
Ewan's user avatar
  • 75.8k
6 votes

Code design: introduce new method vs add optional parameter to existing method

There is no right answer to this. In a general sense, you actually have three options: Add an optional parameter, Add a second function with a different name, Add a second function with the same ...
David Arno's user avatar
  • 39.3k

Only top scored, non community-wiki answers of a minimum length are eligible