Jez Higgins

Freelance software grandad
software created
extended or repaired


Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed

Wednesday 08 November 2023 Yr glygfa o Hescwm Uchaf, rhif 4 : You live where?

Something over six months ago, Virgin Mobile started the process of transferring me over to O2 as part of their Virgin-O2 merger/takeover/whatever-it-is. For most of the time between then and now, I was in some kind of liminal space, coexisting in both Virgin and O2 customer account systems without being entirely in either.

It’s been a bit of trek. Sometime in May, for example, I got a text from Virgin saying they were sorry I was leaving, which was a little alarming as, you know, I wasn’t.

After that, every month there was text saying I would be fully switched over to O2, that I didn’t need to do anything, it would all happen by magic. A few days later, there would be another text saying actually no they didn’t, but they’d have another go next month. This culminated in a letter in post saying they’d have one more go but if that didn’t work they’d have to close my account. Again, a little alarming, and not a little irritating especially as it was worded to imply this was somehow my fault.

Remarkably though, the letter actually did the trick, and I was finally fully dumped over into O2-land. Perhaps most surprisingly of all, my phone not only continued to work the service actually got a bit better [1].

Between the start of this tedious little saga and now, we moved house. Virgin gave O2 our address then and, because of the account interregnum, I wasn’t able to correct it until now.

It takes a little while to find the right bit of the O2 website, but once you’re there it’s a pretty normal house name or number + post code affair.

change address form

Perfect, right?

tada its wrong

Erm, no.

Our address back when was
34 Forest Road,
Moseley,
Birmingham,
West Midlands,
B13 9DH

Our address now is
Hescwm Uchaf
Dinas Cross,
Newport,
Dyfed,
SA42 0XL

Why do O2 think differently? No matter how many times I go through their change of address form, I just can’t shift the rogue FOREST ROAD.

How?

There’s a lot here that confuses me.

O2 have not done the simple and obvious thing - delete the old address, store the new one - to change the address in their database. I don’t think they have a versioning scheme with effective dates or anything sophisticated like that. Instead, we have some peculiar piece by piece update, giving us this weird merged outcome.

Let’s annotate those addresses a little:[2]

Old

New

Result

Hescwm Uchaf

House name

Hescwm Uchaf

34

House number

Forest Road

Street name

Forest Road

Moseley

Dinas Cross

Area

Dinas Cross

Birmingham

Newport

Post town

Newport

West Midlands

Dyfed [3]

County

Dyfed

B13 9DH

SA42 0XL

Post code

SA42 0XL

Some houses have names, some have numbers, some have both. Whoever wrote this wacky address update code knew to account for those various permutations. We need to know the difference between a name and number for example, if only to be able to format the address properly.

The new address has no house number, so the existing one was deleted. The new house name was written in. All looks good. Well done them.

On the other hand, they’ve completely fumbled the fact that the new address has no street name Well, maybe not completely fumbled. The address did change to include all the new bits. It didn’t complain or just plain break. That’s something.

But the choice, and this is a choice people actively made, of if there’s no street name then leave the street name unchanged I find very curious. It’s so obviously wrong. We’re changing the address - everything’s in play, we’ve paid attention the name/number thing - and yet we’re chosing to not change part of it. I wonder if the same applies if a new address lacks an area name, for instance[4].

Somehow though, someone, somewhere, wrote this behaviour into the code. Nobody else in the organisation noticed it, or if they did it wasn’t challenged, and it made it out into public view. It must affect hundreds of their customers, but there it is. Very obvious, very wrong, and yet probably very easy to correct[5].

The Spaces In Between

I am now a fully enrolled O2 customer. I can log into the website, see my bills, change my plan, all that good stuff. But for all that, I’m still in that liminal space, hanging between Birmingham and Pembrokeshire.


1. I knew it had worked because I got up in the morning to find my phone now offered WiFi calling. Our hefty stone walls are pretty radio-opaque so this is great! I mean I’m still not going to answer it, but my phone now rings so I actively ignore calls.
2. There’s more, loads more, to UK addresses than just these fields (number suffixes, dependent streets, double dependent localities) but they’re not relevant here, and lets not worry about the fact that my new address has both English and Welsh language versions…​
3. Not wrong, but mostly people use Pembrokeshire
4. Almost any part of a postal address can be missing. My bank’s postal address, for instance, has only company name, post town, post code. At this point, I think I’m obliged to link to Falsehoods programmers believe about addresses
5. And I don’t use a word like easy lightly

Monday 02 October 2023 Yr olygfa o Hescwm Uchaf, rhif 3 : Typesetting With Brian W Kernighan

Brian Kernighan, along with fellow veterans Al Aho and Peter Weinberger, has new book out and I am excited. The book, The AWK Programming Language 2nd Edition, extensively updates the 1988 original, which itself describes a language developed in 1977. In many ways awk was one of first "scripting languages" and has been successful both in its own right and as an influence on subsequent languages. It’s continued to develop over that time, if in fits and starts, and Kernighan’s been a big part of that. The fact the book warrants a second edition after such a long time is a testament to its continued success.

As he has done for nearly fifty years, Brian Kernighan did his own typesetting on this book. Herein, an almost complete history of Kernighan’s typesetting.

This book was set in Times Roman and News Gothic Condensed by the authors, using a Graphic Systems phototypesetter driven by a PDP 11/45 running under the UNIX operating system.

— Kernighan and Plauger
The Elements of Programming Style, 1974

This book was set in Times Roman and Helvetica Regular by the authors, using a Graphic Systems phototypesetter driven by a PDP-11/45 running under the UNIX operating system.

— Kernighan and Plauger
Software Tools, 1976

The book was set in Times Roman and Courier 12 by the authors, using a Graphic Systems phototypesetter driven by a PDP-11/70 running under the UNIX operating system.

— Ritchie and Kernighan
The C Programming Language, 1978

This book was set in Times Roman and Courier 12 by the authors, using a Graphic Systems phototypesetter driven by a PDP-11/70 running under the UNIX operating system.

— Kernighan and Plauger
The Elements of Programming Style 2nd Ed., 1978

This book was set in Times Roman and Courier by the authors, using a Mergenthaler Linotron 202 phototypesetter driven by a PDP-11/70 running under the UNIX operating system.

— Kernighan and Plauger
Software Tools in Pascal, 1981

This book was typeset in Times Roman and Courier by the authors, using a Mergenthaler Linotron 202 phototypesetter driven by a VAX-11/750 running the 8th Edition of the UNIX operating system.

— Kernighan and Pike
The Unix Programming Environment, 1984

This book was typeset in Times Roman and Courier by the authors, using an Autologic APS-5 phototypesetter and a DEC VAX 8550 running the 9th Edition of the UNIX operating system.

— Aho, Kernighan, Weinberger
The AWK Programming Language, 1988

The book was typeset (pic|tbl|eqn|troff -ms) in Times Roman and Courier by the authors, using an Autologic APS-5 phototypesetter and a DEC VAX 8550 running the 9th Edition of the UNIX operating system.

— Kernighan and Richie
The C Programming Language 2nd Ed., 1988

This book was typeset (grap|pic|tbl|eqn|troff -mpm) in Times New Roman and Lucida Sans Typewriter by the authors.

— Kernighan and Pike
The Practice of Programming, 1999

This book was typeset (grap|pic|tbl|eqn|troff -mpm) in Times and Courier by the authors.

— Fourier, Gay and Kernighan
AMPL: A Modeling Language for Mathematical Programming 2nd Ed., 2003

Typeset in Times, Courier and Helvetica using groff, ghostscript, and other open source Unix tools.

— Kernighan
D is for Digital: what a well-informed person should know about computers and communications, 2011

Typeset by the authors in Minion Pro, Lato, and Consolas, using Go, groff, ghostscript, and a host of other open-source Unix tools. Figures were created in Google Drawings.

— Donovan and Kernighan
The Go Programming Language, 2015

This book has been composed in Times, Courier and Helvetica using groff, ghostscript, and other open source Unix tools.

— Kernighan
Understanding the Digital World: What You Need to Know about Computers, the Internet, Privacy, and Security, 2017

Camera-ready copy for this book was produced by the author in Times Roman and Helvetica, using groff, ghostscript, and other open source Unix tools.

— Kernighan
Millions, Billions, Zillions: Defending Yourself in a World of Too Many Numbers, 2018

Camera-ready copy for this book was produced by the author in Times Roman and Helvetica, using groff, ghostscript, and other open source Unix tools.

— Kernighan
UNIX: A History and a Memoir, 2020

This book has been composed in Times, Courier and Helvetica using groff, ghostscript, and other open source Unix tools.

— Kernighan
Understanding the Digital World: What You Need to Know about Computers, the Internet, Privacy, and Security 2nd Ed., 2021

This book was formatted by the authors in Times Roman, Courier and Helvetica, using Groff, Ghostscript and other open source Unix tools.

— Aho, Kernighan, Weinberger
The AWK Programming Language 2nd Ed., 2024

Perplexing Footnote

Ossanna and Kernighan’s Troff User’s Manual does not say how it was typeset.


Thanks to Ben Deane for details of The Elements of Programming Style, and to Chris Oldwood for details of The Elements of Programming Style 2nd Edition.

Friday 15 September 2023 Yr olygfa o Hescwm Uchaf, rhif 2 : STinC++ - The current line in ed/ex/vi/vim

STinC++ rewrites the programs in Software Tools in Pascal using C++

Back on my slow stroll through rewriting Software Tools in Pascal in C++. This is a book I’ve read cover to cover I don’t know how many times in the past thirty years, but I find new facets in each time, and particularly as I’m writing code along with it.

We’re all (and by all I mean all Vim-speakers) familiar with the providing line numbers to a command - 1,$s/x/y/, .,.+10d - that kind of thing. Strictly speaking those are line expressions, rather than line numbers, but that starts to feel like splitting hairs.

But did you know, because I sure as hell didn’t, know you can provide an arbitrary number of line expressions?

When I read that Kernighan and Plauger’s edit could take any number of expressions, I thought it was just an implementation detail and didn’t really think anything about it.

I wrote my command parser to eat as many expressions as you give it, then just hand out the last two. Because that makes sense right? Treating 1,2,4,8,16d as 8,16d just seems sensible.

And then the other evening I read

A line number expression can be arbitrarily complex, so long as it lies between 0 and $, inclusive. And there can be any number of expressions, so long as the last one or two are legal for the particular command. Thus
\function\;\\
finds the second previous function declaration and
/begin/;//;//;//p
prints from the third succeeding line containing begin to the fourth, inclusive.

Whoa! What now?

For context, \<pattern>\ searches backwards, /<pattern>/ searches forward. \\ and // search backwards or forwards using the most recent pattern again. function and begin are Pascal keywords.

The key here is the difference between using , and ; as the separator between the line expressions.

A , is just a normal separator, but using ; updates the current line number to the value of the expression. That’s why the examples above do what they do. Without the ; the searches would just find the same line each time. With the power of ;, you can do all kinds of crazy stuff. I can’t think why you would, I mean I’ve lasted this long without knowing this stuff, but I’m already expecting to find out this is Turing complete[1].

That’s it?

That’s it!

That’s the key. Multiple line expressions aren’t a quirk of Kernighan and Plauger’s little line editor, it’s a deliberate part of ed, and consequently ex, and vi, and vim, and presumably other editors too.

Bananas.

My editor didn’t support ; properly. You could pop one in as a separator, but I’m wasn’t doing anything special with it.

Kernighan and Plauger’s editor operates as it parses each command. If they see a ; then just update the current line right there and then. That’s a reasonable choice given their various constraints - writing didactic code in Pascal, in late 70s, for people who’ve never heard of Unix, etc, etc.

My code has a hard divide between command parsing and executing those commands. If you give my editor a command that makes no sense, then nothing should happen. Either it all works, or nothing works. What can I say? I’ve taken the Abrahams guarantees to soul of my being.

To evaluate the line expressions, I need to update the current line without updating the current line while parsing, then actually update the current line when executing.

Look! A Squirrel!`

It all went pretty well. The first four commits were gentle preparations to actually pulling the trigger, and implementing the new functionality, all three lines of it, in the last commit.

(And then fixing a classic C++ blunder (function argument evaluation order!) to actually making it work.)

Actually, I realised afterwards, I pulled the trigger on half the functionality - evaluating the line expressions - but not updating the current line during command execution.

Nevermind. Next time.

Endnotes

This whole endeavour relies on Software Tools in Pascal and Software Tools, both by Brian W Kernighan and PJ Plauger. I love these books and commend them to you. They are both still in print, but new copies are, frankly, ridiculously expensive. Happily, there are plenty of second-hand copies around, or you can borrow them from The Internet Archive using the links above.

For this project I’ve been using JetBrain’s CLion, which I liked enough to buy and keep renewing a license for. I use it all the time now.


Tagged code, and software-tools-in-c++
Older posts are available in the archive or through tags.


Jez Higgins

Freelance software grandad
software created
extended or repaired

Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed