It’s The Web, Basically

If you are of a certain age, you probably learned to program in Basic. Even if you aren’t, a lot of microcontroller hobbyists got started on the Basic Stamp, and there are plenty of other places where to venerable language still hides out. But if you want to write cool browser applications, you have to write JavaScript, right? Google will now let you code your web pages in Basic. Known as WWWBasic, this is — of course — a Javascript hack that you can load remotely into a web page and then have your page use Basic for customization. You can even import the thing into Node.js and use Basic inside your JavaScript, although it is hard to think of why you’d want to.

According to the project’s documentation — which is pretty sparse so far, we’re afraid — the Basic program is compiled into JavaScript on page load. There are a few examples, so you can generally pick up what’s available to use. There are graphics, the ability to read a keyboard key, and a way to handle the mouse.

If you were thinking about old-school games, so was Google, apparently. It would be fun to pull out some of the old books full of Basic games and get Star Trek, Wumpus, and all the other games of that era in the browser. However, it looks as though some things that would be difficult are yet to be implemented (for example, the INPUT statement). We suppose you could write your own quasi-input function using INKEY but that would be painful.

We couldn’t find any way for the Basic code to interact with the browser data directly which is a shame because that means your output is limited to a virtual Basic “screen.” It looks pretty good for graphics, but the text output looks like an old-school computer, which is charming but not terribly practical. Microsoft’s VBScript technology for example, can write into the page just like JavaScript does, and that would be nice to see in WWWBasic.

Is it practical? Probably not, but we enjoyed seeing our old friend Basic show up in the browser again. The fact that unlike VBScript it is sort of retro just made it that much more fun.

If you want a more traditional Basic experience, Quickbasic is still around. Or, if you want to stay in the browser, you can do that, too. Incidentally, no actual donkeys were harmed during the production of this post.

43 thoughts on “It’s The Web, Basically

      1. GOTO can actually be very useful – but the cases in which it is such are very small.

        One case is when in a very deeply nested set of IF-THEN constructs, sometimes you just want to break out. More modern versions of BASIC allow for a “BREAK {num}” to bust out so many nested levels, but if you are really deep in the weeds, such a construct may not be easy to implement because you have to count and figure out your nesting level. Instead, a quick “GOTO label” can make all the difference.

        That said, if you are that deep into nested IF-THEN constructs – then perhaps your code and implementation needs refactoring…

        There’s another example I’ve seen that involves the use of IF-THEN constructs to implement a very compact and readable state machine architecture – somebody on a forum showed me this (in a discussion on whether GOTO was bad or good – his example changed my mind!) for an implementation in PIC BASIC (or maybe it was PBASIC? All I do remember is that the BASIC was for a PIC microcontroller, and didn’t have SWITCH-CASE available). It was quite elegant.

        But ultimately, GOTO is one of those language features that only gurus of the language should ever touch, and most of the time even they know better than to mess with it…

    1. Yeah actually, I learned TUTAC assembly first. Then FORTRAN. Then Basic and PL/I about the same time more or less. APL and Forth fit in there somewhere. Then Z80 and 1802 assembly. I am somewhat promiscuous when it comes to programming languages. Like most things in life, I try to enjoy their differences. I actually PREFER Basic on the low-end PICs because it generates code better on their architecture than stack-based languages with heaps.

      1. It’s not about vintage machines (although I own some Z80 based vintage computers).

        And I never did anything really important in QB. I was 11 oder 12 back then. But I liked how easy it was to access the serial and parallel port on a computer. So I started hooking up leds and buttons to the COM-Port and doing crazy stuff with Hardware connected to the PC.

        I liked the process of writing a piece of code and something would happen in the real world according to what I programmed.

        A few years later I bought my first AT90S2313 (now known as ATtiny2313), hacked together a serial programmer and started using BASCOM.

        Then I learned PHP, Java and a bit of Pascal and discovered C for the embedded world of microcontrollers.

        And 17 years later I am earning my money by pressing buttons on a keyboard in the right order to tell a µC to do something. Just because my physics teacher in the 6th grade gave me a floppy with QB4.5 and said “try it. you’ll like it”

        1. I was on GW-BASIC for awhile after the C64, then on to C– … which was a early C like macro augmented assembly language (a few years before GNU compilers). a 40MB blank screensaver is one thing, but it seems modern home user systems have shifted more toward information appliances rather than a general purpose computer.

          When google announced Foveated rendering, I was 90% sure there was an Amiga with multiple rendering resolutions on the same screen at one point in the 90s. You code long enough, and everything starts to loop… ;-)

    1. If you care to see where QB has gone today – check out QB64 (go to qb64.org – don’t go to the .net site, as it is down – and who knows when it will be back; galleon seems to have abandoned his baby for some reason – but others are keeping it alive and expanding it).

      As an idea of what QB64 can do: OpenGL, built-in TCP/IP and other network stuff, full-on sound control (no more simple “SOUND” commands!), database access…

      At one time there was a way to compile to an Android target – it’s still possible to run QB64 on Android (and I think there is a way to compile, etc – but it’s a bit more convoluted).

      There’s also a library available to do cross-platform GUI rendering called “InForm” – basically, you can do something akin to event-driven VB-like apps for the desktop. It’s a work in progress, but what’s available so far is pretty amazing.

      QB64 compiles programs to native binaries – it isn’t interpreted, nor is it a run-time tokenized system. So it is fast – really fast.

      A few years back on Steam a game was greenlit to be published, called “Black Annex” – it was written in QB64 and was pretty amazing (you may have seen videos of it in action). Unfortunately, it never was released, and the developer kinda seemingly fell off the face of the planet. I have no idea what happened there…

  1. I had to program in BASIC, because the first affordable computers (Casio and Sharp calculators, ZX80, Video Genie, etc.) were all running on it.
    The only other option (if ever) was assembler.
    I tried assembler on the Sharp calculator once, but because the processor was so slow, and it’s internal structure highly optimized for BASIC, it wasn’t much faster with it.

    ASAP, I switched to PASCAL. I never liked Quickbasic, but did some stuff in Visual Basic.
    Nowadays, I’m pretty much stuck with C/C++, and recently some Python.

    If I had the time and need, I’d have a look at Rust, but certainly wouldn’t go back to BASIC.
    Some things are better left buried in the past.

    1. Heh, I lusted after one of those Sharp pocket computers when I was a youngling. I found one at a thrift a couple of years back, haven’t managed to make it do much, not as much as this anyway… https://youtu.be/FclspfSNeq0

      I did have a Casio FX series back in the day though with a whopping 500ish bytes of RAM and spent way too long programming that in it’s BASICese had it playing blackjack, battleships (non graphical) and a couple of other braindead gamelets.

      Do you still have a Sharp? I keep thinking about making an arduino plug in for mine, as sort of a co-processor, or maybe really the sharp becomes just a one line serial terminal. However, anything I think of for that I end up at “it would be better with a Palm III” which I have a couple of, or goes right up to, well it could be done with a phone app and look someone did one already … … …

      1. That wasn’t on my Christmas wish list. I did get a Verbot later. Most of my LOGO programming was on a Commodore PET, program called Kid Stuff. Then Turtle Graphic on C64 a few years later.

    1. I do remember typing in the hex dump that appeared in a magazine that was used for patching Applesoft BASIC — the patch added turtle graphic commands to the interpreter. Pretty nifty bit of code.
      And of course, if you limit yourself to 90-degree turns, then there was Karel ( https://en.wikipedia.org/wiki/Karel_%28programming_language%29 ).
      Nowadays it appears Python is occupying the spot that BASIC once had, and Scratch is taken up the spot of LOGO.

    1. Back in ’81~’82 in high school I used TRS-80 Model 1 w/ Level II BASIC and the enhanced BASIC (aka Level III) with TRS-DOS. Moving from TRS-80 BASIC to BASIC/BASICA/GW-BASIC on the PC was pretty simple due to high degree of similarity between them.

  2. My first computer was a ZX-81 kit, followed by a C-64. Finally a PC clone with GW-Basic. So of course I learned basic.

    When I took Differential Equations, we were given a problem to solve using the Euler method.Everyone one else used the Cc lab and wrote their program in Fortran. I used Basic. It took an hour to run at .001 increments, so I added a periodic beep command to let me know it was running and not locked up.

    Later, when working for the State Police in the communications division, I found our IFR-1200 service monitors had a serial port, and wrote programs to automate our bench work It ran on a Zenith Supersport XT Laptop).

    Once they ditched line numbers, I got lost.

  3. Look for Liberty BASIC/Run BASIC. I used Run BASIC many years ago to make a web application from an old, old CBASIC accounting application. It worked really well then. I don’t know if it been kept current.

  4. Y 4 people pick on BASIC? Interpret BASIC was on just about every home/personal computer in ancient times and probably would kill sales if it werent. Was the stepping stone for many programmers. Is cool that Google made another gateway that it might get some people to join in. As a fan of Borland products I feel compelled to add Turbo BASIC mention. Thanks for finding. Lasagna code. Spaghetti code is for beginners.

      1. Forth is not very spoken language like and maths implemented weren’t so liked. Reverse Polish Notation not loved by many and quite often poorly documented libraries and functions took Forth secluded to hardware tech types. Probably the closest to an object orientated language at the time. Notice that I avoided using Forth terminology? Forth is still very usable in particular to small architectures and is ‘alive’ and well.

  5. ” the Basic program is compiled into JavaScript on page load”. Javascipt is interpreted and not compiled which makes any scripting language have poor performance not just BASIC javascript is not an efficient language either.

  6. Great! As a BASIC programmer from the 1980s I excitedly clicked on the link. …and as an 1980s programmer, I have no idea how to actually RUN the example BASIC programs (packaged into HTML files)…. : (

    1. I don’t think it takes much – what you want to first do is download the git repo from https://github.com/google/wwwbasic (it wasn’t clear if you’d done this). Unzip it somewhere, then just use your browser to open up one of the html files in the /examples folder.

      They run fine in a browser without needing a web server (though if you wanted to play around with using a web server to host the files, you could use something like the python testing web server – see https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server).

      Hope that helps!

      /also an 80’s BASIC programmer – today I’m employed as a nodejs/javascript SPA developer (among a ton of other languages I know – but my heart will always have a place for BASIC in it)…

  7. G’day,

    In case anybody is interested in this for the giggles, I’ve embedded wwwbasic.js (and am in the process of tweaking my fork of it) in TiddlyWiki to create BASIC Anywhere Machine, a single html-file (as is TiddlyWiki) that provides an IDE and programming tools for coding and running BASIC programs online/offline and anywhere (the only requirement is a web browser.)

    Carry it around on a USB stick for hobby-programming, learning/practicing fundamental programming concepts, experimenting with both BASIC and enhancements to programs with native TiddlyWiki goodness.

    Give it a spin here: https://cjveniot.neocities.org/TW_BasicIDE.html
    Project website: https://sites.google.com/view/basicanywheremachine

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.