All posts in "Expressive code"

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 - 11 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 - 6 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, conciseness, 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 - 2 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 - 24 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 […]

1 18 19 20