Tuesday 23 April 2024

ACCU 2024 trip report

 I went to the ACCU conference this year. I was speaking on the last day, which I managed to put out of my mind for a while and went to several other sessions.

We started with a keynote from Herb Sutter about safety in C++. He's spoken and blogged about this before, but this talk pulled together several strands and, at least to me, emphasised ways we can check for potential problems. 

For the next talk, we split into tracks so I had to make a choice. I went to listen to Nina Ranns talking about Embracing CTAD. As you probably know, we can say

std::vector items {1, 2, 3};

without having to spell out the <int> part, due to compile time argument deduction (CTAD). Nina used something similar as a starting point, then delved into lots of more general cases, writing your own deduction guides and why some things are not supported. For example, it's hard to decide what would we mean for say a pair of two types when we specify only one of them. I came away with lots to think about. Often a simple start can progress on to so many interesting things to think about. 

I went to Steve Love's C# Performance: Demons, Wizards, Warriors, Auditors session next. He had some C++ towards the end, having started with lots of C# examples. He simply put small structs into a hash set in various ways. Again, a nice simple idea to start with from which we learnt lots. He showed the C# could be lots quicker than the C++ when populating the container. I want to find a moment to find out what's going on there. All very interesting.

Inbal Levi's KEYNOTE: Welcome to the meta::[[verse]]! was an introduction to reflection, which is coming up in C++26. It was a nicely done talk, giving an introduction if you've not seen this before. Watch this space.

I then went to Jutta Eckstein's Creating Better Systems by Focusing on Sustainability session. She started by giving background information and defining terms, after a short discussion with the attendees about what they thought about when sustainability was mentioned. We then filled in a survey and discussed the results. It's very easy to think big, and worry about how to change everything all at once, but this helped to focus on some small things we can do. Using less RAM or powering off machines that aren't being used will make a difference. Again, I came away with lots to think about. Jutta's website has a link to her survey. I believe we did a shorter version at ACCU. It's a great starting place for a discussion. 

In the afternoon, I went to Rog Orr's Linkers and the One Definition Rule. This is an old idea, but he still managed to find various new ways to break code. He also gave a great explanation of what the linker is up to and why and how. I will have to re-watch this when the talk is on YouTube, and maybe he'll write this up for Overload one day.

On Friday Laura Savino's KEYNOTE: Coping with Other People’s Code covered various ways of coping with difficulties. No one specific thing comes back to mind now, because my mind wandered around lots of similar situations and code bases I have been in. I suggest listening to this when it's on YouTube to give yourself space to reflect.

I went to Kevlin Henney's The Data Abstraction Talk session next. Trying to pull on what abstraction really means is always good. We had various implementations of a stack, again a nice simple place to start which leads to many thoughts and questions. 

After lunch, I went to listen to Mathieu Ropert's Data Oriented Design and Entity Component System Explained. I have listened to people talking about structure of arrays versus arrays of structures several times before, and the approach taken can have a performance impact. His angle was how "Entity component system " (ECS) - a way to manage struct of arrays for fields in a Thing, is often suggested as a way to solve almost anything. The introduction was very useful and has clarified several terms for me, but whether ECS will really solve all your problems remains to be seen.

On the last day, I partly went to see Matthew Jones talk about How to delete code, because I was in that room after the coffee break, so I wanted to remind myself where it was. However, I liked the idea of the talk. Matthew chatted to me before hand saying he hasn't spoken for years and was surprised his talk was accepted. I am so pleased I went. It was really a talk about refactoring. Though many specifics referred to C++, the contents were applicable to any code base. How do you decide which code to deal with? When do you refactor? Who should do this? Many other questions... and some answers too. 

I then gave my talk: An introduction to swarm intelligence algos (Swarm your way out of a paper bag). My slides got stuck in presenter mode, and a friend said to me afterwards, "You're talks are always chaotic, but not in a bad way", or words to that effect. I had embedded some mp4s in my PowerPoint, so I could just run those rather than switch to a demo, but they refused to run in presenter mode. Oh well. That meant I ran various demos afterwards, but this allowed the audience to choose what they wanted to see. I covered the general gist of Swarm algorithms, which can be used to find the "best" solution to a problem, provided you can encode the problem and define best, or at least better. I specifically walked through the "Cat swarm algorithm." I like trying out various machine learning algorithms and implementing them from scratch. It provides a way to practice coding and always leaves me with various things to think about, usually how to I make my code neater so it fits on a slide.

I then went to Andreas' Weis' C++ Modules - Getting Started Today talk. I've listened to various talks before, mostly by Dani Engert. I have not got round to trying modules yet. Andreas started simply, but we still hit some gnarly parts soon enough. For now, I think I will watch from the slide lines. Modules will be really useful, I just don't have the bandwidth to play with them yet.

Finally, the closing keynote was KEYNOTE: Learning is teaching is sharing by Björn Fahller. This was a positive ending to a great conference. He talked about flying, and fighter jets. In fact, we'd already had mention of nuclear submarines at a couple fo other talks. Weird, emergent themes. Björn's emphasis was more on the "API" to a very basic fighter plane, but in the context of helping others, and sharing knowledge. He also encouraged us to be humble and keep learning and sharing.

Sometimes ACCU gets described as a C++ conference, but it's more than that. There are usually talks about a couple or more other languages, as well as refactoring, testing and more general coding related topics. It's a great place for me to catch up with friends as well as meet new people. 

I plan to revisit this and add some photos at some point and add the links to the talks as they turn up on YouTube. If you did a conference write up, feel free to add a link in the comments. 

Friday 22 March 2024

Randomness

I gave a talk called "What is a Random number and why should I care?" a few times last year. It evolved each time, but I was fundamentally trying to decide whether I could define "randomness" properly. 

My first attempt was at ACCU. Unfortunately, in a surprising turn of events, my laptop died, but I did manage to give the talk using a pdf version on someone else's laptop. I got other chances at other conferences, for example MeetingCpp, so you can watch if you are interested. 

The second part of my title - why should I care - is easier to answer than the first. Without randomness, however we define this, outcomes are predictable, which is boring. For example, letting some blobs march up the screen at the same pace gives a very predictable outcome:


If each blob behaves randomly, more interesting things will happen, so we can watch them race.

Now, we can answer the first part of the question. What is a random number? There is no such thing as a random number, but a sequence of numbers might be random. If you can predict what comes next the numbers are not random, but if you can't that proves nothing. For example, what digit comes next in this sequence?
15926535897932384

It's a 6, because these are the digits of π, starting at the fourth digit. If you spotted that well done.

How do you generate random numbers on a computer? Most of the time, we use pseudo-random numbers. These are not random at all. They often use a congruence relation, generating a new number based on a previous number. The simplest is a multiplicative linear congruential generator
xi+1=AximodM


where A is a constant and M is a prime number. The first value of x is a seed, and using the same seed generates the same sequence of numbers. There are various other generators, some more complicated than others.

I still can't define random but using pseudo-random numbers is good enough for some machine learning applications or games. For example see my Swarm blog post, and I'll be talking about swarm algos at ACCU this year.

My first book, Genetic Algorithms and Machine Learning for Programmers, shows how to build some simulations and models using stochastic or (psuedo) random functions, and my latest book, Learn C++ by Example, aimed at helping people get back up to speed with C++, also has several simple games, like a higher/lower card game. To make the games fun, you get lots of practice using C++'s random numbers. The C++ book is currently on pre-order at Amazon, or you can buy it directly from the publishers.