Tuesday, March 5, 2019

C++ On Sea Trip Report! - Day 2

Day 2

Day 2 didn't have an opening Keynote so let's jump right in!

The Hitchhiker's Guide to Faster Builds ⭐⭐⭐⭐🍟

By Viktor Kirilov - author of doctest - "The fastest feature-rich C++98/C++11 single-header testing framework", focus on game and game engine development.

This talk was a thorough list of all the things you could try to make your build time shorter! 
Some highlights:

  • templates and inlining functions is more work for the compiler/linker
  • debug builds take less time to build because compiler does a lot less
  • Remove unused code! 
  • Remove unnecessary includes!
  • Move function definitions out of headers!
  • Pre-compiled headers
  • Unity files (not Unity the game engine)
  • The "Rule of Chiel" - SFINAE is very expensive
  • compiler cache
    • maps a hash of preprocessed source to object files
    • first run (cold cache)
    • successive runs (warm cache)
  • C++20 modules will improve compile times! 
    • exports BMI (Binary Module Interface) produced by MIU (Module Interface Unit)
    • importing these won't recompile them
    • BUT - there won't be huge gains initially as it will take time for people to adopt modules in their code


Diffuse your way out of a paper bag ⭐⭐🍟

By Frances Buontempo - editor of ACCU’s Overload magazine, focus on machine learning, data mining.

This session was mainly using mathematical formulae to influence the animation to create randomness. Frances explained the random formulae and terminology a little, Brownian motion, stochasticmersenne twister, uniform/normal randomness, etc. 


Learning (and teaching) modern C++ - Challenges and Resources ⭐⭐

By Arne Mertz - author of blog "Simplify C++!", focus on modernising old C++

This session went through all the different resources you can use to learn/teach C++ and the pros and cons of each method. 
Modern C++ is a moving target and teaching/learning it can be difficult because the rules are changing every few years!
For example, you can write a book about C++17 features but if you want it to be published at the same time as the official C++ version release, then you will have to write while the language development is not yet finalised and so you could end up publishing incorrect material. On the other hand, if you write the book once the language features are released, then it will only be valid for a shorter amount of time, until the next version of the language comes out. 
I went to this talk hoping to be given an answer to how to effectively learn/teach c++ so I was a little disappointed that the talk was more of a general list of all the material you could use. The conversations that sparked after the talk from different Q&A was quite interesting though, because different people were talking about their experiences of how they managed to learn or teach.


Quickly testing legacy code ⭐⭐⭐🍟

By Clare Macrae - Principal Scientific Software Engineer at Cambridge Crystallographic Data Centre focus on research engineering

Here, the speaker was explaining about a framework she had worked on called Approval Tests which is available in other languages but wasn't, until now, for C++. She talked about how we often get stuck in a horrible loop with legacy code testing like this:



In such dilemmas, you can use a method of testing legacy code called "Golden Master Testing". This is a very high level "test", in that you save the output of your code in a text file and compare the file before and after you make code changes. AKA - "Poor man's integration test". Well the Approval Tests framework enables you to do this quickly with popular C++ testing frameworks gTest or Catch2. 

I actually tried to use the framework during a company hackney to try and test the legacy code I am tackling at work but I couldn't really get my methods to output anything that I could easily save in a text file. Also, the project was so lacking tests that it first took me half a day to build the one test package we already had, and then I didn't really know how to set up the framework to work within our tests. 😕 I think the framework would work better in the example scenarios that she gave, where they had functions that output an image. 



Keynote: What Everyone Should Know About How Amazing Compilers Are ⭐⭐⭐⭐⭐🍟🍟🍟

By Matt Godbolt - creator of Compiler Explorer

This final keynote was given by Matt Godbolt, who created the widely used tool - Compiler Explorer. This talk was a really excellent introduction to reading assembly - which is essential to using his tool and following a lot of online C++ content such as Jason Tuner's C++ Weekly. He started the talk by saying that after the talk, he wants everyone there to be able to understand assembly by the end of the talk and compared it to like reading Shakespearean poetry - "You pretend to like it, you kinda glaze over it and kinda get the gist, and at the end you're like 'That was actually quite good!'" 😂

And you know what? At the end of his talk that is exactly how I felt about reading assembly! 😂😂 So he definitely achieved his goal! 

I don't really want to spoil the talk by trying to explain it all here - he really explains it well. But basically, he went on to explain the basics, then gave examples of how the compiler does an awesome job of optimising your code, so don't try to be clever and do bitwise shift etc. in your code, because your compiler knows better! 
I really really recommend watching this talk! 

https://www.youtube.com/watch?v=w0sz5WbS5AM



And that's it! It was a very good conference and I think the only constructive feedback I had was that the break/lunch times were a bit too long so for those of us who went alone and aren't very good at striking up conversation with strangers, 90minute lunch time was a little too long to try and keep up a conversation haha 😅

But I look forward to going next year! Thanks for reading 😊

Tuesday, February 19, 2019

C++ On Sea Trip Report! - Day 1


Earlier this month I went to the C++ On Sea conference, sponsored by my company, King. It was the first of it's kind organised by Phil Nash, organiser of London C++ Meetups, and it was really great! 


There were a number of famous C++ speakers such as Jason Turner, Kate Gregory and Matt Godbolt, to only name a few! 


The only thing that was unfortunate was the weather and since the venue was a lovely old 19th Century theatre, the rooms did not warm up much and kept us on our toes 😅 The venue, Leas Cliff Hall, is in Folkestone, where the channel tunnel is also located, so it was a convenient location for those travelling from Europe and would have been lovely if it was sunny!




The conference was 2 days long and there were workshops on the third day. I attended the 2 day conference and the Meet the Speakers Gala Dinner at the end of the first day. This was a really nice occasion to speak to other attendees so you have some familiar faces at the conference the next day 😄 , but also to have the opportunity to speak to the speakers of the conference, get to know them, ask them specific questions about something you've been wanting to ask! I had the opportunity to sit next to Nicolai Josuttis, who is the author of many C++ books, including 'The C++ Standard Library', 'C++ Templates', and he is currently writing 'C++17 - The Complete Guide', which he gave a free electronic copy of to all attendees of the conference! You can find the e-book here

Below, I'll cover each of the talks I went to briefly and give my two cents. 

Key:
Overall quality of content and delivery: ⭐ - 
How code heavy the talks are: 🍟 (snack-able), 🍟🍟(decent portion), 🍟🍟🍟(overload)

Day 1

Keynote: Oh The Humanity ⭐⭐⭐⭐⭐ 🍟

Kate Gregory - author, speaker, mentor, project leader

In this excellent talk, Kate opened our eyes to the fact that there are emotions in code!  Say what? Well, not in the sense that the programs are becoming sentient and will take over the world! She was talking about how the programmer's emotions are reflected into the code that we write. These emotions are often:
  • Fear - eg. "Maybe I'll need this code later so I'll just comment it out."
  • Arrogance - eg "I know what these variables mean and what this method does, so why should I name it properly? If other people can't understand it by reading the code, then that's their problem."
  • Selfishness - eg. "Why should I spend my time making things easy for others?"
  • Laziness - eg "Whatever, it works."
But these emotions be replaced by positive emotions with a little care from ourselves:
  • Confidence
  • Humility
  • Generosity
  • Caring
She emphasised how we are all human - not robots, and it's ok to have emotions. It's ok to show emotion and we shouldn't try to be like Mr. Spock because it's good to have emotions! We should share the positive emotions with each other - through code - to make the world (and the code base) a better place! 😆

Postmodern immutable data structures ⭐⭐⭐🍟🍟

Juan Pedro Bolivar Puente - consultant engineer, focus on interactive software, functional programming and open source strategy

This talk was about the benefits of having immutable data structures and how to use his library for persistent and immutable data structures to achieve a stricter yet more elegant software architecture. He was describing how copying of data is a common problem we have in C++, and the cause is because we pass objects by value. However, the root cause is the mutability of the object. 


He introduced us to the Uni-directional Data Flow architecture, which is common in front end languages such as React, and explained how this Action-Model-View architecture can be used instead of the traditional Model View Controller architecture, where you end up having a reference or a listener everywhere and can become messy. 


He gave a detailed example of how you can use his library, Immer, to implement the 'undo' feature in a text editor he wrote using it, Ewig, and how performant this architecture allows it to be. It was quite impressive because even when copy-pasting/undoing large amounts of text (I think it was like 2GB), it was almost instantaneous and it wasn't freezing up the editor like you would expect it to. 


Unfortunately, there were some technical difficulties with the slides and the talk didn't run smoothly, which is perhaps why I couldn't appreciate the content as much but I believe he gave a similar talk at CppCon 2017, where I believe the delivery was better and you could actually see the code on the screen 😅 Although I think his demo had more updates since the one from 2017.


https://www.youtube.com/watch?v=y_m0ce1rzRI



Fast and Small - What are the Costs of Language Features ⭐⭐⭐⭐⭐🍟🍟

By Andreas Fertig - lecturer, trainer, focus on practical and theoretical knowledge of C++ at various operating systems. Creator of cppinsights.io

In this talk, Andreas Fertig gave examples, using Cpp Insights, of the seemingly harmless mistakes you can make that may result in unwanted behaviour and bugs. Therefore the importance of following good practices. 


Recommendations from the talk:


  • Use auto& and auto* for consistency
  • Default to using const auto& BUT use auto&& when writing generic code/abstraction/templates
  • Beware of decltype auto brackets:
    • decltype (auto) b = foo; <=copy
    • decltype (auto) d = (foo); <=reference!
  • Incrementing variables
  • If you ever see this, remove the brackets because it's an old C-style return statement
    • return (x);
  • auto can optimise better than when you know your type
  • Beware of lambdas - the compiler is actually creating an anonymous class
  • Watch the Jason Turner Cpp Weekly Stateful Lambda episode 
  • Static variables are initialised the first time the program passes the declaration and this is controlled by a boolean flag to say whether it has already been initialised. It is not thread safe pre-C++11. Post-C++11, there is a mutex to control thread safety.


Practical Performance Practices Revisited ⭐⭐⭐⭐⭐🍟🍟

By Jason Turner - regular conference speaker, developer, and trainer. Host of YouTube channel C++ Weekly and co-host of CppCast. Author of ChaisScript.



In this talk, Jason Tuner gave a talk in 2016, where he gave  recommendations on best practices using examples from when he was trying to improve the performance of his ChaiScript. This talk was him giving an update on those best practices, now that there is new functionality and new best practices for C++17. His talks are always fast paced and very interactive make sure you are fully awake and paying attention otherwise you'll be left behind! 
  • std::array in C++17 is very optimised and even better than vector. Always prefer to use std::array over std::vector over std::list, map, etc
  • constexpr All The Things! 
  • Use IIFE - Immediately Invoked Function Expression
  • Reduce the amount of branching in your code!
  • Don't add virtual destructors if you don't need it because it disables the move constructor
    • this can be up to 10% less efficient
  • Don't declare variables until you need it, but don't declare at all if you don't need it! 
  • std::endl flushes so use \n 
  • Try not to use: 
    • shared_ptr
    • std::map
    • std::deque
  • Smaller code is better because if it can fit into the CPU cache, it'll be faster!
(no youtube link yet!)

Keynote: Deconstructing Privilege ⭐⭐⭐⭐⭐

By Patricia Aas - programmer, founder of TurtleSec consultancy. Member of #include organization hoping to improve diversity and inclusion in the C++ community.

This ending keynote did not have any code references but was by a C++ developer to a C++ audience and it was very powerful. 
Aas talked about how 'Privilege' is not having experienced a specific hardship. As part of a diverse community, she really opened my eyes to some of the hardships that I had never thought about. 
https://www.youtube.com/watch?v=ZYvyO27uMCU

Day 2 blog coming soon...  Slides for the talks are available here and video recordings on the official Youtube channel.