Category Archives: Programming

ACCU Meet-up: Lies, Damn lies and Estimates, Seb Rose

Seb Rose gave an excellent presentation on the difficulty of providing estimates in the software industry. He debunked some myths, including the shape of Cone of Uncertainty, and recommended several books on the subject for further reading:

The Leprechauns of Software Engineering 20141021-143907.jpg

A few other points to take away:

  • We are best at estimating small tasks, so split them into 1, 2 or 3 days tasks
  • Express estimates as a range with a confidence level – 90% confident that will take between 2-3 weeks
  • Communication with stakeholders is most important – assess the impact on upstream and downstream systems

I’ve downloaded the Leprechauns eBook – it’s main intention is to persuade the reader that several views that are taken for granted have not been proven in the literature – such as the Cone of Uncertainty as projects progress (the further into a project, the less error in estimates) and the 10X Programmer (some programmers are ten times more productive).

For what it’s worth, my view on the 10X Programmer issue is that, whilst it’s hard to gather the necessary evidence to compare performance across real world projects, there’s little doubt that some developers add much more value to a project than others. This is true of any human activity – queuing in a coffee shop with a handful of baristas serving while the queue barely moves, it’s usually possible to tell the one person who’s actually getting any work done. On holiday, I watched at a cycle hire place while one guy served at least three times as many families as any other.

It may not be 10X productivity in programming, but a star developer will: eliminate swathes of work by adopting a suitable 3rd party library; consistently check-in code that works (unlike his unproductive colleague who always breaks the build and leaves edge cases untested); produce intuitive user interfaces, reducing the hours of support to train new users.

I have Waltzing with Bears on order – PeopleWare by the same authors was excellent, so looking forward to this one.

Leave a comment

Filed under Meetup, Programming, Soft skills, Technology

Bruce Dawson – crash investigator

Another great post from Bruce Dawson,
with some valuable tips to check compiler flags in Visual Studio to aid debugging of an entire class of crashes.

/GS, /NXCOMPAT, /DYNAMICBASE, /analyze and all its associated labors – plus actually fixing the bug – took a lot of time, but it was definitely worth it. Most of these changes were trivial and had huge payoffs. Running /analyze was by far the biggest task but, like other smart programmers, I am convinced that it was invaluable. Entire classes of bugs – serious crashing bugs and crazy logic errors – that use to show up quite frequently are now entirely extinct. It is not often that you get to entirely eradicate dozens of types of bugs and doing this definitely increased developer productivity and product reliability.

I’ll certainly check these are set for the projects that I own.

Leave a comment

Filed under C++, Programming

How to achieve pattern matching in C++ using boost::regex

Suppose you are parsing text input and need to handle the string representation of a field that could have several formats. In that case, using regular expressions is appealing because you can try a number of patterns sequentially (taking the most likely first) and exit when you get a match.

When I tried to do this in C++, I found it hard to find an easy example to follow. Here’s the way I’ve been doing it, based on a simple example to parse a length that could be in any of several units of measure:

    #include <boost/algorithm/string_regex.hpp>

    void parse( const std::string& candidate )
    {
        boost::smatch value;

        if ( boost::regex_search( candidate, value, boost::regex( "(.*)ft(.*)in" )) )
        {
            auto feet = atol( value[1].str().c_str() );
            auto inches = atof( value[2].str().c_str() );
            std::cout << "Matched " << feet << " feet and " << inches << " inches\n";
        }

        if ( boost::regex_search( candidate, value, boost::regex( "(.*)m(.*)cm" )) )
        {
            auto metres = atol( value[1].str().c_str() );
            auto centimetres = atof( value[2].str().c_str() );
            std::cout << "Matched " << metres << " metres and " << centimetres << " centimetres\n";
        }

        if ( boost::regex_search( candidate, value, boost::regex( "([0-9]+)mm" )) )
        {
            auto millimetres = atol( value[1].str().c_str() );
            std::cout << "Matched " << millimetres << " millimetres\n";
        }

        throw std::runtime_error( (boost::format( "Failed to match candidate '%1%' with ft/in, m/cm or mm" ) % candidate).str() );
    }

This only uses a fraction of what can be done with regex – the point is to show how to use boost::regex. One gotcha is that, as per the code above, the string matches that are written into value are indexed from 1 – for some reason, the zero’th index accesses the whole candidate expression. Another gotcha is that boost::regex is one of the few boost libraries that isn’t just implemented using templates in a header file, so you also have to add the appropriate .lib into the linker inputs.

1 Comment

Filed under C++, C++ Code, Programming

Usability woes

When working remotely, I am able to log into my desktop machine and work pretty much as if sitting at my desk in the office. Unfortunately, though, whoever wrote the remoting layer thought that “SHIFT+F3” would be an inconspicuous shortcut for logging out immediately, without even a confirmation dialog box.

20140922-093736.jpg

My main applications include Visual Studio and Excel – so I log myself out several times a day when in-the-zone and either searching code or editing functions respectively.

I’ve resorted to taking the key out to avoid the reconnection penalty every time this happens.

Leave a comment

Filed under Musing, Programming

LINQ for C++ by Steve Love

The October 2013 issue of Overload includes an article by Steve Love on building a range library that enables LINQ like syntax in C++.

20140827-141310.jpg

This looks pretty good and is along similar lines to the approach in cpplinq.

Leave a comment

Filed under C++, Programming

Interview with Bjarne Stroustrup

Short interview with Bjarne Stroustrup where he comments briefly on Go and Swift.

Apparently, Stroustrup is currently working for Morgan Stanley – hence his interest in C++ for financial applications.

Leave a comment

Filed under C++, Programming

How to investigate rebuilds in Visual Studio

You never know when this tip from Kiri Osenkov might come in handy – how to investigate why Visual Studio keeps rebuilding before running, even when you think nothing has changed.

Leave a comment

Filed under Programming

How to generate tests under GTest

One of the many features provided by GTest is the ability to generate test at runtime. One useful application of this is that you can execute data-driven testing by obtaining a list of test file names, then generating a test for each of them. It’s actually very simple to do this in GTest – they call these value-parameterized tests (see documentation). Here’s a snippet of code to demonstrate how little overhead is involved:

#include <gtest/gtest.h>

using namespace testing;

// placeholder - could be used for test setup/cleanup
class MyTest : public ::testing::TestWithParam<std::string>
{
};

TEST_P( MyTest, IntegrationTest )
{
    std::string test_file_name = GetParam();

    // open file and run the integration test
}

std::vector<std::string> test_file_names();

INSTANTIATE_TEST_CASE_P( MyLibraryName, MyTest, test::ValuesIn( test_file_names() ) );

On one hand, this approach isn’t really in the spirit of unit test – data-driven tests have a habit of quickly escalating to integration tests between libraries. However, such integration tests also have their place in a testing strategy, and this is a neat way to accomplish it with minimal overhead.

1 Comment

Filed under C++, C++ Code, Programming

Development processes at Microsoft

This article provoked a lot of discussion about software development and architecture where I work.

With a few more weeks for managing the transitions between the phases of development, some extra time for last-minute fixes to both the beta and the final build, and a few weeks to recover between versions, the result was a two-year development process in which only about four months would be spent writing new code. Twice as long would be spent fixing that code.

For me, this paragraph sums up where multi-year release cycles are just plain wrong:

In addition to making the Visual Studio team enormously unresponsive, this development approach wasn’t much good for team morale. A feature developed during the first development phase wouldn’t properly get into customer hands for the better part of 18 months. For Windows and Office, with their three-year cycles, the effect is even worse. A developer could be waiting more than two years before the work they did would ever make it to end users. Most developers actually want their software to be used; it’s just not that satisfying to know that you’ve implemented some great new feature that nobody will actually use for years. With Microsoft’s long development cycles, a developer may not even be on the same team—and may not even be at the company—by the time their code makes it to desktops.

Leave a comment

Filed under Programming

F# equivalent of C++ ‘Most vexing Parse’

I first read of the C++ “Most Vexing Parse” in the Scott Meyers Effective C++ series. For reference, here’s the code:

double aDouble;
int i(int(aDouble)); // This doesn't do what you think

The commented line actually declares a function i that takes a single integer parameter and returns an integer. Now, today, I saw something similar in F# that made me scratch my head and I think is similar:

let func a b c =
    return a + b + c

let main () =
    let sum = func a b
    // use sum
    0

The symptom was that my function (here, called func) wasn’t being called. Yet stepping through in the debugger, I could break on the line that called it – yet it wouldn’t step into the function! Of course, by missing one of func’s parameters in the function call, I’d actually declared sum to be a new function taking one parameter (or to use functional terminology, I’d curried a and b).

This is hard to spot when the calling code and function declaration are in separate files and when you’ve added a new parameter to the function and it still compiles but doesn’t do what you expected!

Leave a comment

Filed under Programming