r/WarmZero • u/Remus-C • May 29 '24
Unexpected Outcome - Chapter 3
Unexpected Outcome - Chapter 3 - Act for the future
With power (to do something) comes responsibility (to live with it, to manage it or avoid it).
See first << Chapter 1 <<
Now that I know how this unexpected result can occur...
- Is this unexpected result intentional?
If so, mark it and move on.
How to mark it? That depends first on your coding rules and second if the tools can be instructed to know about. - Is this unexpected result not desired?
If so, How can this exceptional case be detected with minimal effort?
A possible solution:
- Create tests for this function.
- Test phase must fail if coverage is less than 100%.
Minimal effort overall:
- Tests are written once but run multiple times.
- The overall effort is low for each run, much less overall than the effort for a possible next investigation from scratch for the same problem.
Of course, the same approach can be used for the case of intentional behavior as well. Nothing stands in the way.
Notes:
- C+- concept asks for 100% coverage. Unexpected results are caught.
- With Abc and
*.test.*file names it is simple to create in-place tests, then benefit from them.
Q: What is your approach given your context?
2
Upvotes
1
u/Remus-C Jun 10 '24
// (In my context)
My coding conventions are not specified here, as they certainly differ to a great extent compared to your coding conventions.
I consider more important the analysis and decision for the future for a certain class of problems.
And of course this is my opinion in my context. Your opinion may differ due to different context and experience.
1
u/Remus-C Jun 10 '24
// (In my context)
The build tools are used to inform the developer about possible known problems.
Not all the time, but most of the time. As appropriate, if it makes sense for a coding convention. First comes safety. Second comes speed.
Better to be informed sooner than to find out at the review and go back. Or worse, find out after release because the client called.
[1] If the compiler has a warning for a particular problem, great!
[2] If the compiler does not cover a potentially important case, then maybe a code checker will do the job.
[3] And there are rare cases when a warning/error is important and a tool is not yet available.
What to do?
Create your own code checker or maybe an awk script or maybe repls is good enough etc. What works best and is fast enough.
Any change in the build chain is evaluated for a while:
Developers usually use parallel and incremental builds, so most of the time the impact is negligible. Regarding safe code: On dedicated build computers or before a release, all steps are enabled anyway.
1
u/Remus-C Jun 10 '24
// (In my context)
There are code conventions defined and used. The list rarely grows or shrinks.
The list of conventions grows because:
The list of conventions is shrinking because:
1
u/Remus-C Jun 10 '24
// (In my context)
Code coverage with tests - for sensitive parts this is a must.
To be effective, there must be 100% coverage. Otherwise, say for 80% coverage, bugs enjoy hiding in the remaining 20%. And besides, if a part is too hard to create tests for, then it's a good candidate for redesign anyway.
Minus:
Plus:
These tests can be added to the build chain.\
1
u/Remus-C Jun 10 '24
// (In my context)
For "Unexpected Outcome" - in case of "float/double":
1
u/Remus-C Jun 10 '24 edited Jun 10 '24
// (In my context)
For "Unexpected Outcome" - in case of operator overloading - the behavior is intentional:
It's great that the language allows operators to be redefined to such an extent.
As long as the developers know what they are doing, one can write clearer/abstract/shorter code that is better suited to the invented concepts.
1
u/Remus-C Jun 10 '24
// (In my context)
For "Unexpected Outcome" - in case of operator overloading - the behavior is indeed unexpected:
1
u/Remus-C Jun 10 '24
// (In my context)
For "Unexpected Outcome" - considering the scope:
As it was written without indentation, it appears that its scope is global. But how does the compiler see it?
In this case, "virtual" is missing. Coding conventions and code checkers require "virtual" in this case.
But there were no complaints during the build... hmm... Broken build chain? OR - mispelled function name? OR - mispelled types?