I heard a great development process idea from Tom Forsyth where he explained that he litters his code with assert(true) to make sure that he hits all the key code paths during early testing.
This got me thinking about asserts and code coverage.
Code coverage is an evil that kills the sole of testers. It is treated as an absolute and they are forced to try to hit 100%. A much more efficient approach is to have humans spend real thinking power about where and what needs to have code coverage checked. Sure this is not black box testing, but a clever mix of black box, API, edge case, and coverage testing is a much better approach.
While C++ lags behind new languages for support at compile time, there is some ability to get some of the advantages.
A simple case is to create a allow a runtime function that is simple enough to be run at compile time. This has the nice feature that if the function is not able to be used at compile time it will still work at runtime. Thus this can be done for many functions:
Coding when you are using an OS or library that requires a series of calls that build on each other to get the final result requires a set of checks to make sure each stage is successful. If some of the stages also require it partner call to free/close/destroy the items, then the programming logic requires you to be careful in how you tear down the items if there is an error in the middle of the process.
This can be coded several ways, and this post discusses a series of approaches in C++. The code selected for the example is performing Windows OS calls. These are done at the lowest API level without any other library or framework. The code has three places where tear down is required. The flow is complex enough to stop a simple reorganisation of the code to perform the same task. There is no addition error management present so make it easier to read. It is a fully working program and it gets a list of USB devices that the program is allowed access to.
Using the logic that we should use tools that are as simple as possible and only adopt complexity where it is absolutely necessary, it feels like I could use a very early version of C++. What follows are the reasons why I have increased that to C++17. The idea will be to only use these feature and no more. Any new use will be add to this page.
I hope you have a nice big screen – or several of them. Nice huh?
Well all this real estate comes with a price. Some times the screens can hold so much information it is hard to find what you are looking for. Would it not be nice to be able to search for the word you are looking for in a huge list of dense text?
Sure almost every app has search, but can you search the dialogue boxes, the drop down menus, the image of a poster?
So why not have a system wide special key combo that triggered a find dialogue box. Type in ‘comment’ and the screens are captured, OCR’ed and then if the text is found an overlay highlight shows you where the word is.
Tim Melville Gallery had an exhibition of Alberto Garcia-Alvarez’s work. I love the strong and bold colours. I guess with circles and a subject of ‘Time’ it was hard for me not to be enamoured. I explained to Tim that it would be easy to take the static images of the Phenakistoscopes and turn them into a movie to show what they really looked like if they were being used as intended. He said for me to try it and this story is the outcome.
With a little messing about, I managed this with the minimum of tools. Just a CMD batch file to loop through the commands, ImageMagick commands, and Gimp to find the centre and size of the circles.