An essay on paradigms, refactoring, control flow, data, code, dualism and what Roman numerals ever did for us

Looking at something from a different point of view can reveal a hidden side. With physical objects this hidden side can be literal, hence why technical drawings of three-dimensional objects are often made using a multi-view projection, such as a plan view and elevation views. With abstract concepts the hidden side is more figurative. In software architecture, for example, view models, such as 4+1 or ODP viewpoints, can be used to bring different concerns of a system into focus, such as user interaction, governance, behaviour, code structure, information model, physical distribution, infrastructure, etc.

Numeral systems also have this quality. Changing how numbers are represented doesn’t change the numbers represented, but it does change how we think about them. Thinking about integers in binary, for example, reveals different patterns (and failures) than when we think about them in decimal. Binary also chunks more easily into hexadecimal. Thinking about RGB triplets makes more sense in hex than in decimal. And so on. Changing base can reveal new possibilities. …


Assertions should be necessary, sufficient, and comprehensible

Image for post
Image for post
A previous version of this article appeared in 97 Things Every Programmer Should Know

It is important to test for the desired, essential behaviour of a unit of code, rather than for the incidental behaviour of its particular implementation. But this should not be taken or mistaken as an excuse for vague tests. Tests need to be both accurate and precise.

Something of a tried, tested, and testing classic, sorting routines offer an illustrative example — they are to computer science as fruit flies are to genetics. Implementing sorting algorithms is far from an everyday task for a programmer, commodified as they are in most language libraries, but sorting is such a familiar idea that most people believe they know what to expect from it. …


The challenge is not to write comments for what code does not say, but to write comments for what code cannot say

Image for post
Image for post
A previous version of this article appeared in 97 Things Every Programmer Should Know

As with any other form of writing, there is a skill to writing good comments in code. And, as with any other form of writing, much of the skill is in knowing what not to write.

It has been said that the difference between theory and practice is greater in practice than it is in theory. This observation certainly applies to comments. In theory, the general idea of commenting code sounds like a worthwhile one: offer the reader detail, an explanation of what’s going on. What could be more helpful than being helpful? …


The number of days in a year is 365 or 366… or more or less

In jumping from calendars that are a distance apart and moving at different speeds, you need to change gears to get the two in sync. This can upset the regularity of our expectations:

I said that calendar years have one of two day counts: 365 and 366 days. In the Gregorian and Julian calendars this is true… but when jumping from one system to another, truth is more fluid.

In the default case you take the baseline of 365 days and add an optional leap year. In exceptional cases, such as changing from the Gregorian to the Julian calendar, you lose a few days to mesh gears. For example, instead of 366 days, 1752 in the UK had 355. The same happened in Denmark and Norway in 1700. 1753 in Sweden and Finland had 354 days instead of 365. …


When is the same date not the same day?

It’s 23rd April, World Book Day, as I write this.

Miguel de Cervantes and William Shakespeare both died on 23rd April 1616. They did not, however, did not die on the same day. There is no paradox, but there is an assumption: these dates of death do not come from the same calendar.

Image for post
Image for post

In 1616 Spain was following the Gregorian calendar, introduced by and named for Pope Gregory XIII in October 1582, and England was still following the Julian calendar, based on Julius Caesar’s calendar reforms in 46 BCE. …


The one where my software and creative writing worlds collide

Behind every story lies a story. This one begins one Saturday morning in Malmö. To be precise, Saturday 7th March at the single-day, single-track Beauty in Code conference. I’m speaking in the afternoon. Just before nine o’clock, however, I’m still upstairs in my hotel room, taking it easy.

Just then I receive a WhatsApp message: “Are you coming down?” It’s from Alistair Cockburn, who’s giving both the opening talk of the day, Getting back to the Heart of Agile, and the closing one.

“Yes, but not for a few minutes. Got caught in an email.”

“I’m going to ask you to write and read at the end a flash fiction:). How much time do you need?” …


Foreword to The Java Module System by Nicolai Parlog

Image for post
Image for post

The motivation and desire for modularity is not new. In the proceedings of the 1968 NATO Software Engineering conference, the landmark conference that helped popularize the term software engineering and a vision of software components, E E David outlines an approach for the development of large systems:

Define a subset of the system which is small enough to be manageable, then build on that subsystem. This strategy requires that the system be designed in modules which can be realized, tested, and modified independently, apart from conventions for intermodule communication.

From the same conference, H R Gillette describes how modularity supports a system’s…


What makes a new year a new year?

Happy New Year! At the time of writing, the Gregorian New Year lies in the rear-view mirror, and we have arrived at the Lunar New Year.

Around the world, people’s lived are governed and influenced by many calendars. While they differ in their structures, motivations and durations, they are all cyclic. In spite of this multiplicity, one system is used officially by all nations. …


How we count years, decades and centuries

I’m writing this on 1st January 2020 (2020–01–01). It’s a new year, but is it a new decade? Some people object to that claim, insisting that the previous decade does not end until 2020–12–31 and, therefore, the new decade does not begin until 2021. Are they right?

This blog post was inspired by one such discussion (with Marco Heimeshoff and J B Rainsberger), because — in addition to being fun! — it helped reveal some of the assumptions that surround calendars. I recently wrote that

Date–time handling is harder than people expect — even when they’re expecting it. It is a truth universally acknowledged that a single programmer in possession of the belief they understand dates and times, must be in want of a code review. …


Checked exceptions were an experiment — it’s time to move on

Image for post
Image for post

If you ever want to walk to Hell, the journey will be easy on your feet. The whole road is very well paved, with good intentions as far as the eye can see. At least one of those paving stones is dedicated to Java’s checked exception model.

A checked exception is one that, if not handled within a method, must appear in the method’s throws clause. Any class descended from Throwable can be listed after throws, but unhandled checked exceptions (not descended from either RuntimeException or Error) must appear. …

About

Kevlin Henney

consultant · father · husband · itinerant · programmer · speaker · trainer · writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store