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.

Monday, May 1, 2017

Death by Jenkins - Really difficult bits to find out about Declarative Pipeline DSL (Part 2)

As I said in my last post, I'm not a build engineer and I don't know groovy. I am currently working in a team that is creating a cross-platform system that integrates iOS and Android SDKs to be used as a shared library in C++. But somehow I've become the Jenkins Lady of the team...

So first thing I want to say is that I think there is a serious problem of not error-ing with Pipeline.

Say you have the following piece of code:

You have separate methods to load separate groovy files and run them with different parameters.
This seems fairly straightforward and valid to me.

But not to Jenkins Pipeline!

This will result in a successful Pipeline build but your external script, in this case neither build.groovy nor test.groovy will load. And it won't give you any output either.


So then I spend hours Googling and trying things out.
And well, it turns out, you cannot have the same method name in your external script.
Because the Jenkinsfile had two method calls to "run()", it could not figure out which it needed to call and failed silently.

So if I changed my code to the following, the external scripts are loaded as expected.


That was the first problem.

A few days later, I ran into the same exact problem. AGAIN! But now my scripts all had differently named methods so I had to go Googling and trying things all over again.

Now, my Jenkinsfile had some other methods that needed to go through a map and add the key to a separate array if the value was true. Like this:

While making this change, I first got an error saying:
"Calling public static java.util.Map org.codehaus.groovy.runtime.DefaultGroovyMethods.each(java.util.Map,groovy.lang.Closure) on a CPS-transformed closure is not yet supported (JENKINS-26481); encapsulate in a @NonCPS method, or use Java-style loops"

After confirming on various sites (like here) that you need to do this if you want to use .each in Pipeline, I put @NonCPS on prepareTests() and everything was all green (y)

But then of course I realised it wasn't loading the script.

Turns out you can't load scripts in a method that has or calls other methods with @NonCPS.

I have since found this document Pipeline Best Practices and it does say:
"Beware for (Foo f: foos) loops and Groovy closure-style operators like .each and the like. They will not work right in normal Scripted Pipeline contexts where Pipeline steps are involved directly."

So I wish I had known that earlier but the solution here is to use a for loop and give up on nicer .each syntax.
(also another link I have since found has other people complaining about Pipeline! yay friends! :P )

Well of course my misery doesn't end there and I could go on about how much Pipeline's been more of a headache than help but now our build process looks pretty so yay! x)

I feel like I've been rather grumpy writing these blogs and complaining about Pipeline but obviously there are benefits and I've been told by my team that it's been useful for them so all is good :) 

Thursday, April 27, 2017

Death by Jenkins - Really difficult bits to find out about Declarative Pipeline DSL (Part 1)

I haven't written in a long while, but I've been working with Jenkins for the past 4 weeks (yes, I've been working for over 2 years now! no, I am not a build engineer), and I found it so excruciatingly painful to find answers about Jenkins Pipeline syntax on the Internet, that I thought I needed to update my blog and save others from a similar fate x)

Some context:

I've been working on converting our myriad of Jenkins jobs into the new Jenkins Pipeline job.
Jenkins Pipeline, if you don't already know what it is, is a new way of setting up CI. Every time you push code, it goes through different stages (Build, Unit Test, Integration Test, etc) so that by the end of the pipeline, if it all passes, you should be super confident about the code you committed, that it can be released automatically.


Commit => Build => Test => Deploy



It had been on my mind for a while that our Jenkins jobs were getting out of hand and we needed to migrate to using the DSL. Once you have two sets of 10 jobs, it starts to become unmanageable...

But wasn't sure if I should use a Pipeline or standard DSL linked to a job. In the end, I decided to go for the Pipeline because Jenkinsfile scanning using github enterprise and workspace management came with existing Pipeline plugins and it would tidy up all the jobs we had into one job per branch. I still don't know if this was the correct decision because I find that having only one job makes it more difficult to look through workspaces because the pipeline UI is a bit clunky.
Anyway, I'm rambling, let's get to the code.

The most annoying thing I could not find on the web was to re-assign/reset a global variable set in the environment block.


Here is a simple boolean environment variable:


Now I want to change this value when the Step succeeds within a try-catch block:


This doesn't even error but if I do an echo isSuccess before and after, I get false both times.

So after hours of Googling, I finally found out you need to override the environment variable. 
But how? 
The documentation merely says the below, and I couldn't find any examples anywhere!

So I after a few trial and error, I finally got it. The correct syntax is:
But this didn't work either. Now I was getting a type mismatch. Because when you defined isSuccess = false in the environment, it was kindly casting it to a string "false"!

Soooooo:


Finally, it was setting the correct value and now in my next stage, I could check if(isSuccess=="true")

Maybe you can properly define a boolean variable using: def  isSuccess = true

but I didn't have the patience to try this out so let me know if you try and it works!

After all of this, turns out I didn't want a try catch and so I didn't need to set a global variable but hey at least I know something now and I've shared it here so I hope this is helpful to someone out there, so my efforts weren't for nothing! 

Part 2 coming up with my finding about:
- loaded groovy script method cannot have the same name
- @NonCPS doesn't let you load scripts - problem with using .each

Monday, February 10, 2014

First SpriteKit Game

My first game using Sprite Kit!!
It's based on a tutorial by  Ray Wenderlich on http://www.raywenderlich.com/ 
Graphics were done by me on a simple paint tool so its not great haha but the concept is to shoot vegetables at kids who are running away! 
Still working on it to add levels and different vegetables as well as a boy character. 




Sunday, February 9, 2014

Get your code on!

So thursday evening, I went to an event, "Get your code on", organised by a group called Ladies who Code. It was at Mozilla office in London and they had a very nice office, despite the fact that it was a little small, but then again, it is in central london, in a very nice location so not surprised or complaining :)
There was a presentation by a Senior Engineer at Mozilla (http://soledadpenades.com) about an online gif chat website that she and her friend had created for fun and how it had suddenly become a success within a community and grown beyond their control thanks to many contributors adding to their open source website. (https://chat.meatspac.es)

Then we ordered some pizza started working on projects and getting to know other ladies ;)
I was fortunate to meet very nice people and had a lot of fun so I would definitely go to their event again!


And now I'm working on my own project to create games. I was talking to a couple of developers this weekend and they told me that C++ wasn't necessarily the language they used for games programming and certainly not the only language I should focus on. They told me to look at JS, ObjectiveC for mobile, if not Unity and C#.
So I just found a very nice tutorial for ObjectiveC iOS SpriteKit Tutorial so I wanted to share that with you :)
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
Thanks to the guy who wrote this tutorial, Ray Wenderlich, I am now going to modify it and try to make my own version :)

Have a nice sunday!

Monday, February 3, 2014

Finished our App!

So last week was our deadline for the HTML5 game app that my group and I were creating as our coursework.
I made a demo video so check it out ;)
I fear I sound like a bit of a bore but it took me all day to script what I was going to say in the video, practice the game so I don't get it wrong AND not stutter or say 'uhh'! haha


I made the video using audio and screen recording on Quicktime Player (Mac), then I put the audio and video together using iMovie.

The game is actually pretty fun! I'll let you know when it goes on the app stores!!

Now I'm focusing on applying for jobs, and my new second term modules.

In the end, I decided to take Software Engineering, Algorithmics, Functional Programming and Business Analytics.

Functional Programming is really fun. We are using a functional programming language called Miranda and I am loving it. Although, admittedly, it is getting more and more complex as the introductory weeks have gone by. But the way functional programming works is so cool! It's so logical it feels good! haha #supernerd

Business Analytics is less interesting for me because I feel that I know a lot about it already from my bachelor's degree. But the interesting thing about this course is that they teach you how to use the popular Statistical Analysis Software developed by SAS. People from SAS have come in to teach us and we've got a coursework to actually work on industry data.

I also just made my first six website to increase my online visibility and show that I am interested in game development.
Since when am I interested in games? Well, very recently. I've never been a big gamer but I am addicted to mobile games and so I went to this talk by a Games Industry Graduate Recruiter, Aardvark Swift at my university's career service event. It got me thinking how cool it would be if I could be a part of creating mobile games like Candy Crush and Plants vs Zombies!
So I spoke to the guy who gave the talk and I've been teaching myself C++ so I can develop games and build an online portfolio so games companies can see how I am interested.
I even entered a competition last week called Search for a Star, where I had to take an exam about C++. I doubt I got through to the next round because I just started learning C++ last monday, but it was really good experience and motivated me to crash learn C++.
Here are some websites I found really helpful:
https://www.wibit.net //The guys doing the videos are hilarious. Keeps you awake (y)
http://www.cplusplustutor.com
http://msdn.microsoft.com/en-us/library/ms228358(v=vs.90).aspx //For those who learnt Java first
http://pages.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Java_vs.html#arrays //For those who learnt Java first
http://www.cplusplus.com/ //Ofcourse

Anyway, back to work! Hope you all had a nice weekend and have a nice week (y)