Swiftian Satire, or Tragedy?

I honestly cannot tell if Swift developers are seriously eating Irish babies, or taking the Mickey.

From bad implementations of Equatable and Hashable, the wag leaps to:

extension GridPoint : HashVisitable {
    func hash<H: Hasher>(_ hasher: inout H) {

Bravo! That’s easily the funniest punchline to a programming joke since “where do you think the chaos came from?”

Starts with the most bizarre strawman Objective-C Sieve of Erathosthenes I’ve ever seen. A real implementation would be in C, because Obj-C is C with objects, and it’d be massively faster:

#include <stdlib.h>
#include <stdio.h>

typedef char BOOL; // or link in Foundation
#define YES 1
#define NO 0

int main(int argc, char **argv) {
    if (argc != 2) {
        printf("Usage: primes COUNT\n");
    long n = atoi(argv[1]);
    BOOL p[n];
    p[0] = NO;
    p[1] = NO;
    for (long i = 2; i < n; ++i) {
        p[i] = YES;
    for (long i = 2; i < n; ++i) {
        for (long j = i*i; j < n; j += i) {
            p[j] = NO;
    for (long i = 1; i < n; ++i) {
        if (p[i]) {
            printf("%ld ", i);
    return 0;

This does use more lines of code, but they’re short, low-density, and it’s instantly obvious what it’s doing (my predilection for 1-char var names aside). Can you actually decode his filter-based version?

func sieve(_ sorted: [Int]) -> [Int] {
    guard !sorted.isEmpty else { return [] }
    let (head, tail) = (sorted[0], sorted[1..<sorted.count])
    return [head] + sieve(tail.filter { $0 % head > 0 })

let numbers = Array(2...1000000)
let primes = sieve(numbers)

And the runtime experiment:

mdh@Aegura:~/Code/CodeC% time clang -O3 -o primes primes.c                
clang -O3 -o primes primes.c  0.04s user 0.41s system 83% cpu 0.534 total
mdh@Aegura:~/Code/CodeC% time ./primes 1000000 >~/Desktop/primes.txt      
./primes 1000000 > ~/Desktop/primes.txt  0.02s user 0.00s system 89% cpu 0.025 total

mdh@Aegura:~/Code/CodeSwift% time swiftc -O -o swiftPrimes swiftPrimes.swift
swiftc -O -o swiftPrimes swiftPrimes.swift  0.57s user 0.64s system 69% cpu 1.754 total
mdh@Aegura:~/Code/CodeSwift% time ./swiftPrimes >~/Desktop/swiftPrimes.txt  
./swiftPrimes > ~/Desktop/swiftPrimes.txt  51.79s user 26.49s system 99% cpu 1:18.78 total

So the naïve C implementation is about 3,151x faster. I can’t measure it precisely because a limit measurable in C, would take Swift until the heat death of the Universe.

So here’s my question: Is Vincent aware of this, and his theme of “diabetes”, “sugar”, “saccharine”, etc. pointing at how fat, bloated, slow, and deadly Swift is? He never lets on if this is a joke, he keeps tossing more syntax layers on top of Swift.

Not So Easy to Get a Program Right

“By June 1949 people had begun to realize that it was not so easy to get a program right as had at one time appeared. I well remember when this realization first came on me with full force. The EDSAC was on the top floor of the building and the tape-punching and editing equipment one floor below on a gallery that ran around the room in which the differential analyser was installed. I was trying to get working my first non-trivial program, which was one for the numerical integration of Airy’s differential equation. It was on one of my journeys between the EDSAC room and the punching equipment that hesitating at the angles of stairs the realization came over me with full force that a good part of the remainder of my life was going to be spent in finding errors in my own programs.”

-Maurice Wilkes, Memoirs


Trying to load a PNG image and display it on the canvas has been… not fun. Delphi only knew about BMP stored in some horrible Microsoft resource format, and so everything FreePascal adds on top is a pile of hacks or undocumented features. The WWW was not especially helpful.

Mostly I’m posting this so someone else might find it in a search.

uses Classes, SysUtils, Controls, Graphics, LCLType, types, contnrs;

    TSprite = class
        color: integer;
        filename: array of utf8string;
        subrect: array of TRect;
        constructor Create(c: integer; f: utf8string; r: TRect);

    imageCache: TFPObjectHashTable;

function getImage(filename: utf8string): TPortableNetworkGraphic;
    img: TPortableNetworkGraphic;
    img := imageCache.Items[filename] as TPortableNetworkGraphic;
    if img = nil then begin
            img := TPortableNetworkGraphic.Create();
            imageCache.Items[filename] := img;
        except on e: Exception do begin
            LogError(Format('Image %s: %s', [filename, e.message]));
        end; // try
    Result := img;

procedure drawSprite(canvas: TCanvas; spr: TSprite; srect: TRect; tick: integer);
    img: TPortableNetworkGraphic;
    frame, nframes: integer;
    if spr.color <> dawnUndefined then begin
        canvas.Brush.color := spr.color;

    nframes := length(spr.filename);
    if nframes > 0 then begin
        frame := tick mod nframes;
        img := getImage(spr.filename[frame]);
        canvas.CopyRect(srect, img.canvas, spr.subrect[frame]);

Pascal Learning Curve

What I’ve learned so far:

  • I spent a while trying graphics libraries (or failing to even compile them) before deciding I don’t understand the UI model enough yet, so I’ll prototype with some high-level drawing and circle back around to OpenGL or SDL.
  • Build a do-nothing app in Lazarus, make a single form with a default FormCreate method, then quit out and write code starting from there in BBEdit.
    • Part of that is that I’m not going to use a ton of GUI components, and code building is the evil opposite of Interface Builder. In IB, you edit UI and connect it to method names scanned out of the source code, it doesn’t touch your code.
    • The Lazarus editor is nightmarishly wrong and keeps inserting stuff in my code which makes me crazy. Maybe there’s non-crazy-making settings, and probably it seems fine to masochistic Windows and Linux users, but I make enough problems in my life.
  • Naming conflicts are a giant problem, so my current naming scheme is: For class “foo”, it goes in file FooUnit.pas, containing unit FooUnit and type TFoo = class…. I’m naming instance fields _bar and accessors bar() and setBar() as I do in most languages. I’ve mostly got the compiler to stop screaming at me every build. Not letting you name a unit, class, and field the same thing is infuriating.
  • Build with lazbuild -B --bm=Release whatever.lpi; I wrote a script to choose Debug or Release builds and launch the app if nothing went wrong, which is close enough to hitting Cmd-R.
  • Bookmark the docs for:
    • RunTime Library
    • Free Component Library – in particular unit ‘contnrs’ wants to buy some vowels but has dictionaries, lists, etc.
    • Lazarus Class Library
    • There’s very little explanation, so often I have to go digging in source like /Developer/lazarus/lcl. I lost about 30 minutes today because they didn’t document that TCanvas.FillRect uses Brush settings, TCanvas.Rectangle uses Pen settings, and I figured it out by reading the Carbon implementation. 😡 ☕️ 🔪
  • Almost always if there’s a non-domain-specific type I need it already exists. Batteries are included but mostly they’re named badly, or upside down, or hidden in sofa cushions, or the dog buried them and I need a metal detector, or my psycho ex stole them and is holding them hostage for a pity fuck.
  • The actual implementation code isn’t much different from any other procedural language. For a guy who codes in Pascal for one year every 10 years, it’s rolling along pretty fast. The near-equivalency of records and classes, and of functions, properties, and methods is convenient. Defining vars before using them, like in old-timey K&R C, is not convenient. Inline variable definition would be a gigantic quality of life improvement, which I doubt they’ll do.


Trying out alternative languages to work around my performance and native binary problems, I’ve circled back around to the ’70s and ’80s: Pascal. I used classic Pascal on Atari 800 and TRS-80 back in the day, and did quite a bit with Kylix (Linux version of Delphi) before Borland killed that.


  • Fast Compiles. FreePascal compiles faster than anything I’ve used in ages. That was always a major Pascal selling point, and it still is. Optimized for programmer time.
  • Fast Runtime. As close to perfectly optimized machine code as you’re going to get. Computer Language Shootout has competitive times with C++ for most benchmarks, and I think the worst-cases are variations in style.
  • Object-Oriented. FreePascal reimplements Delphi-style objects, which are pretty standard Simula-type OOP. I dislike having to tag methods as virtual, like some C++ or Swift peon, but it has everything I’d expect in a modern OOP system.
  • Reference Counting. No GC pausing, no manual memory management. Like Objective-C 1.0, you have to nil-out field references in your destructor, but otherwise you never need to worry about it.
  • Exceptions. Unlike Objective-C and Swift (which relies on Obj-C frameworks), you can throw exceptions and catch them and the program keeps working. Hooray! Flow control that isn’t insane! There’s no checked exceptions, which is sad, but it works.
  • Cross-Platform. Mac, Linux, Windows, Android, and iOS. Has SDL and OpenGL bindings, and some other options. I’ll see how building out UI for each of those works, but it’s not trapped on Mac like most other choices.
  • Native Binary. No source code included in the downloaded app. Dynamic language obfuscators are a minor obstacle at best, while machine language is hard enough to decompile. Sure, the other option is to put the program online and just have a thin client in the user’s hands, but I’m old-fashioned, I believe in networkless programming and not paying Amazon for server time.
  • Easy Native Library Integration. Pretty much seems to be defining functions as external and calling.
  • Type-Insensitive. I’m usually neurotic about proper capitalization, but here it’s a mercy: The classic Pascals were all-uppercase, Delphi CapitalizedEveryWord, but I prefer lazyCaps. FreePascal doesn’t care.
  • Real Programs. There’s working programmers using FreePascal to keep their (often very expensive) Delphi software running, and writing new code in it. That makes me confident it’s not an unsupported toy, and there’s current documentation and help.
  • BBEdit. Object Pascal syntax mode works fine.


  • Bondage & Discipline. Not quite as BDSM as Java, Swift, Haskell, or classic ISO Pascal, which in practice have no safewords. You can use dynamic arrays, Variant and OOP types, and even dangerously cast anything to anything or screw around with pointers, but it’s not beautiful anarchy like Python or JavaScript.
  • Pascal Syntax. Verbose begin/end pairs everywhere, long words of function, procedure, and such. Semicolon rules are insane (yes, they’re terminators not separators; this is not how we use them in any other language, including English), I’ve taken to just always using begin/end blocks because I don’t trust a misplaced semicolon not to terminate the wrong block.
  • Documentation. FPC’s docs assume you already know Delphi. I found some decent docs at Borland’s site and old Pascal textbooks, but I dunno how a normal person would learn this. Some of the libraries have moved in 3.0, and you’re never going to figure this out unless you like digging thru the guts of a language.
  • Configuration. Put this in fpc.cfg somewhere, and export PPC_CONFIG_PATH to the path containing it:
    #WRITE Compiling with fpc.cfg

    The write is just a sanity check that I have it configured. Instead of the next two lines, I could put -dDEBUG or -dRELEASE on the fpc command-line, but I’m not currently using gdb (unfrozen caveman Mark debugs by writeln), so this is easier. -MOBJFPC forces modern FreePascal mode, not a compatibility mode. -Sh forces a default string type of ansistring instead of shortstring; but to be precise, I always specify utf8string. The -Fu lines add some paths where libraries have been moved.

    I want to have the local directive {$M+} (reflection support) always turned on, but I can’t figure out any command-line option to do that.

  • Look Like a Crazy Person. But sometimes the crazy people are right.


To (re)learn the language, I wrote a 4-function RPN calculator for Mac console: RealCalc

Presumably it compiles just fine on Windows or whatever, but you’ll have to customize the fpc.cfg file. I’m a ways from dealing with that.

Perl 6

This is kind of fascinating in the train-wreck sense, but even aside from weirder-than-Perl5 syntax, taking a speed penalty like that in modern times is not acceptable; computers are fast enough to solve all problems in a few seconds, but the slower your program is, the more power it consumes, and that costs you real money in a data center.

I don’t see any support in Perl6 for a web server, GUI, low-level graphics, sound, or even low-level UNIX libraries, you have to use NativeCall with a lot of wrapper code for every struct. Perl5 made Gtk pretty easy to use, hideous as it may be, and mod_perl made it a powerful choice on Apache servers.

What we expect from a systems programming language has changed since the ’70s-’90s when Perl and its immediate ancestors were invented, and even the most rough, low-level programmers don’t want to reinvent everything from assembly up anymore.

Python has multiple ways now to get faster, I’m currently trying out Cython and getting faster, compiled Python binaries, which can directly call C code (because by that point it is C code). Python’s standard Tkinter GUI is primitive, but SDL works well if you can distribute it. Python’s system libraries and web frameworks are top-notch.

JavaScript isn’t fast, but modern runtimes are surprisingly good; I’d have to write some tests to see how Node or Electron compares to Perl 6, but I’d bet on the massive VM investments in JS. JS does everything now, it’s certainly the most familiar user interface these days.

If you just want a multi-paradigm language for hacking, Scheme and Racket are ideal, supported by tons of papers and books like SICP, and they compile to fast native code.

And then there’s the real outliers, like Lazarus, which is a Delphi-like Pascal IDE, or the usual “I want a hobby language” choices of Haskell, OCaml, Clojure, etc.

Even if Perl6 had come out in the first decade of its development, it would’ve been a little backwards, but compared to modern choices it’s archaic.

I’ve avoided the Whatever Star because, in addition to making Perl 6 look like a lineal descendant of brainfuck, it is governed by rules that are too subtle for my understanding.
—Evan Miller