DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Trending

  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • PostgreSQL Everywhere and for Everything
  • Designing a Secure API From Day One

What's Your Signal-to-Noise Ratio in Your Code?

By 
Cyrille Martraire user avatar
Cyrille Martraire
·
Sep. 12, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
14.4K Views

Join the DZone community and get the full member experience.

Join For Free

you write code to deliver business value, hence your code deals with a business domain like e-trading in finance, or the navigation for an online shoe store. if you look at a random piece of your code, how much of what you see tells you about the domain concepts? how much of it is nothing but technical distraction, or « noise »?

like the snow on tv

i remember tv used to be not very reliable long ago, and you’d see a lot of « snow » on top of the interesting movie. like in the picture below, this snow is actually a noise that interferes with the interesting signal.

the amount of noise compared to the signal can be measured with the signal-to-noise ratio . quoting the definition from wikipedia:

signal-to-noise_ratio (often abbreviated snr or s/n ) is a measure used in science and engineering that compares the level of a desired signal to the level of background noise. it is defined as the ratio of signal power to the noise power. a ratio higher than 1:1 indicates more signal than noise.


we can apply this concept of signal-to-noise ratio to the code, and we must try to maximize it, just like in electrical engineering.

every identifier matters

look at each identifier in your code: package names, classes and interfaces names, method names, field names, parameters names, even local variables names. which of them are meaningful in the domain, and which of them are purely technicalities?

some examples of class names and interface names from a recent project (a bit changed to protect the innocents) illustrate that. identifiers like « cashflow »or « cashflowsequence » belong to the ubiquitous language of the domain, hence they are the signal in the code.

examples of classnames as signals, or as noise

examples of classnames as signals, or as noise

on the other hand, identifiers like « cashflowbuilder » do not belong to the ubiquitous language and therefore are noise in the code. just counting the number of « signal » identifiers over the number of « noise » identifiers can give you an estimate of your signal-to-noise ratio. to be honest i’ve never really counted to that level so far.

however for years i’ve been trying to maximize the signal-to-noise ratio in the code, and i can demonstrate that it is totally possible to write code with very high proportion of signal (domain words) and very little noise (technical necessities). as usual it is just a matter of personal discipline.

logging to a logging framework, catching exceptions, a lookup from jndi and even @inject annotations are noise in my opinion. sometimes you have to live with this noise, but everytime i can live without i definitely chose to.

for the domain model in particular

all these discussion mostly focuses on the domain model, where you’re supposed to manage everything related to your domain. this is where the idea of a signal-to-noise ratio makes most sense.

a metric?

it’s probably possible to create a metric for the signal-to-noise ratio, by parsing the code and comparing to the ubiquitous language « dictionary » declared in some form. however, and as usual, the primary interest of this idea is to keep it in mind while coding and refactoring, as a direction for action, just like test coverage.

i introduced the idea of signal-to-code ratio in my talk at dddx 2012, you can watch the video here . follow me ( @cyriux ) on twitter!

Published at DZone with permission of Cyrille Martraire. See the original article here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook