All posts in "Expressive code"

The Pi Day Challenge For The Most Expressive Code In C++

Published March 2, 2017 - 10 Comments

Each year, the fourteenth of March is marked by a very special event: Pi Day! It’s called this because in American notation, the 14th of March is 3/14. And during this day, the number Pi is celebrated all over the world in various ways. One notable way to celebrate it is bringing a pie to work or to university. […]

What 70 people came up with on expressive code

Published February 6, 2017 - 7 Comments

Last week held the monthly meetup of Software Craftsmanship in my area. The organizer, Stéphane Bagnier, proposed a very original and interesting schedule for the evening. After a short series of brief and spontaneous presentations, any attendee could propose a topic he found worth spending time talking about, and then everyone got to vote. The 2 topics receiving the […]

How to choose good names in your code

Published January 30, 2017 - 7 Comments

Naming is SO important. If your code is going to be read at least one time — if only by yourself — then names will play a major part in your capacity to work with it. Variable names, function names, class names, names in an interface, all are priceless ways to let your code tell more about […]

Making code expressive with lambdas

Published January 19, 2017 - 22 Comments

Lambdas are arguably one of the most noted addition to the language in C++11. It is a useful tool, but one has to make sure to use them correctly to make code more expressive, and not more obscure. First off, let’s make clear that lambdas do not add functionalities to the language. Everything you can do […]

Super expressive code by Raising Levels of Abstraction

Published January 3, 2017 - 7 Comments

In this post I would like to propose a technique based on levels of abstraction to transform an obscure piece of code into expressive and elegant one. You’ve been quite a few to take up the Christmas Break Challenge for writing expressive code, by posting a comment on the challenge post or by chipping in on Reddit. […]

Can you write expressive code? – Christmas break challenge

Published December 19, 2016 - 1 Comment

Before you go away on holidays and feast on Christmas and New Year’s eve parties, I want to propose you a challenge about writing expressive code to keep your skills up during the holidays period. I’m going to show you the code for a simple task performed by an application. I’m even going to explain that code to you. […]

It all comes down to respecting levels of abstraction

Published December 15, 2016 - 2 Comments

As software developers, we get to learn many good practices and strive to apply them in our code. For instance we learn the importance of good naming of variables and functions, encapsulation, class cohesion, the usage of polymorphism, concision, readability, code clarity and expressiveness, and many others. What if there was only one principle to […]

Partial queries with optional<T>

Published December 1, 2016 - 5 Comments

Clearer interfaces with optional<T> showed what optional<T> was, and how to make interfaces clearer by using it as a return type. If you’re not familiar with optional, I would recommend you to read it first. Here I present a example of using optional as an argument, to leverage on its “not set” semantic. The need we’ll work […]

Clearer interfaces with optional<T>

Published November 24, 2016 - 0 Comments

The need for representing a value that is “empty”, “null”, or “not set” arises regularly in code but often leads to clumsy or brittle solutions. This need may appear with a function that needs to return a value but may not be able to compute it in all cases. In this case, several solutions are […]

Make your functions functional

Published November 22, 2016 - 11 Comments

Introduction : global variables Global variables are a Bad Thing. Everyone knows this, right ? But do you know exactly why ? I have asked this question around, and many of us can’t exactly explain why global variables should be avoided. It is not a question of scope. Indeed, global constants have the same scope as […]