Programming the Web with HyperLANG and HyperCLI
Throw CURL and Node.js in a blender and toss in a bit of COBOL
In 2021 I started working on a command-line tool to make it easier to “program the Web.” That’s when HyperLANG and the HyperCLI was born. Since that time, I’ve continued to improve and expand the Hyper tooling and have found it very rewarding to work with. I even featured it in my book “RESTful Web API Patterns and Practices Cookbook.”
For more on HyperLANG and HyperCLI, join me at GOTO Chicago w/ promo code “mike10” for 10% off
https://b.mamund.com/3ZRG30p
What is HyperLANG and HyperCLI?
Imagine if cURL and NodeJS were tossed in a blender together with a dash of COBOL for flavor (yes, COBOL!). HyperLANG and the HyperCLI makes it easy to discover, navigate, and interact with API resources and data they contain no matter where in the world these services are running on the network.
HyperLANG is the scripting language used to automate repetitive tasks and build scripts for interacting with APIs. It's a simple, domain-specific language that allows you to manipulate resources and perform actions based on the data contained in API responses.
HyperCLI is a command-line interface (CLI). It provides a simple interface for accessing HyperLANG's features and capabilities within a persistent shell.
Turing, COBOL, and HyperLANG
HyperLANG is not Turing complete. It cannot compute all computable functions. It cannot simulate another Turing-complete machine. HyperLANG is just that -- a language. Like a spoken language. And, like all spoken lanuages, it is not strictly axiomatic. It was designed to look and feel closer to a spoken language than machine/computing language.
And that is where the COBOL influence comes in. I chose to make HyperLANG look a bit like COBOL for a number of reasons. First, I just like the look of it. Here's a bit of COBOL (circa 1970) :
Procedure Division.
000-Main-Logic.
Perform 100-Say-Hello.
Perform 200-Get-Date.
Perform 300-Say-Goodbye.
Stop Run.
**
** Setup initial values and say we are starting.
**
100-Say-Hello.
Move 80 to Stringlen.
Move 02 to Dest-output.
Move Start-Msg to Str.
CALL "CEEMOUT" Using Msg Dest-output Feedback.
Move Spaces to Str. CALL "CEEMOUT"
Note the use of Perform
and Move ... to ...
and CALL.
Most “modern” languages have dropped this kind of verbosity in preference for more terse, and more easily computable code. Here's a typical example in C (circa 1970).
// Header file for input output functions
#include <stdio.h>
// main function -
// where the execution of program begins
int main()
{
// prints hello world
printf("Hello World");
return 0;
}
Note that both languages appear in the late 1960s and early 1970s. But they have very different styles.
Now, let's look at a piece of HyperLANG code:
# store values
CONFIG SET {"start":"http://rwcbook12.up.railway.app"}
CONFIG SET {"format":"application/vnd.collection+json"}
STACK PUSH {"title":"stacked-title","tags":"stacked","completeFlag":"false"}
# get initial response
CALL WITH-URL $$start$$ WITH-ACCEPT $$format$$
# add a new record to the list
CALL WITH-FORM TEMPLATE WITH-STACK
# clean up
STACK POP
CONFIG REMOVE start
CONFIG REMOVE format
EXIT
Like COBOL, HyperLANG was designed to seem almost conversational.
Applications, Algorithms, and Mel Conway
You don't need to be an advanced programmer to understand most of what is in this script. Even if you don't know much about the HTTP protocol, this example will be accessible to many people who work "on the Web" regularly.
Also, readers who do have a strong understanding of HTTP will look at this script and see that quite a bit of detail is hidden from view. There are no HTTP methods, one header is referenced, and only the starting URL is supplied. This is a good example of what Mel Conway calls an application language. As he puts it:
"Application languages and algorithm languages are different creatures. The job of a productive application language is not to describe algorithms, but to hide them." -- Mel Conway
One line of this script in particular exemplifies Conway's notion of application language. First, here's the line in *HyperLANG*:
CALL WITH-FORM TEMPLATE WITH-STACK
Now, let's break it down -- actually expand it -- in order to see what is happing here. To do that, I'll resort to some pseudo-code.
* Using the most recent repsonse,
* Find the FORM that acts as a TEMPLATE for write operations
* Retrieve the HTTP method from that TEMPLATE (e.g. POST, PUT, etc.)
* Determine the document format used for sending write operations
* Get a list of all the inputs associated with this write operation
* Fill in all the input values with data from internal memory
* Send the write request (URL, HTTP METHOD, HTTP HEADERS, INPUT values)
That's a pretty extensive list of things to be done -- and even this list is truncated a bit for brevity.
Another way to look at HyperLANG is to see it as an abstraction layer for programming the Web. As Conway says, HyperLANG hides the algorithms and, in doing so, makes writing programs more productive.
Plug-Ins, DSLs, and the Power of HyperLANG
It turns out HyperLANG (and the HyperCLI that is wrapped around it) also makes it easy to build "plug-ins" that can extend the language. The current iteration of the CLI is written in Node.js and authoring plug-ins is just a matter of implementing new functionality (in Javascript) and then exposing that functionality via new HyperLANG keywords. This makes both HyperLANG and the HyperCLI platform handy for both high-level (Web-level) progammers and low-level (machine-level) progammers alike.
The choice to implement a cross-machine programming language in the style of COBOL is an indication of the way I encourage developers to think of programming the Web. This is not a clear-cut axiomatic way of working. It is more conversational than computational. And, like any spoken language, HyperLANG can expand, morph, and grow over time.
The fact that HyperLANG is not Turing complete is a concious design decision and, I think, it points to the potential and power of conversational programming in general.
For more on HyperLANG and HyperCLI, join me at GOTO Chicago w/ promo code “mike10” for 10% off
https://b.mamund.com/3ZRG30p