Jonathan Boccara's blog

7 More Ways to Get Better at C++ This Summer (2018 Edition)

Published June 29, 2018 - 2 Comments

C++ summer

Summer is coming!

About the same time last year, I released my 7 ways to get better at C++ during summer, and it nudged a lot of developers into taking on summer projects, to hone their skills for the coming  year.

That’s cool and the good news is, during this year, I’ve built up another set of 7 ideas of programming stuff to do this summer, which you’ll find here!

Indeed, summer offers two things that make great conditions for a programming project:

  • time. It can be actual time off from the office, or just less activity at work because a lot of people are away.
  • a limited period of time. Indeed, the crazy voyage of the Earth around the Sun brings a non-negotiable deadline to summer.

These two aspects make summer a fantastic opportunity to take on a project, that will help you improve your skills for the coming year, let you have a good time, and hopefully both.

In the large sense of the term “project”, your project can be to rest. Lying on the beach, walking in nature, sleeping in and watching series. If that’s what will boost you for next year, that’s all fine.

But if you’d like to use your summer time to level up your skills with a programming-related project, here are 7 ideas that will help you do that.

Project #1: Removing duplicates in C++ base classes

Of all the 7 projects, this is the most technical one.

We have seen a few days ago how the variadic CRTP allows to add a set of extra features to a given class. The extra features looks like this:

template<typename Derived>
class ExtraFeature1
{
public:
    void extraMethod1()
    {
        auto& derived = static_cast<Derived&>(*this);
        // uses derived.basicMethod()
    }
};

template<typename Derived>
class ExtraFeature2
{
public:
    void extraMethod2()
    {
        auto& derived = static_cast<Derived&>(*this);
        // uses derived.basicMethod()
    }
};

And those features can be plugged into a customizable class X the following way:

template<template<typename> typename... Skills>
class X : public Skills<X<Skills...>>...
{
public:
    void basicMethod();
};

With, at call site:

using X12 = X<ExtraFeature1, ExtraFeature2>;
X12 x;
x.extraMethod1();
x.extraMethod2();

About this topic, Fluent C++ reader Christopher Goebel wrote in a email recently, asking an interesting question: if you group the features into packs, and some packs happen to contain the same skills, the code stops from compiling. How can you then deal with features packs?

A feature pack consists in an intermediary class that inherits from several skills relating together:

template<typename Derived>
struct ExtraFeaturesA : ExtraFeature1<Derived>, ExtraFeature2<Derived> {};

template<typename Derived>
struct ExtraFeaturesB : ExtraFeature3<Derived> {};

It can be used with the same syntax as unitary features:

using XAB = X<ExtraFeaturesA, ExtraFeaturesB>;

XAB x;
x.extraMethod1();
x.extraMethod2();
x.extraMethod3();

The problem comes when several packs have some features in common:

template<typename Derived>
struct ExtraFeaturesA : ExtraFeature1<Derived>, ExtraFeature2<Derived> {};

template<typename Derived>
struct ExtraFeaturesB : ExtraFeature2<Derived>, ExtraFeature3<Derived> {};

Compiling the code that calls extraMethod2 leads to the following error message:

main.cpp: In function 'int main()':
main.cpp:59:7: error: request for member 'extraMethod2' is ambiguous
     x.extraMethod2();
       ^~~~~~~~~~~~
main.cpp:20:10: note: candidates are: 'void ExtraFeature2<Derived>::extraMethod2() [with Derived = X<ExtraFeaturesA, ExtraFeaturesB>]'
     void extraMethod2()
          ^~~~~~~~~~~~
main.cpp:20:10: note:                 'void ExtraFeature2<Derived>::extraMethod2() [with Derived = X<ExtraFeaturesA, ExtraFeaturesB>]'

Indeed, X inherits from ExtraFeature2 via two ways: by ExtraFeaturesA and by ExtraFeaturesB:

variadic crtp

The project consists in making the code compile. Here is the complete code that doesn’t compile to work on.

One idea would be to remove the duplicates amongst the base classes, because only one version of each would be enough. But there is no native way in C++ to perform an unique on classes. This is where template metaprogramming could help, with for example Boost Hana. If you explore this possibility, getting familiar with Boost Hana is an interesting part of the project.

Or maybe there are other ways to solve the problem?

In any case, if you’re interested in this project and have questions about the requirements, just let me know. Also, I’ll be happy to have a look at your solutions.

Project #2: Title Case

Look at the headline of this post “7 More Ways to Get Better at C++ This Summer (2018 Edition)”. Most words start with a capital letter, but not all (for example, “at” and “to” don’t). This is called Title Case.

Project #2 is about making a library with the clearest interface possible that takes in a string, and outputs a string containing the same contents but in Title Case.

The point is to get more experience with ranges and the STL, design an clear API, and implement a library with expressive code. All of which are precious tools for everyday work.

The requirements of this project can be phased into several steps:

Step 1: Basic Title Case

For each word in a sentence, make all of its letters lower case, except the first one that would be in upper case.

There is a list of “exceptions” words that need to be entirely in lower case, including their first letter. This lists includes “at” and “to”, along with another dozen words. For the sake of this project let’s say that the list of exceptions is: a, an, the, at, by, for, in, of, on, to, and, as and or.

Note that in all cases, the first word of the string must start with a capital letter.

Step 2: Title Case with customizations

Make the list of exceptions customizable: the library user can add new exceptions, replace the list with their own, or add words that should not be changed by the library.

An additional requirement is that words in all caps should be left as is (“STL” must remain “STL”, and not be changed into “Stl”), but the library user should be able to opt-out of this feature.

Step 3: Other capitalizations

Title Case is one of the various forms of capitalisation there is. Other examples include UPPER CASE, lower case, snake_case, Start case, and so on.

Implement at least two other forms of capitalizations in the library, by reusing as much code as possible from the previous steps. The point of this step is to make a smooth introduction of new features into existing code via a form of polymorphism (runtime, static, other… you choose).

There is no specific requirement on the form of the API, because that’s part of the project: design an interface that’s easy to understand and use. And since you’re starting from scratch, it should be easy to write unit tests around your library, and even develop it with TDD if you feel in the mood.

Of course, I’ll be happy to have a look at your API when you’ve designed it! Feel free to send me an email.

Project #3: Make a program that will make you more productive

Aren’t there tasks that you do and that would be better left off to a robot? Or things that you’d like to do, but that would need some automation to become realistic?

Summer might be just the right moment to work on this and make your life simpler for the rest of the year, and get some programming experience along the way.

For example, Fluent C++ is building up a lot of contents, and some of it gets buried in the archives of the website, below piles of ever newer posts. I’d like to know which articles I should bring back up and promote so that new readers can benefit from them.

For this, my summer project could be to make a program that scans through the contents of the website, identify what posts would deserve more attention based on some criteria, and tell me which articles I should promote. All this at the press of a button (or whatever interface) and on a regular basis.

Your summer application doesn’t have to be ambitious, as it takes some time to put a program together anyway. But if you have a clear objective, this is the moment to automate something for next year.

What’s more, it will make you build a piece of software end-to-end, and offer you a view that you sometimes don’t get to see when you’re working on a larger project at work. And this sort of big picture is beneficial for the day to day activities of a software developer.

Project #4: Read Clean Architecture

Imagine yourself, lying on a beach bed, listening to the waves crushing onto the sand and the rocks, smelling the scent of pines carried by a light breeze from the forest behind you, and watching the occasional bird fly high in the sky under the glazing sun.

It’s almost the perfect picture. Except it misses just one thing. What is it? A programming books in your hands, of course!

Reading a book is a classical summer project. There are plenty of books that could improve your programming skills, and for this summer I recommend this recent one: Clean Architecture, by Robert Martin.

I was skeptical at first, because the table of contents seemed like announcing pretty basic topics at a first glance. But it turns out to be a very interesting read, particularly the part on Architecture (part 5), with a point of view on levels of abstractions and dependencies that is well worth its reading time.

Moreover, Robert Martin has a very clear writing style, which makes it easy to read fast, or to clarify notions that could be confused before taking on the book.

Project #5: Write everything you know about X

The last three projects are less about how to write code itself, and more about getting a deeper knowledge of your favourite programming topics.

Pick a topic that you know about, preferably not too large. For example, don’t pick “C++” or “programming” as they’re too big, but rather “polymorphism” or “default parameters in C++”. For instance, I’m currently doing this with the topic of “how to stay motivated with legacy code”.

And once you’ve selected your topic, write everything you know about it.

You have no limit in size (which is why you don’t want too vast a topic), and the project consists in spilling on paper (or more likely, computer) every last thing you know about that topic. And before you begin, I suggest you start with a list of sub-topics that compose your topic X. And even when you start on sub-topic X1, it helps to make a list of its different aspects as well before writing about it.

When you undertake such a project, you will see several surprising things happen.

The first is that you realize that you know way more that you thought on that topic. The second one is that when you write about it, you realize that some things aren’t so clear as they seemed, and it forces you to do some research or experiment, making you learn new things.

The third one is that it makes you make connections. Indeed, you may have several opinions, or bits of knowledge on a given topic, without seeing that they are in fact related until you get into that big-picture experience of writing everything.

As a result, your knowledge and understanding of topic X comes out wider and more organized. What’s more, you end up with a deliverable that can be a long article or – why not – the draft for a book or enough to start a blog.

Project #6: Prepare your Daily C++

My favourite way to spread technical knowledge in a company is with the Dailies, for example with the Daily C++.

The dailies is a format of training designed for people motivated to learn a lot of things, but that don’t have a lot of time at work. They are talks of 10 minutes given every day right in the office spaces where people work.

10 minutes fits in the day of most people: you just turn your chair, listen to the Daily, and carry on with your day. But over time, those little shots of 10 minutes of focused time build up to a fair amount of knowledge.

The person who presents the Dailies has a set of 10 to 20 talks that they present to a team for a month. Then they go to another team the following month, and present the same set of talks to that team. And so on the next month. And when they have been to all the teams interested in that topic, they constitute a new set of 10 to 20 talks and start again with in the first team’s office.

How do you come up with 10 to 20 talks? There are two options: creating your own contents, or diffusing existing contents. You can find existing contents on Fluent C++, with the articles marked with a Dailies C++ logo on the posts page. Or you can use the contents of other blogs if their authors agree to it.

Creating your own contents takes more time that selecting existing ones, but either way you can use this summer to prepare for your first Daily session of next year.

Project #7: Speak at a conference

A lot of people attend programming conferences, and even more watch their videos on the Internet.

But have you ever considered speaking at a conference?

If you haven’t, know that you don’t have to be Bjarne Stroustrup or Herb Sutter or Madonna to be accepted on stage. Conference organizers welcome submissions and generally appreciate a wide variety of presenters.

But how do you find a topic to talk about? And how do you turn it into an 45 minutes (or more) presentation?

One possible answer to both those questions is: gradually.

Let’s start with the topic to talk about. What did you try to learn about recently? What was your last coffee-machine discussion about? Pick something that motivates you and that you’ve dug in already, even if only a little and even if it doesn’t have any trendy buzzword in it.

Then make a small presentation out of it. A 10 minutes presentation that you will show to your close colleagues. If there is a Daily session near you, ask to be a guest speaker for one day. The point is to get it out in front of some people.

Another way to get it out there is write an blog post about it. If it’s about writing clean code, consider guest posting on Fluent C++. Or present it at your local meetup or user group (they’re looking for people to present).

The point is to get your stuff in front of people, and get feedback. The more feedback you get, the more you can flesh out your presentation until you have a 45-minutes long talk you can submit to a conference. And summer is a good time for producing the initial contents, and starting to iterate on it.

Then fire. If it’s about C++, send it to CppCon, Meeting C++, ACCU, C++ Russia, Pacific++ and all the others.

Finish a project

Make sure to make this summer count! Don’t try to to everything at the same time, or to change project during the course of summer. Focus your efforts on one project, or maximum two, and get to the end of it before the ineluctable rotation of Earth clicks into September.

Note that Fluent C++ stays open and active during the summer, so stay tuned!

So what will you do during the next two months? Summer is on your door, decide on one project NOW. And tell us your programming plans in the comments section!

Don't want to miss out ? Follow:   twitterlinkedinrss
Share this post!Facebooktwitterlinkedin

Comments are closed