BASIC
I spent a large part of my teens fiddling with the Commodore 64 and its BASIC. It will always have a special place in my heart. I never really left BASIC behind. From time to time, I code a little kata in the emulator, e.g. Prime Factors, Game of Life or several years later Roman Numerals. When learning a new programming language, my usual exercise is to create a Scheme (Lisp) interpreter, but I have also played with BASIC as a Scala DSL and even turned it upside down creating a BASIC parser in Scheme, using TDD, unit tests and a file watcher to run my tests for all modified files. It was a fun project and I stopped after parsing most of the BASIC code I was able to find on my old disks.
Monkeys Everywhere
So what did I do on the evening of my anniversary? I opened a can of energy drink and had a look at a new programming language. I went for Garmin Connect IQ, a platform by Garmin to build applications for their watches. While I did not own a Garmin device, I wanted to support a developer at my client who wanted to create her own specialised app for her watch.
Connect IQ reminds me a lot of Android: There is an SDK, support for various devices, an emulator, an API for different kinds of apps, an app store with review process and so on. It has manifests, permissions, storage, intents etc. Someone at Garmin had some humour, as the programming language is called Monkey C (with extension
.mc
), the build system is called Jungles (.jungle
) and the system libraries use the Toybox namespace. They even have their own domain-specific property language for managing style elements, derived from CSS. The whole thing is branded with monkeys all over the place.Using a small, proprietary language has disadvantages: There are only few public code samples to copy from and ChatGPT is unable to create any working code in Monkey C. Still I found everything I needed during that first evening: a minimalist Unit Testing framework and CLI commands to build and test my code. Piping the test output through a small shell script added ANSI colours, i.e. Red and Green respectively, to the test output. Perfection! In my tradition of learning new languages, I TDD'ed the Prime Factors code kata as first exercise:
import Toybox.Lang; class PrimeFactors { static function generate(n as Integer) as Array<Integer> { var factors = [] as Array<Integer>; for (var candidate = 2; candidate <= n; candidate++) { while (n % candidate == 0) { factors.add(candidate); n = n / candidate; } } return factors; } }The language itself is object oriented and looks a lot like JavaScript with optional types, the
as ...
clauses. It is a compiled language and all type declarations are optional but can be forced with a compiler flag. I felt at home immediately. What a happy anniversary ;-)
2 comments:
Congrats on your 39th coding anniversary! I began my programming journey with BASIC too. The world has changed over the years, yet the fundamentals remain invaluable. Keep coding and enjoying the journey!
Wow! I knew you were experienced, but how much of a veteran you were I didn't know. This calls for celebration Peter!
May your bugs straighten out in fear
(OMG! Code Cop is coming!)
May your tests save the day, saying
(Code Cop has written me for it!)
May your code makes people jealous
(Who wrote it? Code Cop or something?)
And may it teach others, as always
(Huh, didn't know that was a thing!)
May the cake be delicious,
Let the bugs know you're pernicious,
May your future be most auspicious,
And your endeavours - ambitious!
Post a Comment