July 13, 2022

The Importance of Deleting Unused Code

Darshan Mehta, Vice President, Core Engineering

Following the initial post on the Importance of software craft at Goldman Sachs, this blog post covers an important aspect of software quality and its commercial impact on software development and delivery: deleting unused code. 

We are focused on client happiness as reflected in our commercial software delivery of features, risk reduction, operational efficiency, and continuous delivery. There is a correlation between client and developer happiness; our clients are happy when they see regular enhancements to the software they use, and developers are happy when they're able to deliver software quickly. One aspect of developer happiness is healthy codebase and one of the key factors contributing to healthy codebase is code relevance, and this in particular is the subject of this blog post. Maintaining a healthy and relevant codebase is one of the important software craft practices that we follow.

One way to maintain code relevance is by identifying and deleting unused code. This can streamline our codebases, making them easy to maintain, and can improve our ability to deliver commercial benefit to the organization. We come across examples of unused code, often not realizing it. Such unused code convolutes the codebase - especially true to developers reading the code for the first time. They have to exert unnecessary cognitive load when trying to understand the code's functionality. Unused code directly impacts commercial aspects of software delivery, as having to manage and maintain irrelevant code will impact the team’s velocity and their ability to respond to rapidly changing business requirements. There are other negative byproducts of irrelevant code including unnecessary increases in build pipeline times, increased difficulty in library upgrades, and the inability to efficiently refactor.

During a recent software project, we were able to reduce the size of a codebase by 67% by adopting a set of practices that the remainder of this blog post will cover.

The Approach We Employed To Improve Code Relevancy Steps - Please See description.
The Approach We Employed To Improve Code Relevancy Steps - Please See description.
In the above diagram we show a continuum of lower effort to higher effort activities to help improve code relevance. They can be employed in stepped progression or be considered maturity levels. First, using IDEs and build dependency analyzers. Next having conversations with users and clients to diagnose their needs and the APIs and Flows that are not needed. Then, use Sonar and other static code analysis tools to identify unused code. Finally Identify unused API endpoints with custom observability mechanisms to ascertain detailed metrics on timings, users and responses. 

The Commercial Benefits

Using this approach we accrued several benefits: 

  • The overall code footprint and complexity were reduced.
  • The codebase became easier to navigate and test.
  • Build and delivery pipelines became significantly faster with less code for static analysis tools to analyze and fewer tests to run.
  • The release cadence of the product improved to more than 250 releases per year
  • The reduced codebase gave us more confidence in our testing and the time saved provided opportunity for other investments.

Uplifting components and dependencies became easier with a reduced codebase. As an example, we had some code tightly coupled to an older external library. Once we removed that unused code, we were able to upgrade to a supported corresponding version of that library. 

Maintaining Code Relevance in the Future

We want to ensure that we keep our codebase relevant going forward and have adopted some practices and behaviors to support that. We regularly review and discuss observability metrics exposed by our applications. This allows us to have meaningful discussions with our clients about usage and deprecation. Static code analysis tools are integrated into build pipelines. This helps us identify duplicated and unused code. Our build pipelines also have a set of control gates, including build breaks, which help us maintain the quality of our software. We continuously review the code as a part of our software development practices,  which involves discussions around new implementations, refactoring, and bug fixes. This review step helps us identify potential code duplication at an early stage.

Other Considerations

Although identifying unused code and subsequently deleting it looks straightforward, there are a few considerations to be aware of. For example, if the code is executed through configuration (or reflection in the case of Java), it may look like unused code at first glance. Another example would be a transitive dependency on the component or module of a 3rd party library. Deleting the code in such situations is not feasible, however, we can take an incremental approach where we would deprecate the component first and provide the alternatives before removing it in the subsequent major version release.

Deleting the code is not always easy and is often met with resistance. However, fostering a Software Quality culture across the team really helps maintain a healthy codebase. Each software component that we write and manage has its own lifecycle, given the constantly changing nature of our industry. Maintaining a healthy codebase means one of the software component lifecycle stages needs to be ‘delete’.


Our clients are happy when we deliver reliable software regularly, and our developers are happy when we can see that we are contributing to the business as well as codebase hygiene. We believe the investments made in ensuring code relevancy result in significant commercial benefits to our business.

In the next entry in this series on Software Craft, we will focus on the code review practices at Goldman Sachs.

Join us

To learn more about opportunities at Goldman Sachs, we invite you to explore our careers page.

See https://www.gs.com/disclaimer/global_email for important risk disclosures, conflicts of interest, and other terms and conditions relating to this blog and your reliance on information contained in it.

This site is for informational purposes only and does not constitute an offer to sell, or the solicitation of an offer to buy, any security. The Goldman Sachs Marquee® platform is for institutional and professional clients only. Some of the services and products described on this site may not be available in certain jurisdictions or to certain types of client. Please contact your Goldman Sachs sales representative with any questions. Nothing on this site constitutes an offer, or an invitation to make an offer from Goldman Sachs to purchase or sell a product. This site is given for purely indicative purposes and does not create any contractual relationship between you and Goldman Sachs. Any market information contained on the site (including but not limited to pricing levels) is based on data available to Goldman Sachs at a given moment and may change from time to time. There is no representation that any transaction can or could have been effected on such terms or at such prices. Please see https://www.goldmansachs.com/disclaimer/sec-div-disclaimers-for-electronic-comms.html for additional information. © 2023 Goldman Sachs. All rights reserved.
Transaction Banking services are offered by Goldman Sachs Bank USA (“GS Bank”). GS Bank is a New York State chartered bank, a member of the Federal Reserve System and a Member FDIC. © 2023 Goldman Sachs. All rights reserved.
Not all products and functionality mentioned on this website are currently available through our API platform.
All loans and deposit products are provided by Goldman Sachs Bank USA, Salt Lake City Branch. Member FDIC.
Brokerage and investment advisory services offered by our investment products are provided by Goldman Sachs & Co. LLC (`‘GS&CO.`’), which is an SEC registered broker-dealer and investment adviser, and member FINRA/SIPC. Research our firm at FINRA's BrokerCheck. Custody and clearing services are provided by Apex Clearing Corporation, a registered broker-dealer and member FINRA/SIPC. Please consider your objectives before investing. A diversified portfolio does not ensure a profit or protect against a loss. Past performance does not guarantee future results. Investment outcomes and projections are forward-looking statements and hypothetical in nature. Neither this website nor any of its contents shall constitute an offer, solicitation, or advice to buy or sell securities in any jurisdictions where GS&Co. is not registered. Any information provided prior to opening an investment account is on the basis that it will not constitute investment advice and that GS&Co. is not a fiduciary to any person by reason of providing such information. For more information about our investment offerings, visit our Full Disclosures.
GS DAP™ is owned and operated by Goldman Sachs. This site is for informational purposes only and does not constitute an offer to provide, or the solicitation of an offer to provide access to or use of GS DAP™. Any subsequent commitment by Goldman Sachs to provide access to and / or use of GS DAP™ would be subject to various conditions, including, amongst others, (i) satisfactory determination and legal review of the structure of any potential product or activity, (ii) receipt of all internal and external approvals (including potentially regulatory approvals); (iii) execution of any relevant documentation in a form satisfactory to Goldman Sachs; and (iv) completion of any relevant system / technology / platform build or adaptation required or desired to support the structure of any potential product or activity.
Mosaic is a service mark of Goldman Sachs & Co. LLC. This service is made available in the United States by Goldman Sachs & Co. LLC and outside of the United States by Goldman Sachs International, or its local affiliates in accordance with applicable law and regulations. Goldman Sachs International and Goldman Sachs & Co. LLC are the distributors of the Goldman Sachs Funds. Depending upon the jurisdiction in which you are located, transactions in non-Goldman Sachs money market funds are affected by either Goldman Sachs & Co. LLC, a member of FINRA, SIPC and NYSE, or Goldman Sachs International. For additional information contact your Goldman Sachs representative. Goldman Sachs & Co. LLC, Goldman Sachs International, Goldman Sachs Liquidity Solutions, Goldman Sachs Asset Management, L.P., and the Goldman Sachs funds available through Goldman Sachs Liquidity Solutions and other affiliated entities, are under the common control of the Goldman Sachs Group, Inc.