worldwideqert.blogg.se

Loopy code
Loopy code










If it is, we construct a directory iterator from it at (3) and iterate through each path of that directory to see if we have a regular file and at (4) create two boolean flags, ‘good and ‘useable’ (yes, they are bad names), at a high enough scope that they can be seen wherever needed and far enough away from the point of use, that they are confusing – even a few weeks later.įrom (5) we test the current file to see if it is large enough and has the correct suffix. We need to know if the path exists and whether it is a directory. Std::string pathSuff( possPath.substr( possPath.length() - 10))Īt (1) above we begin by constructing an iterator for the vector of strings and then from (2) we iterate through the strings and from each construct a boost filesystem path. simplified here, tests for suitable suffix setting useable not required, it is already false, here for 'clarity'. in scope in all conditional cases below test file for suffix and size, handle/log errors log the error - config should provide paths to dirs.įor( bfs::directory_iterator dirIt( myPath) dirIt != bfs::directory_iterator ++dirIt) If( !bfs::exists( myPath) || !bfs::is_directory( myPath)) member variable, std::vector pathStringsįor( strIter = pathStrings.begin() strIter != pathStrings.end() ++strIter) Here is the code: namespace bfs = boost::filesystem A couple of weeks later in testing, it was discovered that the function did not quite always do what it was supposed to do and I had to fix it! This turned out to be difficult because the two week old function was so hard to understand.

LOOPY CODE CODE

The code has to build in a system using the Borland Classic compiler (shipped with Embarcadero Berlin around 2016, so not old) and therefore cannot use many features of modern C++. The following examples are simplified for clarity (but hopefully not too much to make the old code easy to read). Once found, the files would be checked to see if they were valid for the next stage of processing, otherwise they would be rejected, renamed and logged. Given a container of strings representing paths, the requirement was to search for files with a certain suffix.

loopy code

We reflect on the mental barriers to using the STL in the first place.

loopy code loopy code

In this article we examine some code that was difficult to understand only a week after it was written, and how by using the STL it was converted into something more pleasant to reason about and maintain. Gary works for Marlan Maritime Ltd, a company concerned with maritime safety and the monitoring/mapping/management of changing coastline using radar. This is a guest post written by Gary Taverner.










Loopy code