Chapter 11. Code in the Language of the Domain

PICTURE TWO CODEBASES. In one, you come across:
if (portfolioIdsByTraderId.get(trader.getId())
.containsKey(portfolio.getId())) {...}You scratch your head, wondering what this code might be for. It seems to be getting
an ID from a trader object; using that to get a map out of a, well, mapof-maps,
apparently; and then seeing if another ID from a portfolio object exists in the inner
map. You scratch your head some more. You look for the declaration of portfolioIdsByTraderId and discover this:
Map<int, Map<int, int>> portfolioIdsByTraderId;
Gradually, you realize it might have something to do with whether a trader has access to a particular portfolio. And of course you will find the same lookup fragment—or, more likely, a similar but subtly different code fragment—whenever something cares whether a trader has access to a particular portfolio.
In the other codebase, you come across this:
if (trader.canView(portfolio)) {...}No head scratching. You don’t need to know how a trader knows. Perhaps there is one of these maps-of-maps tucked away somewhere inside. But that’s the trader’s business, not yours.
Now which of those codebases would you rather be working in?
Once upon a time, we only had very basic data structures: bits and bytes and characters (really just bytes, but we would pretend they were letters and punctuation). Decimals were ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access