Category Archives: Video

Video: Meta – Toward Generative C++, Herb Sutter

Herb Sutter shared this video of his Qt 2017 talk on his personal metaclasses project.  

 

I first heard about this development at ACCU 2017. The benefits of standardising best practices for definitions of interfaces/value types etc are huge and would let the developer concentrate more on the business problem they are solving, rather than the technicalities of the language. 

  

Leave a comment

Filed under C++, Programming, Uncategorized, Video

Video: Writing good C++14 with Guideline Support Library (GSL), Bjarne Stroustrup

ISOCpp.org re-advertised the Channel9 videos from last year’s CppCon, so I thought I’d watch a couple. I started with Writing Good C++14. The slides are available here.

Stroustrup’s aim is to provide guidelines for writing simpler, cleaner C++ – then use this to spread the word of how Modern C++ can be so much better than archaic C++ idioms that have been superseded by new techniques.

But how to do it, because coding guidelines are frequently ignored or wrong. Telling what not to do is not enough – you need to do more than prohibit use of certain language features. Instead, build a set of what you should do – comprehensive, browsable, teachable guidelines.

High-level rules: philosophical approach to coding. And low-level rules: more specific, tangible rules that can be checked using tools (at least in the future) – each rule must have a rationale and an example as well as alternatives/exceptions/enforcement. And Guideline Support Library (GSL) for useful abstractions over messy/dangerous features – e.g. not_null, owner, array_view.

Result could be: productivity doubled (like a great programmer working on a modern codebase); less debugging by eliminating whole classes of errors – resource leaks, dangling pointers.

For example, dealing with range checking:

// Before
void f( int* p, int n ) // this is Stroustrup's least favourite interface!
{
    p[7] = 9;
    for ( int i = 0; i < n; ++i ) p[i] = 7;
}

// Guideline - better
void f( array_view<int> a)
{
    a[7] = 9; // checkable against a.size() e.g. in debug mode
    for (int x : a ) a = 7;
}

Example – dealing with null pointers:

// Before
void f( char* p )
{
    if ( p == nullptr ) // is it necessary to check every time?
    {
    }
}

// Guideline - better
void f( not_null<char*> p )
{
    // no longer needs to check, not_null<> cannot hold nullptr.
}

This looks pretty interesting – there’s a VS2015 plugin to run the GSL tools too. This featured in the follow-up presentation by Herb Sutter:
Screen Shot 2016-08-19 at 16.52.11

Leave a comment

Filed under C++, Programming, Video

Video: Animations

I was interested to see how animations are executed for Apple Watch apps.  These videos shed some light on it: WWDC 2015 Apple Developer Videos.  I watched:

  • Layout and animation techniques for WatchKit
  • Designing with Animation

It seems that a lot of the animations are ‘tricks’ achieved by tweaking the layout groups (either changing size, alignment or visibility).  Other recommendations include writing skeleton apps to mock animations by switching between images put together in KeyNote – this enables choosing between competing ideas without taking the time to code them all individually.

Leave a comment

Filed under Programming, Video

Video: Introducing WatchKit OS2

Catching up with this Intro to WatchKit OS2.  I found the following points interesting:

  • ClockKit has templates for watch kit complications, matching the different shapes and sizes available on the various watch faces
  • Complications should be immediately up to date when viewed, so watch kit allows you to bulk upload e.g. a timeline for a calendar widget that changes during the day.
  • Watch connectivity allows data sharing between phone and watch
  • CoreMotion, CoreLocation, MapKit and HealthKit APIs are available on the Watch

Leave a comment

Filed under Swift, Video

Video: Herb Sutter Back to the Basics at Cpp Con 2014

Herb Sutter’s Back to the Basics video is hardly an introduction to C++ as the name suggests. Rather, it clarifies his default choices when faced with some basic tasks like parameter passing, in the light of modern C++ techniques.

Don’t pass owning choices down the call stack – use non-owning raw pointers and references when you don’t need ownership transfer down the call stack, e.g. when callee parameter’s lifetime entirely nested within the called method. If the called method doesn’t participate in ownership, it should be agnostic to the lifetime of the object, whether on the stack, the heap, global, shared_ptr or unique_ptr.
image

Another reason to use auto is performance – it guarantees no implicit conversion because there’s no explicit declared type.
20150326-120815.jpg

Reviewing parameter passing choices, established rules of thumb still apply, they just got better.
20150326-121118.jpg
This is especially true for pass-by-value, which experts considered to be the new default choice for a while for moveable types, but is now only recommended for constructors that wish to retain a copy.

There was a bonus slide on returning multiple values using std::tie, which I’ve been doing for a while.
image

Finally, it seems that there’s a new term for Universal References – “Forwarding References”. I agree that this states the intention of T&& parameters better that Scott Meyer’s original name, although my eBook of Effective Modern C++ still uses the old name.

Leave a comment

Filed under C++, Programming, Video

Video: Herb Sutter on Visual Studio cross platform development

Exciting times for C++, you can now target multiple compilers and platforms from a single IDE, Visual Studio.

IMG_3544.PNG

IMG_3545.PNG

Leave a comment

Filed under C++, Programming, Video

Going Native 2013 – Don’t Help the Compiler, Stephan Lavavej

This presentation from Stephan Lavavej could have been entitled “Compiler Knows Best” – he rockets through numerous examples where the advice is to write less code and let the compiler do the right thing.

Here’s a slide of one of the key messages:

20140207-183930.jpg

Other highlights for me:

  • decltype(auto) coming in C++14 looks very cool (eliminates duplicate code when using auto with decltype for late-specified return values)
  • Don’t call std::make_pair( x, y ) – the T, U are inferred by template argument deduction, so should always be left out (unless you want to force a type conversion when T != typeof(x) e.g. short -> long
  • Use nullptr because it is convertable to all pointer types, but 0 and NULL are always type int

I love the new features of C++11 and couldn’t have written some of the cool libraries I’m working on without them. But – presentations like this make me concerned for the complexity of the language and the steep learning curve that even experienced C++ hires will have to climb.

Leave a comment

Filed under C++, Programming, Video

Going Native 2013 – Effective C++11/14, Scott Meyers

Scott Meyers presented three guidelines from his upcoming new edition of Effective C++:

  • Understand std::move and std::forward
  • Declare functions noexcept whenever possible
  • Make std::threads unjoinable on all paths

The advice on std::move and std::forward echoes thoughts from Scott’s earlier presentation on Universal References. This time, he also talks about efficiency and points out that some standard library methods (such as std::vector::push_back) won’t move unless it can do so using noexcept methods. This is the motivation for the second guideline to use noexcept whenever possible on these key methods (move operators and swap).

The guideline on std::threads harks back to the ongoing discussions in the standards committee – when a joinable (“running”) thread is destroyed, should it block/detach/terminate. Scott advises to use RAII to force the behaviour that you want, and presents a simple class for that purpose.

Leave a comment

Filed under C++, Programming, Video

Going Native 2013 – ‘new’ STL algorithms

I’ve watched a few of the Going Native 2013 videos now and, whilst I was impressed by Herb Sutter’s games written in Cinder, I particularly like the slide and gather algorithms demonstrated by Sean Parent in his C++ seasoning presentation:

template<typename Iter>
auto slide(Iter begin, Iter end, Iter target) -> std::pair<Iter,Iter>
{
    if (target < begin) return std::make_pair( target, std::rotate(target, begin, end) );
    if (end < target) return std::make_pair( std::rotate( begin, end, target ), target );
    return std::make_pair( begin, end );
}

template<typename Iter, typename Pred>
auto gather(Iter begin, Iter end, Iter target, Pred predicate) -> std::pair<Iter,Iter>
{
    auto start = std::stable_partition( begin, target, std::not1(predicate) );
    auto finish = std::stable_partition( target, end, predicate );
    return std::make_pair(start, finish);
}

Whilst I haven’t used std::rotate or std::stable_partition, I’m sure to use these two algorithms built on top of them, probably because their behaviour is so much easier to describe.

Leave a comment

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

Scott Meyers Video – Universal References

Scott Meyers posted a video of his Universal References presentation from C++ and Beyond 2012. There’s also an article on the subject in the ACCU magazine Overload Issue 111, but I found the video much clearer (and more entertaining).

Meyers coined the term ‘Universal References’ for instances where the type of a variable or parameter is declared T&& and where T is a deduced type. It may look like an rvalue-reference, but it can also match lvalue-references:

20130813-122646.jpg

so it’s usually a mistake to overload on both T&& and const T& in a template function. Another key point is that, whereas an overload with an rvalue-reference would call std::move (e.g. a move constructor where T is not deduced), an overload with a universal-reference should call std::forward (because you don’t yet know if it’s an rvalue- or lvalue-reference):

20130813-123009.jpg

He also summarises the reference-collapsing rules as “lvalue-references are infectious”, a handy mnemonic from Stephan T. Lavavej.

1 Comment

Filed under C++, Programming, Video