Using assert calls to check coverage

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.

Continue reading “Using assert calls to check coverage”

Compile time functions

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:

static constexpr u32 function(const char* const int)

However this flexibility also has the problem that you cant be sure it will be run at run time.

Continue reading “Compile time functions”

About

General musings on things I like. I will try to keep them into separated into categories to help the reader, but the list of topics is unconstrained.

The range of items will at least include: photography, cameras, art, streaming, computers, coding, C++, programming languages, 3D rendering, vulkan, TV and movies.

The range of items is likely to be large; D&D, cameras, Streaming, Computers, TV and Movies.

It is also being used as a private note taken solution as OneNote, Evernote, etc do not solve all the requirements – Humm have not checked into Notion yet. There should be a post on that…

.

Never Nester, Goto, RAII, and Defer

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.

Continue reading “Never Nester, Goto, RAII, and Defer”

Reasons for Using C++ 17

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.

#if !((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
    #error Requires C++17 or higher
#endif
Continue reading “Reasons for Using C++ 17”

Screen Find – Seeing the Wood in the Trees

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.

Testing

Animating Alberto Garcia-Alvarez’s Phenakistoscopes using Magic

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.

Continue reading “Animating Alberto Garcia-Alvarez’s Phenakistoscopes using Magic”

Configuring WordPress

I wanted to use one of the default blogging themes, so picked a simple one from WordPress themselves. This is Twenty Seventeen.

However a few changes were needed to get it working for posts with code in it.

The main single post width needed increasing. This does not help on the mobile media, but it helps a lot when viewing wide code snippets on a full size browser window.

Continue reading “Configuring WordPress”