In Martin Fowler's refactoring book, there is a code smell named "Insider Trading" which I don't understand:

Software people like strong walls between their modules and complain bitterly about how trading data around too much increases coupling. To make things work, some trade has to occur, but we need to reduce it to a minimum and keep it all above board.

Can you give me some code examples?

  • 2
    The term is meant to be a loose metaphor; according to wikipedia "Insider trading is the trading of a public company's stock or other securities (such as bonds or stock options) based on material, nonpublic information about the company" (emphasis by me). So the code smell is just when one class (or any other component) knows too much about the internals of another one and relies on those internals (private data and methods) to do its work. (Or when both components know about the internals of each other). I.e., there's no well defined contract between the two to control the coupling. Jan 23, 2021 at 21:34

2 Answers 2


Well, I don't have my copy of that book at hand, but let me make an educated guess what Fowler could have meant:

  • Let's say there is a function or module A which produces a list of strings or numbers. There is nothing in the documented contract of the public interface of A which guarantees a specific order of that list.

  • Now imagine a second function or module B which takes the list and does some lookup operations using binary search. Imagine B making the assumption that A always returns a sorted list. The author of B might know how A is implemented internally, and that A returns the list always in a sorted fashion. So B does not any sorting by itself.

That is what could be called "insider trading" - using undocumented internal implementation details ("insider knowledge") for shortcuts or simplifications. You can probably imagine what happens when a maintenance programmer who works on A, but knows nothing about B, has to change some internals in A, which leads to an output in a different order.


I’m Mr. Alarm. My job is to flash red lights and make a terrible noise when something has gone wrong with the system. However, no one likes it when I go off for no good reason. When I do my designer gets yelled at.

My designer has me suppressing a lot of signals. The cpu is too hot! Oh but except when powering up or for brief periods or when it’s accessing GPU... and that’s just the CPU.

My designer has created a situation where I have to know almost everything about the whole system. No one can touch the system now without him.

It seems silly to me. All I want to know is when to go off. I’m real good at flashing lights and making noise. Why do I need to know this other stuff?

That’s insider trading. It’s about knowing too much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.