Writing Software Right the First Time

AI is finding more bugs, but why not get it right the first time.

What you’ll learn:

  • Why it’s important to prevent bugs from making it into the wild.
  • How AI is helping and hindering software development.
  • How programming languages like Rust, Ada, and SPARK help when developing high-quality software.

Developing high-quality software isn’t an easy task nor is it cheap. Still, fixing bugs in the field is a lot more expensive with the cost of fixing these issues rising exponentially as it moves through quality assurance to deployment in the field. Add to the mix the rise of generative artificial intelligence (GenAI) and its ability to identify bugs in software, which only elevates the need for high-quality software from the start.

Programming languages like Ada/SPARK and Rust aim to improve things with or without AI assistance. Developers may want to take a closer look at these even while turning to AI to enhance their productivity.

While a definitive accounting of bug fix costs hasn’t really taken place, it’s true that the impact of a bug is more significant as it moves from the design stage to deployment for a variety of reasons. First, the number of systems involved. Second is how they can be updated in the field, and, finally, whether addressing the bug actually fixes the issue and doesn’t cause other problems.

Even with over-the-air (OTA) updates, there’s a significant cost in fixing a bug. OTA doesn’t guarantee that all instances where a bug occurs will be fixed in a timely manner. Another issue concerns which systems will be fixed using OTA even if the option is available, because changes are often device-specific and vendors may not provide updates for legacy devices.

Getting it Right the First Time

Getting the job done right the first time is of course the end goal for most developers (see figure). The challenge is achieving that goal while meeting deadlines and productivity requirements.

These are many aspects that come into play in creating good software:

  • Choice of programming language
  • Formal specifications
  • Version-control systems
  • Bug tracking
  • Good coding practices
  • Peer/code reviews
  • Unit and systems testing
  • Documentation
  • Software bill of materials (SBOM)

AI can assist with many of these even without generating code, such as doing code reviews, generating unit tests, and even writing documentation. AI code generation and agentic AI are areas we’ll leave to another article.

Why the Programming Language Makes a Difference for High-Quality Software

Programming languages can range from very strict and concise to less precise and even undefined characteristics. Rust, Ada, and SPARK are on the strict side, while C is closer to the other end of the spectrum. Essentially, the stricter approaches put the specifications in the programmer’s hands but the checking is done by the compiler. For example, Ada can specify a variable that has a range from −10 to 25 with checking to make this the case, while C integers are specified by the number of bits with no checking by the compiler.

Similar compiler checking is done by Rust when it comes to memory management. Again, C puts the onus on the programmer, while Rust makes sure that the programmer’s specifications are met.

Contracts are a feature that allows programmers to specify preconditions, postconditions, and invariants for functions and code. At least one Rust crate supports contracts, and contracts are inherent in Ada 2012 and SPARK. C++ contracts are part of the C++26 standard. SPARK takes support to the extreme — it’s able to prove that the program meets the specifications at compile time, allowing for removal of most runtime checks.

Though many tout the freedom and efficiency of programming languages like C, these tend to be the ones that cause the most problems when it comes to bugs. That’s because the programmer must check for bugs rather than the compiler.

It’s true that the compiler can’t address a lot of bugs. However, having the compiler check on as many areas as possible allows developers to focus on those areas that the compiler can’t handle alone.

Will AI Help Create High-Quality Software?

When it comes to AI helping with software creation and maintenance, your mileage will vary. For many seasoned developers, it’s made repetitive chores easier. And many new or non-developers have been able to create applications without understanding the underlying code.

In some cases, AI-generated code has been good and bug-free while it’s added major bugs and security issues to applications in others. The field is still new and constantly changing, making it difficult to know where the results of AI and developers will work together in this wide spectrum.

I know that many will task AI with complete application creation and deployment. However, I hope that it will be used more to configure and manage tools like compilers and formal specifications. And that they will be overseen by people who can understand the implications of the system while using, say, compilers to implement the details in a consistent and repeatable fashion.

Check out the results of a few polls we’ve conducted related to software development:

Tero Vesalainen | Dreamstime
Dreamstime Tero Vesalainen Promo 131140735 636e77e566dc4
We would all like to deliver bug-free code, but that's not always as easy as it might sound.
Tero Vesalainen | dreamstime.com
Dreamstime Tero Vesalainen Promo 131140735
Take a quick poll and see what other programmers are up to.
Tero_Vesalainen | Dreamstime
Ed Dreamstime Tero Vesalainen Promo
Rust has garnered a lot of interest in the embedded community, but where do you stand with using it?

I also gave a talk a while back on Creating Bug-Free Embedded Software.

Here are some videos on Certifiable Rust and Embeddable Rust that you might find interesting.

About the Author

William G. Wong

Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sign up for our eNewsletters
Get the latest news and updates

Voice Your Opinion!

To join the conversation, and become an exclusive member of Electronic Design, create an account today!