IET Meetup: Mountbatten Lecture, 2018

I was lucky to attend the 2018 Mountbatten lecture at Savoy Place, London. This year’s speakers were Dr Julia Sutcliffe of BAE Systems and Air Marshal Julian Young of the Royal Air Force.

Dr Sutcliffe’s theme was “Air Sector Technology – is the sky still the limit?” and spoke of breakthrough technologies such as cloud computing and artificial intelligence as the 4th Industrial Revolution (after Steam, Electricity and Electronics/Computing). Her interest in military air systems is the generation of huge amounts of information for each single flight – not only from machine performance but also from crew health metrics. It would be a game changer to be able to receive the telemetry in real time so that appropriate action could be anticipated and actioned as soon as the plane returns to base. Other topics were unmanned systems for dirty or dangerous tasks and “Chemputation“, a method for using algorithms to build materials.

Air Marshal Young’s theme was “RAF 2118 – Engineering the next 100 years”. His point was that the Royal Air Force has been entwined with technology throughout its whole life, with innovation often the deciding factor in conflicts. Innovation has produced accuracy improvements in weapons delivery as well as amazing reliability for engines (such as the EJ200 in Typhoons). Novel technologies can also deliver increased operational performance, reduce production costs and reduce through-life savings – leaving more money to buy shiny new aeroplanes.

Interestingly, multi-core processors are not currently sanctioned for use in safety-critical systems because predictability is paramount. And whilst 3D printing could potentially allow spares to be produced “in theatre”, in practice it’s more reliable to produce them at home in a factory and send them in one of the daily flights transporting crew/cargo to the area.

The RAF Engineering teams breed a culture of innovation and “restless improvement” with each new generation.

Leave a comment

Filed under Meetup

Book Review: The Afghan, Frederick Forsyth

TheAfghanSuppose intelligence discovered that a terrorist organisation was planning a fresh atrocity that would shock the world, but had no further leads to prevent it. Then it might be appropriate to take the longest of shots – send an agent into Iraq to infiltrate that organisation at a senior level, in the hope that the secret is shared with him.

So it happens that Mike Martin, a veteran of the war in Afghanistan, is sent to impersonate The Afghan (Izmat Khan), a war hero supposedly returned from prison in Guantanamo. He is accepted as a member of the Taliban, thanks to his genuine background from growing up in the region and intensive coaching on the religion and customs of the area. But the real mission is to learn about the planned atrocity and to intervene.

It’s a clever plot, if necessarily far fetched – I’d read the book some years ago and it was good on re-reading.
Four stars

Leave a comment

Filed under Book Review, Uncategorized

Book Review: The Andromeda Strain, Michael Crichton

Andromeda StrainThis book is set in the early days of the space race. Scientists have assessed the risk of previously unknown organisms being released on Earth (either alien bacteria brought back to Earth by rockets or Earth-bound organisms changed by exposure to the environment of space). The result is Wildfire – an underground facility with multiple levels of increasing levels of sterilisation, in which the scientists would research any such contaminated material.

The plot is that a satellite has indeed brought back some terrible disease that has killed many people in the vicinity by solidifying their blood. This include two soldiers sent to retrieve the satellite – but there are two survivors, a baby and an old man. The scientists are summoned to the Wildfire bunker to investigate the nature of the disease and the book tells the story of their tests and endeavours as if from a retrospective.

Reviews of this book frequently admit that the reader was convinced that the story was true – I had that impression too, particularly given the fake acknowledgements to those ‘who encouraged me to tell the story accurately and in detail’ at the start of the book and the heavily academic bibliography at the end.
Four stars

Leave a comment

Filed under Book Review, Uncategorized

C++ London Meetup: Tuppence more on Standard Algorithms

This evening of talks was split into a set of Lightning Talks in the first half followed by a discussion about the Standard Library in the second half.

Part 1 – Lightning Talks
Richard Chandler – ACCU 2018 Trip Report – much on C++14 and C++17 standards to catch up on as well as introduction to Kotlin and a number of talks on diversity and inclusivity.

Phil Nash – East End Story
Phil dived into the controversial East Const v West Const debate

    void f( T const& t ) // East const
    void f( const T& )   // West const

i.e. should you put the const before or after the type. This topic was introduced by Dan Saks in 2011 – Simplifying const Syntax, Dr Dobbs and revived by Jon Kalb in A Foolish Inconsistency.

“Const applies to what is on its left, unless there is nothing to the left, in which case it applies to what is on the right.” But using east const format, it always applies to the left! West const reads more naturally from left to right, e.g. “const integer” – the East const argument is that you would always read declarations inside out and right to left!

    char const * const pc = str // pc is a const pointer to a const char, reading right to left

Developers are already accustomed to using East const for const member functions (must put const on the ‘east’ side). And there are other examples of going East:

    // moving the return type further east as a result of c++11
    auto someFunc( int i ) -> std::string; 

    // you have to put the return type on the east side
    auto lambda = [] -> double { return 0; } 

Other considerations: Swift/Haskell have trailing return type; putting auto at the start of list of function definitions, the start of the names line up; C++ standard NL.26 says use conventional const notation, endorses West Const notation, but is itself inconsistent!

Phil is now using trailing return types everywhere in production code – see his blog, East End Functions (LevelOfIndirection.com)

Stewart Becker – A Fool’s Consistency, the rebuttal (Jonathan Muller’s talk)

East const gives more consistency? If 83% of people write const T (i.e. West const), you need to be consistent with everyone else in your codebase.
Const pointer to const fallacy – with modern c++, use const std::string_view instead. Can use std::as_const(x) to get the const cast.
Right-to-left fallacy – but we read loops etc from left to right, and ‘const’ is an adjective which goes before the noun in English.
Clockwise-Spiral rule for function pointers.

const east west const – you are allowed to write const in both the East and West positions!!

Part 2 – Tuppence More on Standard Algorithms – Iakov Sergeev
Iakov believes the standard algorithms should make code easier to implement and read, but are forgotten in practice. He raised issues with inconsistencies and the learning curve to use STL (output iterator, predicates, modifying input sequences, could take both begin/end iterators).

Historically, the predicates were hard to implement where you had to supply a functor to call algorithms. Now, with lambdas, it’s much easier and localised to call algorithms.

The audience felt that Eric Niebler’s work on the Ranges TS should help a lot with adoption of standard algorithms.

Leave a comment

Filed under C++, Meetup, Programming

Book Review: A Legacy of Spies, John leCarre

I was given a lovely hardback edition of this book for my birthday. Whilst this book stands alone, I’m sure I miss much of the sentiment portrayed by the lead character, Peter Guillaume, because I haven’t read any of the George Smiley series before.

There are two main storylines. In the present day, Guillaume is interrogated by the British Secret Service as to his role in Windfall, a cold war operation. The Service is being sued for negligence by descendants of two dead agents – Guillaume is still liable even decades after the event. In the past, we follow Guillaume’s life as an agent from his recruitment through to working with his best friend Alec and the resulting fiasco that took Alec’s life.

The story is beautifully told and reveals its secrets piece-by-piece as if we’re viewing it through a fuzzy lens – perhaps as the cold war agents would have discovered the information themselves.

Leave a comment

Filed under Book Review

C++17: Lambdas

C++ has supported lambda functions since C++11, and post-C++14 even supported generic lambdas. C++17 adds a quirky feature to enable ‘copy capture’ of ‘this’. Here’s an example of it in action:

struct MyStruct
{
    auto lambda_with_this() // Before C++17, copies this pointer
    {
        auto f = [this]{ return value; };
        return f;
    }
    
    auto lambda_with_star_this() // C++17 - takes a local copy of *this
    {
        auto f = [*this]{ return value; };
        return f;
    }
    
    int value;
};

TEST( Cpp17, lambda_capture_this )
{
    MyStruct s{ 42 };
    auto f = s.lambda_with_this();
    s.value = 101;
    EXPECT_EQ( 101, f() );
}

TEST( Cpp17, lambda_capture_star_this )
{
    MyStruct s{ 42 };
    auto f = s.lambda_with_star_this();
    s.value = 101;
    EXPECT_EQ( 42, f() );
}

Notice that in the second case, we capture a copy of our object – so the lambda returns the value held at the point of capture (42) rather than the value when it is called (101). This can be very important if ‘this’ has been destroyed between the creation of the lambda and the time at which it’s called.

Now, C++14 also supported generalised lambda capture, which meant you could (re-)name variables when capturing (and provided a neat way to capture-by-move):

    auto f = [tmp = *this]{ return tmp.value; };

But the C++17 code is more concise. See this useful StackOverflow post for more discussion.

Another advance in C++17 is that lambdas are implicitly constexpr – so you can now use them in compile-time contexts, like declaration of std::array:

// lambda explicitly constexpr since C++17
auto square = []( auto v ){ return v*v; }; 

TEST( Cpp17, lambda_implicitly_constexpr )
{
    // std::array calls 'square()' at compile time
    std::array<int, square(4)> values; 
    EXPECT_EQ( 16, values.size() );
}

See also the previous C++17 post.

Leave a comment

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

C++17: Nested Namespaces

Another crowd-pleaser in C++17 is the ability to declared nested namespaces without literally nesting them. In the past, you had to do this, which involves a lot of wasted whitespace:

namespace NestedNamespaces
{
    namespace Really
    {
        namespace Work
        {
            auto return_int(){ return 42; };
        }
    }
}

Happily, you can now do this instead:

namespace NestedNamespaces::Really::Work
{
    auto return_int(){ return 42; };
}

TEST( Cpp17, nested_namespaces )
{
    EXPECT_EQ( 42, NestedNamespaces::Really::Work::return_int() );
}

See also previous C++17 post.

1 Comment

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