Main / Muse
Thoughts from Jack Ganssle and friends. "After over 40 years in this field I've learned that "shortcuts make for long delays" (an aphorism attributed to J.R.R Tolkien). The data is stark: doing software right means fewer bugs and earlier deliveries. Adopt best practices and your code will be better and cheaper. This is the entire thesis of the quality movement, which revolutionized manufacturing but has somehow largely missed software engineering. Studies have even shown that safety-critical code need be no more expensive than the usual stuff if the right processes are followed." -JG "When you can measure what you are speaking about, and express it in numbers, you know something about it; but when you cannot measure it, when you cannot express it in numbers, your knowledge is of a meager and unsatisfactory kind." -Lord Kelvin CodingI was going over some code recently and found a password stored in malloc-ed memory. That was quickly freed, so the password was deleted. But, of course, it wasn't. The password was still in the heap, potentially visible if those locations were ever returned to fulfill an allocation request. The code's author should have scrubbed those locations first, and then freed the memory. Michael Pollan's advice about eating is concise: "Eat food. Not too much. Mostly plants." In a similar vein, I'd suggest about C code: "Use parentheses. More than you'd think. Clarify expressions." The company's firmware standard should mandate that all expressions using operators be enclosed in parentheses. That is: At 100K LOC it's almost impossible, or at least extremely expensive, to get better than 97% test coverage. The one shining exception seems to be projects done to the DO-178C avionics standard which, for the most critical systems, requires complete testing traceability. The cost? By some reports, about 65% more than code not done to that standard. The upside? Code done to that standard has never caused a plane to crash. These days I like to use variables rather than #defines to get a bit of extra type checking. I also run my code on both Windows and the target - this gives more chances to find obscure bugs (e.g. Visual Studio finds stack corruption "for free"; it can be difficult on target). So I wrote the following: const int size = 5; char buffer[size]; Visual Studio worked as I expected - it generated a fixed-sized array on the stack. The Texas Instruments ARM compiler wasn't smart enough to detect that "size" is constant, so instead generated a variable-length array which is allowed in C99 (no idea why!) and then decided to place it on the heap (the location of VLAs is not defined by C99). My application doesn't have a heap, so the code crashed. VLAs are prohibited by MISRA (rule 18.8) but my MISRA checker (Gimpel's PC-Lint) agreed with Visual Studio that the array is fixed-sized and didn't complain. Moral: stick to #defines for array sizes. Tips"Regarding bare-metal : a simple task scheduler controlling state machines, all tasks required to run to completion, all errors considered fatal, is still my "go to" approach for hard real time control." - contributor "Assume you are writing comments for an intern because that may very well represent the skill level of the next person to work on your code, or your skill level for this piece of code a year from now." - contributor "I am 72, retired and wrote code in the 70's and 80's because I had to. There was no one else to do it. And I have written self documenting code - and lived to understand how incredibly stupid it is. As a result of years of software / firmware and hardware design and maintenance, I now know self documenting code is self documenting. It is documenting who needs to be told it is company policy, as I believe it is everywhere that counts, or they will be replaced. Their code should be randomly examined and if they don't comply they should be replaced before they can do more harm." - contributor New Year's software resolutions(found on a napkin at some watering hole) in 1996: I will learn to touch type Development ProcessFaster... Better... Cheaper... Pick any two. Yes we document our code, but an even better approach is to "code the document" as in the SWDD. Work EstimatingAccording to Capers Jones, a very rough guide to estimating the number of people needed on a project, and the project's duration, is: Number of developers = (function points)/150 Calendar months = (function points)^0.4 One function point is somewhere around 130 lines of C code. Firmware is hideously expensive. Most commercial firmware costs around $20 to $40 per line, measured from the start of a project till it's shipped. When developers tell you they can "code that puppy over the weekend" be very afraid. When they estimate $5/line, they're on drugs or not thinking clearly. Defense work with its attendant reams of documentation might run upwards of $100 per line or more; the space shuttle code was closer to $1000 per line, but is without a doubt the best code ever written. (2023 dollars) Auditing Firmware TeamsFrom time to time companies have me come in to examine their firmware engineering practices. That involves poking around, interviewing team members, reviewing documents, and conferences with managers. In case you want to audit your own team, here are my most common findings, in no particular order:
When it comes to software, I view the data as an impressionist painting, where the outlines might be fuzzy, but one can still make out the general shape of things. LOC Requirements (in pages) Requirements Completeness
Adapted from The Economics of Software Quality, Capers Jones Here's another take on this. It's adapted from Joel Spolsky's software team quality test:
Cost of Good CodeFinally, did you know great code, the really good stuff, that which has the highest reliability, costs the same as cruddy software? This goes against common sense. Of course, all things being equal, highly safety critical code is much more expensive that consumer-quality junk. But what if we don't hold all things equal? O. Benediktsson (Safety Critical Software and Development Productivity, conference proceedings, Second World Conference on Software Quality, Sept 2000) showed that using higher and higher levels of disciplined software process lets one build higher-rel software at a constant cost. If your projects march from low reliability along an upwards line to truly safety-critical code, and if your outfit follows increasing levels software discipline, the cost remains constant. Capers Jones showed that the best people excel on small (one man-month) projects, typically being 6 times more productive than the worst members of the team. That advantage diminishes as the system grows. On an 8 man-month effort the ratio shrinks to under 3 to 1. At 64 man-months it's about 1.5 to 1, and much beyond that the best do as badly as the worst. Or the worst as well as the best. Whatever. RantsOne of my top ten reasons software projects fail is when teams don't resist the urge to start coding. Coding is just one part of the field of software engineering, one that's similar to paving a bridge deck. Without the pavement none of us will drive, but bridge construction requires careful engineering, zoning, funding and a host of other activities far more complex than paving, and far more important to the final result. Bad pavement can be replaced or patched, but a badly designed bridge will collapse. Bad software engineering insures a project will fail no matter how well the coders - the programmers - do their job. Engineering is the art of solving problems, which is what building firmware is all about. "Since we started letting the developers use the [chaos, Capability Maturity Model, Personal Software Process, Test-Driven Development] process they have been much happier and more productive." Really? I can't tell you how many managers have told me some version of this story. It's almost always complete nonsense. Reliability"On the same die, does not fly": Among other things, this meant we couldn't rely on or even use the hardware watchdog timer built into the die of the microprocessor, primarily because they were WAY too easy to defeat. Indeed, it had to be external and a totally independent entity (also rad hardened, etc.). Indeed, I use to demonstrate just how easy it was to defeat an internal WDT by exposing an 8751 (EPROM) micro to the overhead fluorescent lighting. With the WDT enabled, the overhead lights would cause the micro to freeze-up within seconds of removing the opaque erase window cover. "The embedded system needs to serve a specific purpose and be stable. It does not need to interoperate with every digital device in the world!" - Michael Covington "Testing has ever been a thorny problem in this industry. The agile community uses test to get their code right; my philosophy is to get the code right and then use test to prove correctness." - JG Safety-Critical SWSoftware doesn't run in isolation. It's merely a component of a system. Watchdogs are not "software safeties." They're system safeties, designed to bring the product back to life in the event of any transient event that corrupts operation, like cosmic rays. Xilinix, Intel, Altera and many others have studied these high energy particles and have concluded that our systems are subject to random single event upsets (SEUs) due to these intruders from outer space. Chips"The hardware engineer I work with asks me for basic Requirements (number of gpio pins needed, needed interfaces I2C, UART,..). He then goes off and decides which chip to use based on price, package,.. This sometimes means a different CPU from a different vendor with a different architecture for each project. (with very exotic requirements and high volume projects this is the only way to go)." - contributor Top 10 Reasons for Project Failureshttp://www.ganssle.com/tem/tem381.html
Hardware vs SoftwareJohn Sloan John Kougoulos Team Function AnalysisHere are Jack's questions he asks when consulting on team performance: http://www.ganssle.com/tem/tem445.html The idea is to get a sense of team pressures, what it's like to work there, what documentation is produced, what development process is used, how good is product quality, how are issues tracked, etc. |