• AI coding assistance is speeding me up at work

    The newer models like o1 and o3-mini-high have come on leaps and bounds. Here’s a non-exhaustive list of the kinds of problems I hit, and where it helps:

    Integrating new libraries or tools

    Example: Yesterday I needed to get a list of all the variables present in a Twig template. Twig doesn’t do this out of the box, so you need to reverse-engineer it. I googled a bit and found some old forum posts that were in the right ballpark, but I’d still need to get into the weeds of the Twig codebase to really get to grips with it.

    Result: 9/10. I gave the forum post to o1-pro, and explained the issue. It very nearly one-shotted a solution. There was one issue with Twig’s class names1 , but zero logic problems. It worked fine.

    I then needed to extend this to find variables within logic statements like {% if contact.first_name == bob %} and it merrily adapted it after a few minutes of thinking. It also explained to me what it had done, how it worked, and why. I could have probably figured this out myself, but grokking the Twig codebase would have taken…a day? Optimistically?

    Explaining complex code

    Example: as part of the same problem I came across this:

    /**
       * Examine a token string and filter each token expression.
       *
       * @internal
       *   This function is only intended for use within civicrm-core. The name/location/callback-signature may change.
       * @param string $expression
       *   Ex: 'Hello {foo.bar} and {whiz.bang|filter:"arg"}!'
       * @param callable $callback
       *   A function which visits (and substitutes) each token.
       *   function(?string $fullToken, ?string $entity, ?string $field, ?array $modifier)
       * @param string|null $format
       *
       * @return string
       */
      public function visitTokens(string $expression, callable $callback, ?string $format = 'text/html'): string {
        // Regex examples: '{foo.bar}', '{foo.bar|whiz}', '{foo.bar|whiz:"bang"}', '{foo.bar|whiz:"bang":"bang"}'
        // Regex counter-examples: '{foobar}', '{foo bar}', '{$foo.bar}', '{$foo.bar|whiz}', '{foo.bar|whiz{bang}}'
        // Key observations: Civi tokens MUST have a `.` and MUST NOT have a `$`. Civi filters MUST NOT have `{}`s or `$`s.
    
        $quoteStrings = $format === 'text/html' ? [
          // Note we just treat left & right quotes as quotes. Our brains are not big enough to enforce them
          // & maybe user brains are not big enough to use them correctly anyway.
          '"',
          '&lquote\;',
          '&rquote\;',
          '&quot\;',
          '&#8221\;',
          '&#8220\;',
          '&#x22\;',
        ] : ['"'];
    
        // The regex is a bit complicated, we so break it down into fragments.
        // Consider the example '{foo.bar|whiz:"bang":"bang"}'. Each fragment matches the following:
    
        $tokenRegex = '([\w]+)\.([\w:\.]+)';
        $quoteRegex = '(?:' . implode('|', $quoteStrings) . ')';
        /* MATCHES: 'foo.bar' */
        $filterArgRegex = ':[\w' . $quoteRegex . ': %\-_()\[\]\+/#@!,\.\?]*'; /* MATCHES: ':"bang":"bang"' */
        // Key rule of filterArgRegex is to prohibit '{}'s because they may parse ambiguously. So you *might* relax it to:
        // $filterArgRegex = ':[^{}\n]*'; /* MATCHES: ':"bang":"bang"' */
        $filterNameRegex = "\w+"; /* MATCHES: 'whiz' */
        $filterRegex = "\|($filterNameRegex(?:$filterArgRegex)?)"; /* MATCHES: '|whiz:"bang":"bang"' */
        $fullRegex = ";\{$tokenRegex(?:$filterRegex)?\};";
    
        return preg_replace_callback($fullRegex, function($m) use ($callback, $quoteStrings) {
          $filterParts = NULL;
          if (isset($m[3])) {
            $filterParts = [];
            $enqueue = function($m) use (&$filterParts) {
              $filterParts[] = $m[1];
              return '';
            };
            $quoteOptions = implode('|', $quoteStrings);
            $quotedRegex = ':' . '(?:' . $quoteOptions . ')' . '(.+?(?=' . $quoteOptions . ')+)' . '(?:' . $quoteOptions . ')';
            $unmatched = preg_replace_callback_array([
              '/^(\w+)/' => $enqueue,
              ';' . $quotedRegex . ';' => $enqueue,
            ], $m[3]);
            if ($unmatched) {
              throw new \CRM_Core_Exception('Malformed token parameters (' . $m[0] . ')');
            }
          }
          return $callback($m[0] ?? NULL, $m[1] ?? NULL, $m[2] ?? NULL, $filterParts);
        }, $expression);
      }

    which was being called like so:

    $e->getTokenProcessor()->visitTokens($e->string, function($token = NULL, $entity = NULL, $field = NULL, $filterParams = NULL) {

    I very much needed some help here. Passing a function in the parameters is not something I encounter very often. Plus the callbacks in the regex. I had more than two problems.

    Result: 10/10. I used o1 for this, as I wanted a bit of reasoned care. o1-pro would be the fallback if o1 struggled, but it’s slower. o1 broke down the function signature, the regex patterns, the regex construction, and the callbacks. I didn’t spot anything it had missed – although to be fair I probably wouldn’t in this case.

    Reworking deprecated templates

    Example: we had an old Mailchimp template that just stopped working one day. Something was obviously deprecated. Mailchimp, having long abandoned all pretense of caring about anything but money, were little use. And it was a gigantic template. Could o1-pro just…fix it?

    Result: 5/10. Not really. o1-pro knew what the problems were, and explained them in detail. It tried very hard to rewrite it, but the result didn’t quite work. I think it was just too big. It seemed close, but it felt like it would take longer to tease apart the underlying issues from o1’s fixes – so we just rebuilt it. I’ve saved it to try again on o3-pro.

    Dumb mistakes

    The code obviously should work, and there’s obviously some stupid problem somewhere because I am stupid.

    Example: Oh god why doesn’t this work, please fix it, I’m very tired

    'groups' => [
            'include' => $this->dto->includeGroups,
            'exclude' => $this->dto->excludeGroups,
          ],
    'from_name' => $this->dto->fromName,
     from_email' => $this->dto->fromEmail,
    'scheduled_date' = $this->dto->scheduleDate->format('Y-m-d H:i:s'),
    'approval_date' => date('Y-m-d H:i:s'),
    'created_id' => $this->dto->createdID,

    Result: 10/10. Claude or o3-mini spot this instantly, are very nice about it, and suggest I get some sleep.

    How could this be better?

    Sometimes you know there’s a better way. No particular example here, but I do this pretty regularly with functions I feel aren’t very elegant.

    Result: 8/10. Works very well on normal code. It regularly gives you new approaches, or reminds you of things you’d forgotten. So you’re learning too.

    Occasionally it’ll optimize beyond the point of readability, and on fancier stuff it sometimes recommends overcomplex patterns: set up factories and repositories etc. But you can just say ‘I don’t need it that complex’ and it’ll usually back off.

    Drudge work

    I have done this a million times, please do it for me and save me 10 minutes.

    Example: I need a function to extract x data from this embed, parse it, and fire a callback with the results. Here’s the example given in the documentation, and here’s the output I need.

    Result: 10/10. It used to be that Claude and 4o would regularly make one or two mistakes. But o1 and o3-mini reliably get the standard stuff right first time.

    Complexities in the full codebase

    Example: somewhere in the processing of renewing a membership, but only in unknown circumstances, an end date is being added to the payment object. There are a bunch of symfony events being fired, and there’s my own custom code on top of the default handling, and I don’t know where it’s happening or why.

    Result: 0/10. The full codebase doesn’t fit into the context window, the latest code is way outside the training window, and I can’t practically fine-tune on it2. I have to handle this the old-fashioned way, like it’s 2024 or something.

    I cannot wait until this is a thing. My life will change. Probably the world too.

    Integrating the API

    Result: 9/10. I won’t go into much detail here, but integrating with OpenAI and Anthropic is trivial: “here’s an API key and an endpoint, have at it”. Google, not so much – projects and credentials and libraries and blah.

    The only catch is that it’s slower than you expect: you forget that the API needs to wait for all the tokens to generate, while the regular chat UI shows them as they appear in real-time.

    How can I achieve this thing?

    OpenAI’s new Deep Research tool is a wonder. You can send it off to do 5-30min of research (usually about 10) and it’ll go google a bunch of things, read a bunch of pages, and generate a report for you.

    Example: what options are there for open-source email builders? I need something I can embed into my website. It needs to be able to do x, y and z. I’ve tried a and b, and I had these problems. Please let me know the advantages and disadvantages of each, as well as any user reviews.

    Result: 11/10. Amazing, job-changing stuff. I’ve had it make me reports of 11,000 words. These have had some misunderstandings, but if a human wrote me one of these I would consider they had done a good job. No hallucinations so far. They’re just so good at starting you off on thorny problems. And they save you hours.

    Conclusions

    o1-pro and Deep Research are only available on OpenAI’s Pro tier, which is £200/month. This is a lot of money. We decided to try it at work for a month, and it’s been an obvious win. My dev time is worth £100+/hr, and the Twig work alone has covered that. It’s a no-brainer if you can afford it.

    I haven’t even mentioned the AI-completion built into PHPStorm, which is so very pleasing when it does something clever.

    There’s obviously the tedious shibboleth: it’s not perfect3. You have to have your wits about you. But while there is plenty in AI that’s genuinely difficult – copyright, for example – “this tool is not perfect therefore I won’t use it” is throwing the baby out with the bathwater. Just look at what you can do now.

    1. It thought the relevant class was Twig\Node\Expression, while it was actually Twig\Node\Expression\AbstractExpression – easy fix ↩︎
    2. I think? I don’t understand fine-tuning very well ↩︎
    3. The…least interesting conclusion in any domain? ↩︎
  • Links for January 2025

    The Online Sports Gambling Experiment Has Failed

    US-centric argument that online gambling should be regulated out of existence.

    […] it is clear from studies and from what we see with our eyes that ubiquitous sports gambling on mobile phones, and media aggressively pushing wagering, is mostly predation on people who suffer from addictive behaviors.

    That predation, due to the costs of customer acquisition and retention and the regulations involved, involves pushing upon them terrible products offered at terrible prices, pushed throughout the sports ecosystem and via smartphones onto highly vulnerable people.

    This is not a minor issue. This is so bad that you can pick up the impacts in overall economic distress data. The price, on so many levels, is too damn high.

    Dark Energy May Not Exist: Something Stranger Might Explain The Universe

    I like this because it’s the rare theory that’s neatly simple and comprehensible to interested non-physicists. It possibly makes no sense to proper physicists. The basic idea is that some areas of the universe are a lot more dense than others:

    More matter means stronger gravity, which means slower time – in fact, an atomic clock located in a galaxy could tick up to a third slower than the same clock in the middle of a void.

    When you stretch that over the huge lifespan of the Universe, billions more years may have passed in the voids than in the matter-dense areas. A mind-boggling implication of that is that it no longer makes sense to say that the Universe has a single unified age of 13.8 billion years. Instead, different regions would have different ages.

    And since so much more time has passed in the voids, more cosmological expansion has taken place there. Therefore, if you look at an object on the far side of a void, it would appear to be moving away from you much faster than something on this side of the void. Over time, these voids take up a larger proportion of the Universe, creating the illusion of an accelerating expansion, without needing to conjure up any dark energy.

    slashpages.net

    Neat idea for standardised old-school website links, for old-school people who still have their own website

    Slash pages are common pages you can add to your website, usually with a standard, root-level slug like /now, /about, or /uses. They tend to describe the individual behind the site and are distinguishing characteristics of the IndieWeb.

    Geoengineering

    Neal Stephenson makes the case for geoengineering the climate by injecting sulphur dioxide into the stratosphere. Loathed by left and right, and not without risks. But better than what’s coming…? Also pretty sunsets I guess. Contains an impressively horrific prediction for an imminent climate-related disaster.

    My prediction for the Trump administration is that someone will talk him into doing this, and he’ll just do it because Trump, and annoyingly it’ll work.

    History has taught us that when sulfur dioxide (SO2) is injected into the stratosphere by major volcanic eruptions, global temperatures go down for a couple of years until the SO2 naturally falls out of the atmosphere and things return to normal. This is a natural scientific experiment that has been repeated many times throughout recorded history, but only since the Pinatubo eruption in 1991 have we been in a position to capture data and make sense of it.

    Magic Links Have Rough Edges, but Passkeys Can Smooth Them Over

    Magic links are easy for the public, frustrating for power users, and much preferred by websites who really really don’t want to store passwords any more – ie. everyone. They have their issues, and this article argues that layering passkeys on top is a good fix. I agree that this is The Way eventually, but…

    Passkey technology is elegant, but it’s most definitely not usable security

    …I nodded along with this argument that passkeys are not viable yet. Not because of passkeys themselves, which are certainly better than passwords. But because the surrounding infrastructure is too confusing. The tech is standardised, but each OS implements it in mutually exclusive ways that the public have zero chance of understanding. I get tripped up sometimes, and I know what I’m doing. I’ve spent a lot of time implementing password managers in the last year, and I am not shy about treating my users as intelligent enough to understand new tech, but I am not going anywhere near introducing passkeys yet.

    Passkeys are now supported on hundreds of sites and roughly a dozen operating systems and browsers. The diverse ecosystem demonstrates the industry-wide support for passkeys, but it has also fostered a jumble of competing workflows, appearances, and capabilities that can vary greatly depending on the particular site, OS, and browser (or browser agents such as native iOS or Android apps). Rather than help users understand the dizzying number of options and choose the right one, each implementation strong-arms the user into choosing the vendor’s preferred choice.

    No one understands how playing cards work

    Solitaire is really hard to understand, and there are a bunch of variations. It’s also surprisingly popular. Fun article that wanders off into the history of cards.

    “One of the embarrassment of applied probability is that we can not analyze the original game of solitaire,” […] “What’s the chance of winning, how to play well, how do various changes of rules change the answers?” Diaconis wrote. “Surely you say, the computer can do this. Not at present, not even close.”

    The tech to build the holodeck

    “Gaussian splatting” is an objectively fantastic thing to say. It refers to a 2023-developed technique for scanning objects into 3D space – in a much more effective way than creating a massive number of polygons. You can just do it on your phone. I got the app and it’s as impressive as they say – particularly because you can export to standard models.

    When I visited my elderly mom in Germany recently, I realized it could be one of the last times I see her in the cozy little house she has called home for more than two decades. So I did what anyone would do: I busted out my phone and took lots of photos of the place to preserve as many memories as possible: the warm fireplace; the shelves full of familiar books; the rickety old garden bench up front that everyone signed during a special birthday celebration many years ago.

    Then, I tried something else. I opened up Scaniverse, a 3D scanner app from Pokémon Go maker Niantic, and captured some of those things as 3D objects, crouching and tiptoeing my way around them as I slowly moved my phone to record every angle and inch. The results were a bit imperfect around the edges, but they still felt profound. When I opened the scans up later, both on my phone and with a VR headset, I was able to look at that weathered garden bench from all angles, as if I was standing right in front of it. The experience touched me emotionally in ways I wasn’t prepared for.

    Which AI to Use Now: An Updated Opinionated Guide

    A regularly-updated guide to which AIs are best for your use case. Doomed to be out of date the moment it’s published (DeepSeek’s image model! o3-mini! o3-mini-high! That’s just the last week!) but a valiant effort and as good as you can get.

    We are going to go through things in detail, but, for most people, there are three good choices right now: Claude from Anthropic, Google’s Gemini, and OpenAI’s ChatGPT. There are also a trio of models that might make sense for specialized users: Grok by Elon Musk’s X.ai is an excellent model that is most useful if you are a big X user; Microsoft’s Copilot offers many of the features of ChatGPT and is accessible to users through Windows; and the new DeepSeek, a Chinese model that is remarkably capable (and free). I’ll talk about some caveats and other options at the end.

    I’m trying hard to keep up with AI. I find it spectacularly interesting. But I’ve had to go back to Twitter for that, because the Official Bluesky Opinion is that AI is made by techbros, who are bad, and so we work backwards from that to conclude AI is a scam a la crypto. Lots of people I admire seem to have adopted this opinion wholesale, which is dispiriting.

    The Short Case for Nvidia Stock

    The article that probably caused all the fuss in the markets earlier this week. Nominally about NVIDIA but really about the underlying technology, it’s a remarkably clear explanation of the current state of AI models, how they work, and why there’s so much enthusiasm at the moment for ‘reasoning’ models. Super technical but just about within reach if you’re familiar with the broad concepts. I learnt a lot.

    This represents a true sea change in how inference compute works: now, the more tokens you use for this internal chain of thought process, the better the quality of the final output you can provide the user. In effect, it’s like giving a human worker more time and resources to accomplish a task, so they can double and triple check their work, do the same basic task in multiple different ways and verify that they come out the same way; take the result they came up with and “plug it in” to the formula to check that it actually does solve the equation, etc.

    It turns out that this approach works almost amazingly well; it is essentially leveraging the long anticipated power of what is called “reinforcement learning” with the power of the Transformer architecture. It directly addresses the single biggest weakness of the otherwise phenomenally successful Transformer model, which is its propensity to “hallucinate”.

  • RSS still works

    RSS still works

    Social media used to be a great source of interesting things. Twitter in particular: just follow a bunch of interesting people and you’re almost guaranteed to see good stuff whenever you open it. I no longer understand this desire to follow and lament the worst people in the world, though I used to do that too.

    But obviously all the social media sites are having an existential meltdown1. I feel like I’ve been pretty resilient to the awfulness, but even so I’m using them all less and less. In fact, for the last few months I’ve found my most used app to be my trusty RSS reader.

    RSS still works surprisingly well. It’s obviously never going to have a comeback: it’s just too hard to explain. And most websites don’t advertise their feeds any more. But the feeds are still there. Even Substack has them: x.substack.com/feed will do it2.

    Years ago I tried a bunch of readers, and settled on Newsblur. It’s really good. The iOS app is solid and well designed. I regularly sit on the Tube scrolling through a day of posts, and it’s impressively frictionless. It just works. There’s a free tier, but the $36/year is worth it.

    1. Twitter: too many right-wing lunatics and scummy adverts
      Bluesky: too many left-wing lunatics; somehow more depressing
      Facebook: I don’t even mind the adverts – it’s the whatever-the-hell-everything-else-is. Still the only place to actually catch up with friends.
      TikTok: too much unpleasantness for me
      Instagram: spending the weekend converting itself into TikTok
      LinkedIn: hahaha ↩︎
    2. I’ve yet to find a magical all-your-subscriptions feed, sadly ↩︎
  • 2024: Hardware

    Fuji X100V

    I have a properly beautiful mirrorless camera. The picture quality is out of this world. I love it. But it’s big and heavy and I never take it anywhere.

    So I picked up a second hand Fuji X100V1. It’s solid, but slips into my coat pocket without difficulty. It’ll fit into the back pocket of my jeans if needed. It’s always there.

    It’s not a zoom lens: it’s fixed at 35mm. I have to move myself. This is great: it’s teaching me to compose properly. Also I shoot in JPEG and do as much in the camera as possible, which is a new challenge after years of being Mr Lightroom.

    It comes with a load of picture ‘styles’, which I have never paid any attention to in the past. Who cares about fixed colour presets, right? Turns out the Fuji ones are quite lovely. Maybe it’s because they mimic the old film colours I used back in the day. But I’m using them a fair bit.

    It’s surprising how much better than the iPhone it is. It’s not so good in the dark. But it’s lovely in the day.

    Ultimate Hacking Keyboard

    I never had any interest in mechanical keyboards. They click, right? Seems annoying. Anyway, I was wrong.

    The Ultimate Hacking Keyboard is just so tactile. You get physical feedback on every keypress, and the texture of that feedback is super pleasing. They clack and click and resist you for just the right amount of time. So nice.

    (Being a newbie I got the Switch Tester first so I could decide which types of keys I like best. I chose Box Brown.)

    There’s also the trackpoint attachment, which I like because trackpoints are the greatest. You can get a trackball too, if you’re one of those people.

    The whole keyboard splits so that you can put your arms where you want. This is also better than you might expect. I had no trouble adapting to one hand each side of the keyboard – I think I touch-type that way anyway.

    It is very very not for everyone. There are no arrow keys, and a bunch of the other buttons have dual purposes. You have to rewire your brain to use the mod key and the ‘home’ row. This is maddening for a few days, and has a long tail. After 6 months I am 80% of the way there: I can do arrows intuitively, but Home/End/others, not so much. I’m still climbing the mountain, but I believe the view from the top is great.

    That said…I have the new UHK 80 – arrow keys included – on pre-order.

    1. After reading David Hobby’s book ↩︎
  • 2024: Books: The Travelling Photographer’s Manifesto

    I’ve read a lot of books on photography. Memoirs, theory, technical guides: there’s a lot of good stuff out there. But just occasionally a book speaks to you. The Travelling Photographer’s Manifesto, by David Hobby, is one such book.

    So you’re taking your camera to a new country and you want to get some decent photos. Maybe you don’t speak the language. Maybe you don’t know your way around. Maybe you’re secretly nervous you can’t do the place justice. Maybe you’d love to get to know the locals and take some portraits, but let’s be honest: that kind of charm is a superpower and you don’t have it. But whatever you’re doing, you’re going to need a lot of kit – best to pack it all just in case, right…?

    This book tells you how to do these things. Like literally, how can you introduce yourself to a complete stranger and – respectfully, in a way that isn’t exploiting them and that works for you both – end up with a nice portrait that makes both your lives a little better? What literal words can you use to achieve this?

    David Hobby has spent years taking willing students to Hanoi and teaching them how to navigate such new territory. What kit should you carry? What can you prep in advance? How do you get the lay of the land into your head quickly enough? How do you push through the nerves of talking to people? All this is explained in specific detail.

    You learn the beauty of the early morning, and the benefit of naps. You learn the value of tiny bulldog clips, and that you can bond over Google Maps. You learn about shooting how it looks vs how it feels, and how to decide which you want. You learn tried-and-tested approaches to finding your shots, and planning your day.

    And you learn the social side that nobody actively teaches because it’s usually secondary to the technical side (but also maybe because nobody’s actually sure they’re doing it right). It’s the kind of solid advice that feels like common sense once you hear it, but you wouldn’t discover it by yourself for years.

    Then there’s the technical side: tips and tricks on composition, lighting, timing, rhythm – the accumulated wisdom from decades of photojournalism. I’ve read enough photography manuals to recognise gold dust when I see it.

    And above it all: what is it you’re trying to do? How can you come up with your raison d’etre for being in this place with a camera? How do you work backwards from that?

    I am pretty timid when alone in new places, and in all honesty my travel photography hasn’t been up to much of late. I may come back with some decent compositions, but I’m never far from the beaten track. I have found some ways around this1, but I’m certainly way too awkward to befriend any locals. That’s just alien. Yet…reading this book I could see a pathway. In my dreams I’m signing up for his 2025 Hanoi trip.

    About 2/3 through this book inspired me to buy myself a Fuji X100V. It’s always in my pocket now. It’s brilliant too. I’m hopeful.

    1. I recommend carrying a large toy dinosaur to kick you out of your comfort zone and stop you worrying what other people think. Bear in mind his reputation may rapidly outgrow yours. ↩︎