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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

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

Cyrille Martraire user avatar by
Cyrille Martraire
·
Sep. 12, 12 · Interview
Like (0)
Save
Tweet
Share
11.55K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Distributed Tracing: A Full Guide
  • mTLS Everywere
  • Rust vs Go: Which Is Better?
  • Strategies for Kubernetes Cluster Administrators: Understanding Pod Scheduling

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: