Topics

Good news, bad news

Jack, W8TEE
 

In the course of writing code for a pretty large project, I found a way to save some code space by adding two arguments to the function. Since C++ allows function overloading as long as the signatures are different, I used the same function name for both, but the original had no arguments. In theory, there should be no compiler errors in doing that. The good news is that there were no errors during the compilation.

There's even more good news. I wondered if the compiler recognized that the original function was no longer being called and, if so, would it leave the now-unused code out of the executable. I compiled the code with both functions in the code and measure the flash and SRAM usage. I then commented out the unused function and recompiled. If the compiler does its job, the memory usage should be identical. It was!

However, after I thought about it for a minute, there's some bad news, too. My source file could have "dead code" in it and the compiler didn't tell me about it. It would have been nice to get an "unreachable code" error message.

Jack, W8TEE

Mike KK7ER
 

I was looking for something like this for my day job and found that Coverity will do static code analysis and is free.  Wouldn't work for me because I cannot upload my company's proprietary code to the cloud.  But for open source it seems like a great tool:  https://scan.coverity.com

73 Mike KK7ER

Tom, wb6b
 

That was an interesting question. Not knowing I bravely googled around and tried to separate the plausible from the non-plausible explanations. 

Around 2010 gcc removed the dead code warning option for being "unreliable". However, apparently later, the optimizers were improved to better automatically remove dead code. Or so the internet lore goes. 

Another fun thing, for embedded systems, is the lack of runtime error reporting (where is it going to be reported to). Code that does awful things, divide by zero, jumps to or accesses incorrect memory, probably other things, the embedded runtime will ignore the error and keep on running. With whatever unpredictable results that may cause. 

In large scale systems we instrument our code and the instrumentation data if collected by other analysts systems. Would be nice if the Arduino at least kept some counters on run time faults I could access and report in debug data. I'm looking around to see if they do exist. 

Tom, wb6b

Tom, wb6b
 

I was googling around some more and it looks like some folks have hacked the DebugWire protocol to create a free Arduino command line debugger.

Tom, wb6b

Tom, wb6b
 

Jack, W8TEE
 

My software company sold programming tools back in the '80's-'90's and our compiler had a Picky Flag feature that was like the Unix tool Lint. You could set it at levels between 0 and 10. We never saw any published code that passed Level 10. In fact, it was so fussy we ran at Level 4 during development and only cranked it up when it was ready for production.

I started wondering if I could extract that code (it was written in C) and get it going today. Alas, after I sold the company, the code that was not restricted ended up in folders on floppies or hard copy. A failed sump pump while I was away on vacation put almost 18" of water in the basement. I fear my Pick Flag was victim to the flood as I have not been able to find it in the little source code that did survive.

I haven't looked, but there probably is an app that does the same thing. Right now, if you click the bottom checkbox on the Arduino Search dialog, you could type in the name of a function that you might think is "dead" as see if it appears in any other tab...better than nothing.

Jack, W8TEE

On Wednesday, August 8, 2018, 11:40:42 PM EDT, Mike KK7ER <groupio@...> wrote:


I was looking for something like this for my day job and found that Coverity will do static code analysis and is free.  Wouldn't work for me because I cannot upload my company's proprietary code to the cloud.  But for open source it seems like a great tool:  https://scan.coverity.com

73 Mike KK7ER

Tom, wb6b
 

Yes, even if the optimizer automatically removed dead code, it would be a good idea to know about is, as it should not be there in the first place. Would seem if the optimizers have been improved, the gcc complier could put the dead code warning back. 

Truly sad your code was wiped out in a flood. Sounds like it did a good job of pointing out issues and enforcing a user selectable level of code quality. 

Mike pointed out a possible tool, there are others. Possibly some of them check for dead code.

Funny, I had a client that had a cash cow software service. They managed to find programmers that would do the quickest dirtiest fixes to the code and minimally thought out enhancements. Worst yet, one of the company owners hacked the original code together while he was in college for a completely different application, then modified it to the cash producing one. Was horrible code, including numerous global variables that wound through thousands of lines of code. That at any moment could be unexpectedly hijacked by other code (thanks to years of butchering by the previously mentioned cavalcade of programmers) and be doing unexpected things. 

I was attempting to shine some light of reality on the people that made demands to instantly fix things or add a new suite of functionality in a few hours. I ran a code "complexity" analyzer on a core part of the code. According to Microsoft a score above 25 was marginally maintainable and above 50 warranted redesign of the code. Their code came in at around 25000 [I'm sure it is not a linear scale]. It was a pointless exercise.

Such as life, the horrible code did not hurt the careers of the owners. They made lots of money. Fortunately, I've worked at major players where code, architecture and system design quality was rewarded.

Tom, wb6b

Jack, W8TEE
 

I was hired by a company who wrote banking software. There was a cascading if statement with 31 checks, once for each day of the month and its associated function call. In a code walk-through with about 20 programmers and the department head present, I point out that it was an example of RDC--Really Dumb Code--and went on to explain why. I noticed a lot of uncomfortable programmers as I spoke, figuring I had stomped a bit on their toes. After the meeting, one of the guys I new pretty well told me that the department head wrote that piece of code...the one who hired me as a consultant.

I was fired the next day.

Moral: Even RDC runs if you throw enough horsepower at it.

Jack, W8TEE

On Thursday, August 9, 2018, 4:37:50 PM EDT, Tom, wb6b <wb6b@...> wrote:


Yes, even if the optimizer automatically removed dead code, it would be a good idea to know about is, as it should not be there in the first place. Would seem if the optimizers have been improved, the gcc complier could put the dead code warning back. 

Truly sad your code was wiped out in a flood. Sounds like it did a good job of pointing out issues and enforcing a user selectable level of code quality. 

Mike pointed out a possible tool, there are others. Possibly some of them check for dead code.

Funny, I had a client that had a cash cow software service. They managed to find programmers that would do the quickest dirtiest fixes to the code and minimally thought out enhancements. Worst yet, one of the company owners hacked the original code together while he was in college for a completely different application, then modified it to the cash producing one. Was horrible code, including numerous global variables that wound through thousands of lines of code. That at any moment could be unexpectedly hijacked by other code (thanks to years of butchering by the previously mentioned cavalcade of programmers) and be doing unexpected things. 

I was attempting to shine some light of reality on the people that made demands to instantly fix things or add a new suite of functionality in a few hours. I ran a code "complexity" analyzer on a core part of the code. According to Microsoft a score above 25 was marginally maintainable and above 50 warranted redesign of the code. Their code came in at around 25000 [I'm sure it is not a linear scale]. It was a pointless exercise.

Such as life, the horrible code did not hurt the careers of the owners. They made lots of money. Fortunately, I've worked at major players where code, architecture and system design quality was rewarded.

Tom, wb6b

Tom, wb6b
 

Ouch!