Programming for a living used to be an active conversation between yourself, the computer, and your colleagues. This Christmas, a new guest is joining the programming party: the LLM.
Large Language Models (LLMs) can talk a lot and, just like your eccentric uncle at Christmas, occasionally blurt out something bonkers. But do we want to invite LLMs to the programming party? And if we do, where should they sit? More importantly, how can they help things flow?
Finding flow while programming is the art of staying in the Goldilocks zone - working on challenges that are not too hard and not too easy.
Raku and Perl are both highly expressive languages with rich operators. Their low and long learning curves enable programmers to pick a place that matches their current skill level and stay in flow.
There is a potential downside, however, for a language like Raku that is optimised for (O)fun. New programmers sometimes encounter code too far beyond their skill level, pushing them outside their Goldilocks zone. For these programmers fear can become a flow stopper. And as Master Yoda wisely said, “Fear leads to anger. Anger leads to hate. Hate leads to suffering.”
The mindshare of expressive languages has suffered for too long.
Fortunately, Father Christmas is smiling brighter than ever this Christmas! LLMs are a gift that can help lift more programmers up the learning curve and into the Goldilocks zone: less fear, more flow.
Expressive languages, like Raku, can offer LLM-powered utilities as part of their tooling, making it easier for new programmers to leap up the learning curve. Here's a simple example.
[12]\d{3}-[01]\d-[0-3]\d ([^ \[]*?)\[([^\]]*?)\]:.*
Now instead of thinking, “WAT?!” Just run the Raku wat command-line utility to help explain it.
wat utility can helpshell> wat "[12]\d{3}-[01]\d-[0-3]\d ([^ \[]*?) [([^\]]*?)\]:.*"
This code extracts log entries in the format "timestamp [source]: message".
Use it to parse log files and extract specific information.
wat works with code snippets or can explain entire programs for you.
shell> wat WAT/CLI.rakumod
This code summarizes code using the LLM::DWIM module.
To use:
- Run `wat <filename>` to summarize a program
- Run `wat "$some-code.here();"` to explain code
- Run `wat config` to change settings
- Run `wat help` to show help
The WAT::CLI module prompts with your LLM of choice:
# keeping the prompt short and sweet
my $prompt = q:to"PROMPT";
You are an expert programmer.
Produce friendly, simple, structured output.
Summarize the following code for a new programmer.
Limit the response to less than $response-char-limit characters.
Highlight how to use this code:
PROMPT
One programmer's WAT is another's DWIM (Do What I Mean). Under the hood, the WAT::CLI module relies on Brian Duggan's LLM::DWIM module's dwim method.
say dwim $prompt ~ $program-content;
The LLM::DWIM module lets you choose the LLM you prefer and is powered by Anton Antonov's excellent LLM modules.
Current LLMs work best with sufficient context - so they can associate problems and solutions. Without context, LLMs can stumble. Just try giving wat an empty context " " and it's like that eccentric uncle at Christmas after one too many!
To have a play with wat this Christmas, install it with Raku's package manager zef:
shell> zef install WAT
Here are some ideas for Raku utilities to help your programming to flow.
Comment Injector - inject useful commentsComment Translator - translate comments into your spoken languageReviewer - suggest potential improvementsModule Documentor - document a module with RakuDocUnit Test Maker - generate unit testsCLI Maker - generate a command-line interface to a programAPI Scaffolder - translate between OpenAPI spec ↔ programCode Translator - translate code from another language to Raku (e.g., Python → Raku)SEO Docs - document the problems the program solves and generate HTML for SEO and further ingestion by LLMs (e.g., nomnom)Ticket Subtasks - generate a set of subtasks required to close a ticketTest Error Summary - summarise the output of many tests with next steps to fixGit Log Summary - generate a stand-up report for your next Scrum meetingGot something in mind that will help your own programming? Thanks to Raku's rich set of LLM modules and command-line support it's easy to do.
Merry Christmas, and happy coding with Raku + LLM powered utilities!
Originally published 2024 on the Raku Advent Calendar.