Learn to program BASIC with a Twitter bot
Lead image created by katie_panda on Twitter.
With all the advances in programming languages over the past fifty years or so, why would you want to learn a language that saw its heyday fade in the 80s? It might not be the best language for active development of cutting-edge systems, but if you are new to programming and want a simpler way to understand its concepts, BASIC might be the way to go.
The built-in BASIC interpreter on the Commodore 64 was my first exposure to programming. With its simple variables and GOTO commands, it showed me how to think about data as an item and programs as a series of directions. There were even adventure novels that had portions of the story encoded as BASIC programs that you had to copy out and run, giving you a better sense of what you could do. It wasn’t going to get me a fancy developer job, but it did give me a head start when I encountered more complex languages like C++ and Java later on.
Dominic Pajak agrees. He built a Twitter bot that runs tweets as BASIC programs on an 8-bit BBC Microcomputer emulator, and later joined forces with Matt Godbolt to create a modern editor to support it. It’s a simple way for anyone to get started with a BASIC program and see their results in a single tweet.
We reached out to Pajak to understand how he sees BASIC’s relevance today, how he built the bot, and what amazing programs have been created on a decades-old system.
Q: It’s a pretty simple concept—someone writes code in the Owlet editor, then tweets that program @bbcmicrobot, and voila: a quick video of the program for all to see. How’d you build the bot?
A: I used the free Twitter API and Node.JS. Initially, I used a very cool BBC Micro emulator called jsbeeb that I was able to deeply integrate with, inject tweets into the emulator’s memory, and output video frames for ffmpeg to stitch together as an mp4 to reply to the original tweet with. The service itself was running in my garage on a Raspberry Pi to start with, then onto AWS Graviton. I also once did a “live special” with an Arduino connected to a genuine 1980s machine + CRT and had it execute people’s code tweets live on YouTube once. That was fun.
Q: While I get a nice shiver of nostalgia from seeing all that BASIC code, why build a bot to run it today? Is it still relevant?
A: If you grew up in the 80s, you learned to code in BASIC. A generation of kids went on to a career in tech because their home Commodore 64 or Sinclair Spectrum had BASIC pre-installed in ROM. In the UK, we had the BBC Micro in schools. The BBC Micro came with a more modern version of BASIC called BBC BASIC. This implementation had support for functions and procedures—you can structure code without ever needing the much maligned GOTO. BBC BASIC also had a built-in 6502 assembler. And BBC BASIC was fast. The creator of BBC BASIC was Sophie Wilson at Acorn Computers who later went on to design the ARM architecture, now the most widely used processor architecture in the world.
Coincidentally, BBC BASIC is also expressive and easily abbreviated (down to byte tokens in fact), which means it’s possible to cram some pretty impressive demos into the 280 character limit of a tweet!
Q: With all the advances in computing technology since the BBC Micro, what advantages does BASIC have in teaching programming to new learners?
A: The immediacy of that 80s home computer experience was awesome. You powered on the machine and went straight to a prompt asking you to code. No waiting to boot, no installs, no distractions. Admittedly, the frustrations of data cassettes getting chewed up or trying to find typos in a 100 line type-in BASIC program ruins my rose-tinted story, but we can still learn from the advantages of that experience in a modern context I think. You can see that Arduino and Raspberry Pi inherit a lot from that same philosophy of hands-on immediacy.
[Ed. note: we actually had to save programs on what looked like audio cassettes. If you know what an audio cassette is.]
BASIC gets a bad rap but it’s still one of the easiest introductions to the fundamentals—variables, conditionals, loops—the experience of which is relevant to many languages today. And BBC BASIC goes further by adding features to support structured programming. You can use meaningful variable names, call subroutines by label, implement recursion neatly, and never need to use a GOTO or reference line numbers—it addresses issues that Dijkstra famously had with BASIC. Beyond this, BBC BASIC comes with built-in support for color text and graphics keywords so beginners can see something fun happen in their very first program. And that first experience is important as it can make beginners love coding or put them off for good.
That all said, as much as I love it, BASIC is pretty dated these days. Raspberry Pi founder Eben Upton, also a BBC Micro fan, summed it up nicely:
“…You learn it, and then you move on. Maybe Python’s a better choice these days because the ladder goes up further, but nothing wrong with BASIC”
Q: I remember a lot of the early floppy discs I got had a bunch of very cool programs that sprung from the demoscene. That spirit is still alive and well, so what’s the coolest thing you’ve seen through the bot?
These days the bot is hooked up to beebjit which emulates a 7 GHz equivalent 6502 processor on the backend. It can emulate three hours in just a few seconds. This means people are able to experiment with stuff that would have been an overnight job to iterate on the original hardware (the resulting code gives the same real-time output on the retro hardware as it does the bot, just a longer wait to pre-render). Cool things are happening as a result:
A mind blowing ray tracer created in a tweet created by Steve McCrea
Amazing palette cycling animations from Paul Malin
There is so much great stuff to see I’ve not covered though. People are creating way better stuff than I had imagined when I first built the bot, that’s for certain.
If you want to see these programs run live, check out the embedded sandbox-style tutorial for BBC BASIC. It has 9x 6502 emulations embedded in it.Tags: basic, bbc basic, twitter bot
The story behind BASIC (The acronym originally stood for: Beginner’s All-purpose Symbolic Instruction Code)
Wile working at Marconi, one of their engineers wrote a. program that played music on their 4030 computer in his own time. This computer had a loudspeaker circuit that made a sound depending on the data being passed along it’s circuits. By choosing what data was being passed he could play any note he wanted. One night, after normal work, he phoned his wife, who was a music teacher, and played over his phone the theme tune from the Sound of Music. He even wrote a program in his own time that could play any tune, simply by entering what note you wanted punched out on paper tape. Great engineer.
I developed a 3D “navigation” program in Visual Basic 6. It became useless when the dll file dx4vb or something like that was no longer supported. But I’d love to feed that program to this bot! LMKnow