Code reuse can help you save time. But only if you reuse code that complies...
July 7, 2017

The Challenge of Code Reuse (And How to Reuse Code Effectively)

Coding Best Practices
Static Analysis

Consumers are demanding smarter, more connected products. This demand has led to the explosive growth of software and connectivity.

The amount of embedded software in products is growing exponentially. Product functionality is becoming more dependent on software and less on hardware and mechanical components. And it’s happening in every industry.

In aerospace and defense, a Boeing 787 has 6.5 million lines of code. In automotive, a car has 100 million lines of code. And in consumer electronics, an Android phone has 12 million lines of code.

But as software grows, it creates both business and technical challenges. Available qualified developers are limited. And as they become scarce, they become more expensive.

Reusing code can solve the software growth problem.

What Is Code Reuse?

Code reuse is the practice of using existing code for a new function or software.

But in order to reuse code, that code needs to be high-quality. And that means it should be safe, secure, and reliable.

Developing software that fulfills these requirements is a challenge. Systematically developing high-quality reusable software components and frameworks is even harder.

When You Can Reuse Code

Reusing code is a great goal.

In an ideal environment, a developer would be able to access stable and trusted code libraries. They’d then be able to reuse code from those libraries as building blocks within their application.

So, you can reuse code when it can be:

  • Easily extended and adapted for the new application.
  • Ported to different hardware if needed.
  • Shown to be free from defects or problems that affect the reliability, safety, or security of the new application.

But the environment is not always ideal. And code doesn’t always fulfill these requirements. So, reusing code often sounds much easier than it is.

When Reusing Code Doesn’t Work

Reusing code often proves to be difficult.

In practice, developers often end up rebuilding software from scratch. Or they can only reuse a small fraction of existing code in new projects.

Why Software Reuse Is Difficult

Software reuse is difficult. This is especially true for organizations with a large number of product components and geographically distributed development teams.

Here are three reasons software reuse is difficult.

Organization and Scale

As the number of projects and developers increases, it becomes harder to reuse software. It’s a challenge to effectively communicate the details and requirements for code reuse. And it’s difficult to provide adequate guidance and feedback on the reuse of code.

Administration

As the number of projects and developers grows, it’s difficult to share libraries of reusable code. It’s a challenge to catalog, archive, and retrieve reusable assets on a global basis.

Platforms such as GitHub can make this easier. But it still takes time and effort to establish a usable and scalable code repository.

Politics and Psychology

At an organizational level, office politics can be an barrier to software reuse. As business units strive for autonomy — or compete amongst themselves — they may try to block reuse of their assets by other units.

At the individual level, developers may view code reuse as stifling their creativity — or as the organization lacking confidence in their technical abilities. Such perceptions lead some developers to resist efforts to increase code reuse.

Challenges With Code Reuse

There are both operational and technical challenges with reusing code.

Operational Challenges

Creating reusable code requires an investment of time and resources during development. Truly reusable code can be reused in new ways that differ substantially from the code’s original design intent.

More Time

To support planned reuse, development teams need to spend additional time writing documentation for their code. And they need to test it more thoroughly than code slated for just a single project.

This is a challenge for developers with tight deadlines. Some fail because they are overly ambitious. They invest too much in upfront design efforts. Others fail due to poor planning, lack of design flexibility, or lack of funding.

More Resources

Creating reusable code requires project managers to plan additional resources upfront.

At the outset, project managers must commit to the time needed to design, document, and test code, an investment with long-term benefits. The alternative is a short-term approach in which they focus efforts on quickly designing the software to meet their clients’ deadlines and plan on refactoring the code to be reusable at a later date.

Technical Challenges

Software quality plays a major role in how easily software can be reused.

There are four major traits of software quality that impact reuse.

Security

To be reused, code needs to be secure. You can ensure secure code in a number of ways, including using a CWE list.

Reliability

To be reused, code needs to be reliable. You can ensure reliable code by ensuring availability, fault tolerance, and recoverability.

Performance Efficiency

To be reused, code needs to be efficient. You can ensure efficiency by improving response times and monitoring processor, memory, and utilization.

Maintainability

To be reused, code needs to be maintainable. One way to ensure that code is maintainable is to ensure it is compliant.

Static Analysis Makes It Easy to Reuse Code

You can use static analysis to reuse code easily. That’s because static analysis improves overall code quality.

Static analysis identifies problems in code early on. It’s performed directly on the source code. This enabling quality checks to be performed well before the code is ready for integration and functional test.

Static code analysis tools can help spot common flaws in security, design, and program flow. And they can perform data type and variable function checks. These tools often find errors that are not easily detected using other forms of testing.

Static code analysis tools:

And that makes it easier to reuse code.

How to Reuse Code Effectively

You can reuse code more effectively with a static analysis tool, such as Helix QAC.

Learn how Helix QAC improves C and C++ code quality — even in the most complex codebases.

EXPLORE HELIX QAC