Click here to Skip to main content
15,885,670 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
We have a project written in C. It’s about 70K lines of code and has been written over ten years. Features and options have been added onto the original functionality over the years. The application is real time firmware to run on a microcontroller and it has some very carefully crafted interrupt handlers and other critical code. Some of the code has been optimised to work with 2us latency.

Some of the modules now have about 3 features in them as the features have grown over the years. Some of the modules and the general structure has now become tangled. It could do with more commenting and a new programmer has said that it is difficult to get into the code.

The firmware is constantly worked on by about 2 engineers, and so effectively gets run and tested every day as features or customer special versions are created.

There are a few known bugs, which we work through when we have time. Also about once a year a customer reports a bug to us that we didn't know about.

This firmware is used in quantities of about 1000 per year.

A manager (who is not technical) has said the firmware is too buggy and needs to be rewritten from scratch using a methodology like Misra. They say that by doing this the code will be bug free and we will have more robust and maintainable code.

***
Is this reasonable?

Would you rewrite from scratch? Is that the best thing to do? Is there a better strategy?

If we rewrite from scratch do you think we will be able to eliminate all the bugs?

How long do you think it would take to rewrite 70K lines using Misra coding standard?

Is one customer bug report per year per 70K lines of code excessive? What do other people see as a bug rate?

I’m a complete novice at this. I hope this is an appropriate post.

What I have tried:

I asked what the market requirement for Misra was and was told that if we did then if someone asked for it we could say that he have it. I've never heard anyone ask us for Misra standard.
Posted
Updated 15-Feb-17 13:22pm
Comments
jeron1 15-Feb-17 15:32pm    
Is this a 'critical for life' type of application?
bhagman 15-Feb-17 15:46pm    
Good question. It is factory automation equipment. It is generally used by an integrator using one or two as part of a larger machine.
jeron1 15-Feb-17 16:07pm    
Tough to say, if the code is a non-readable, maintenance nightmare, 'only one person in the world can work on it', fustercluck, then maybe a rewrite may be in order. If these bugs are affecting the ability to sell your product or are negatively (in a big way) affecting the business, then maybe a rewrite might be in order. That said, doing a rewrite is not necessarily a slam dunk solution. It could be rewritten poorly, such that you end up with more issues than before, a lot depends on the experience of the dev team. Bugs per lines of code really doesn't matter, the user could care less about the lines of code. It could be that a code review (and adding lots of documentation)and altering the testing in some way will accomplish more than a complete rewrite. Just my $0.02.
[no name] 15-Feb-17 22:13pm    
Are there any plans to upgrade the hardware?

Quote:
A manager (who is not technical) has said the firmware is too buggy and needs to be rewritten from scratch using a methodology like Misra. They say that by doing this the code will be bug free and we will have more robust and maintainable code.

Ummm... there is no such thing as "bug free" code simply because you cannot control non-software factors in your embedded system and how they affect the performance and functionality of a microprocessor or other hardware feeding corrupted or out-of-spec data to it.

Misra is not a methodology. MISRA is an association. They put out a set of guidelines and compliance specifications for software developed for embedded systems in the automotive industry. Things like "favor human safety over vehicle property". That's it. It does not describe a development methodology. That's the realm of Agile, Scrum, Rational Unified, ...

All of your other questions are unanswerable. Only you and your team can answer them.
 
Share this answer
 
This is difficult to answer without taking a look at the code. From what you describe there are two engineers working on the code more or less permanently. So they apparently do understand the code - perhaps not in all parts and perhaps wishing they had invested more into documentation and code cleanups over the year. Nevertheless, that is not a bad starting point at all for improvement.

On the other hand: When rewriting from scratch one has to guarantee that the new code fulfills all functions and timing criteria of the existing code -- not at all a trivial task. Probably you want even to be able to ship it to your existing customer base. In that case you must be VERY sure that the rewrite performs at all those locations flawlessly. And as Jeron1 already pointed out, you could easily end up with a rewrite that has more bugs (at least in the beginning) than your existing product. In any case this is going to be a major development effort.

What I would probably do: Analyze your existing code thoroughly. That would have to be done anyway, even if you later decide to do a rewrite. Then document your existing code accordingly, even or particularly the parts you don't like (will be a result of the analysis). Then decide which parts to rewrite - depending on the results of your analysis this might be anything from just a few modules up to a complete rewrite.

In any case I would not make a decision before really understanding what the existing code does, what its weaknesses are, what all the (undocumented) features and requirements are.
 
Share this answer
 
Comments
bhagman 15-Feb-17 18:21pm    
Thank you to all. All good and useful comments so far. I'm interested in more views if anyone wants to contribute. You'll probably guess that I have a strong view on this subject.

>>>>>> This is difficult to answer without taking a look at the code.
You know as much about the code as the Manager does!
nv3 16-Feb-17 5:33am    
>>> You know as much about the code as the Manager does!
How else could it be. And the little we know is not enough to take a solid decision. If you are not experienced enough yourself you might want to hire an independent expert to take a look at your code and have him help you and the manager with that decision. That might save you all a lot of money in the long run and perhaps prevent a total disaster with a rewrite from scratch that doesn't work properly.
Quote:
Should we rewrite our software from scratch?

We are at the worst place to give you informed advices because we don't have details on that code and its problems. The 2 engineers working on it probably have a better idea on the question.
Quote:
They say that by doing this the code will be bug free and we will have more robust and maintainable code.

at best, those are pious whishes
Bug free: In history of computers, no program beyond the simplest ones have been bug free, ever.
Ask NASA what they think about bug free software, and god knows how a bug can be deadly for them.
Mars Climate Orbiter - Wikipedia[^]
more robust and maintainable code: it fully depend on the people writing it. Nobody can ever guaranty you about this kind of benefits.
Quote:
Also about once a year a customer reports a bug to us that we didn't know about.

I would say the rate is rather low.

My answer: If you don't have major problems with actual software, don't rewrite it from scratch.
I would rather apply modern tools like static analyze to help proofing the code and hint bugs.
Ensuring the code is fully documented is a good idea too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900