Monthly Archives: May 2016

Book Review: Moon Dust, Andrew Smith

MoonDustThis book tells the journey taken by the author in his attempts to find and interview all the remaining astronauts who have walked on the moon. Twelve men in history have known what it is like, and at the time of his writing, only nine were alive. The book describes the impact such an event had on the lives of the men.

It’s an interesting read, primarily it’d good to hear about astronauts other than Buzz Aldrin – the others have just as interesting stories, both of their lunar expeditions, and the effect on their lives afterwards. Yet, the media attention is generally given to Buzz Aldrin these days, with his ideas on colonisation of Mars.
Three Stars

Leave a comment

Filed under Book Review

IET Meetup: Robots Helping People, Yiannis Demiris

IETLogo
Meetup - Robots helping PeopleProfessor Yiannis Demiris gave the latest Prestige Lecture at the IET. His work is truly inspirational – his research aims to develop robots that can help both children with disabilities and adults with chronic or mobility problems. A running theme throughout his talk was the need for the robot’s behaviour to adapt during the life of the relationship with the person – as the person learns a skill, the robot can lower its levels of assistance. Or, the robot can take the person to the next level, for example in therapeutic exercises or in gaming.
YiannisDemiris
The speaker heads the Personal Robotics Laboratory at Imperial College London, where he conducts research in personalised assistive robotic systems, with applications in healthcare, in-vehicle intelligence, and support for children and adults with disabilities.

Leave a comment

Filed under Meetup, Technology

How to initialise data concisely in C++

In the past, creating a collection of dates was a chore, because you had to individually insert them into a container (e.g. declaring a vector on one line and then pushing dates into it on subsequent lines). With features like std::initializer_list from C++11 onwards, it’s now much easier to do this concisely.

Here’s some simple, concise code to create dates without all the hassle:

struct Date
{
    std::string Event;

    int Year;
    int Month;
    int Day;
};

void print( const Date& date )
{
    std::cout << date.Event << ": "<< date.Year << "/" << date.Month << "/" << date.Day << "\n";
}

void print( const std::vector<Date>& dates )
{
    for ( auto date : dates )
    {
        print( date );
    }
}

void test()
{
    std::cout << "Print date:\n";
    print( { "Today", 2015, 5, 5 } );

    std::cout << "Print dates:\n";
    print( {
        { "Christmas", 2015, 12, 25 },
        { "Spring Bank Holiday", 2016, 6, 30 }
           } );
}

This style is particularly useful when writing tests – you can write a whole test, including setting up the data, on a single line (or at least, in a single function call).

Another compelling use case comes when creating test cases for graph algorithms. Suppose you have the following data structures for an undirected, weighted graph:

struct Edge
{
    const size_t end1;
    const size_t end2;
    const size_t cost;
};

struct Graph
{
    size_t source;
    size_t nodes;
    std::vector<Edge> edges;
};

Then creating a test graph to pass into an algorithm is as simple as:

shortest_path( { 0, 4, { {0,1,24}, {0,3,20}, {2,0,3}, {3,2,12} } })

Leave a comment

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