Learning from the Past

Date: 2020-12-18

Contents

' FreeBASIC Hello World:
' ----------------------

 Print "Hello. World."

I work in tech/programming and build complex projects for my job, but in my freetime I like tinkering. For some reason, I veer away from the current fads in programming (even though I encourage them at work) and rather delve into the obscure and aging technologies that are no longer hip.

A lot of times these personal projects don't have a lot of practical value — that is, they won't change the world or build my resumé. But they're interesting to me, and it always surprises me how tinkering sometimes leads to useful connections or knowledge.

There are a lot of great programming languages that have fallen out of favor and aren't as new and shiny. Pascal, Fortran, and BASIC were once king, but there's a generation of devs now who have barely heard of them. The industry has moved on, web development is the way of things, JavaScript runs everything, and the browser is steadily replacing the desktop.

That's okay. It's the way of the world. Every generation reinvents the wheel to some degree. And there's a lot to love about modern programming languages. As someone who uses Node/ES6, Typescript, Python, and C# for work, I can confidently say that modern programming is a wonderland of great tools.

But in an industry driven by the newest shiny thing, it's easy to forget the lessons of the past.

Let's take a minute to consider PowerBASIC, which evolved out of Borland's TurboBASIC. Bob Zale bought the rights when Borland discontinued it, and developed the language and tools until the end of his life in 2012. It's mindblowing to the modern mindset how different PB was (and is) compared to the way things are now.

The entire compiler, includes, documentation, and IDE are less than 10 MB. Yes, megabytes. PB compiles to native code on Windows so compact that there's a #bloat instruction to make your EXE look bulkier (clients were incredulous that anything so small could be providing value). And PB's fast as hell, with fewer footguns compared to programming in C.

Is PowerBASIC as productive as Python or Node? No, probably not. But it's surprising how easy it is to build something interesting, especially since PowerBASIC offers some pretty low-level functionality. I think about how Rust, Nim, and Zig have all stepped up to fill a systems-level niche — but these problems were already solved in the past, and PowerBASIC is a good example of a high-level language that runs like a whisper across the silicon. I'm guessing that it could give these newer languages a run for their money.

Here's an example of a simple Win32 program from Gary Beene's site:

#Compile Exe
#Include "Win32API.inc"

Function PBMain() As Long
    Dim hDlg As Dword, hCtl As Dword
    Dialog New 0, "PowerBASIC",300,300,100,75, %WS_SysMenu,0 To hDlg
    Control Add Button, hDlg, 2, "Cancel", 25, 15, 40, 20
    Dialog Show Modal hDlg Call DlgProc To Result&
End Function

CallBack Function DlgProc() As Long
    If CbMsg = %WM_Command Then Dialog End CbHndl, 0
End Function 

Pascal is another great example of a language that was once very popular and still has a lot to offer. There was a time that Borland's Delphi competed for the RAD development throne, and it got there by embracing Pascal. Pascal, and it's more modern iteration Object Pascal, fill the same niche as C++. The syntax is certainly different, but the concepts are the same. As someone who programs in C and C++, I think Pascal might be simpler to learn. Pascal compiles to native code that runs fast and with a low memory footprint.

Delphi is now owned by Embarcadero, and remains an excellent tool for building traditional desktop applications. A few years ago, Embarcadero started offering a community edition and I recommend giving it a try.

Example from Modern Object Pascal:

{$mode objfpc}{$H+}{$J-} // Just use this line in all modern sources

program MyProgram; // Save this file as myprogram.lpr
begin
  WriteLn('Hello world!');
end.

Fortran is interesting. It's still widely used in scientific circles and for doing cool stuff like parallelizing computation. There are still new versions of the Fortran standard and new compiler development is ongoing. The syntax is a lot different if you're used to a {brackets} language, but the structure makes it easy to read.

Here's an example from Our Coding Club:

! ------------------------------------------------------
! Compute the area of a triangle using Heron's formula
! ------------------------------------------------------

PROGRAM  HeronFormula
   IMPLICIT  NONE

   REAL     :: a, b, c             ! three sides
   REAL     :: s                   ! half of perimeter
   REAL     :: Area                ! triangle area
   LOGICAL  :: Cond_1, Cond_2      ! two logical conditions

   READ(*,*)  a, b, c

   WRITE(*,*)  "a = ", a
   WRITE(*,*)  "b = ", b
   WRITE(*,*)  "c = ", c
   WRITE(*,*)

   Cond_1 = (a > 0.) .AND. (b > 0.) .AND. (c > 0.0)
   Cond_2 = (a + b > c) .AND. (a + c > b) .AND. (b + c > a)
   IF (Cond_1 .AND. Cond_2) THEN
      s    = (a + b + c) / 2.0
      Area = SQRT(s * (s - a) * (s - b) * (s - c))
      WRITE(*,*) "Triangle area = ", Area
   ELSE
      WRITE(*,*) "ERROR: this is not a triangle!"
   END IF

END PROGRAM  HeronFormula

What's really incredible to me about all of these languages is that you can still be quite productive. These languages don't feel crufty or crude; if anything, the opposite is true, they feel surprisingly modern. There's a graceful simplicity to BASIC or Fortran or Pascal. They do more with less, and they are lean and trim, because they were born in an age where every byte counted.

Considering our technical past gives me pause. Many websites now contain more mb of JavaScript than the size of an entire exe built in PowerBASIC. The amount of scaffolding required just to build the JavaScript bundle is staggering (Webpack, Typescript, Babel – all behemoths). We are compiling one high-level language into a more primitive version of the same high-level language, and this is the foundation on which modern software development stands! The irony of a world where JavaScript compiles to a more common form of JavaScript boggles the mind.

Comparing this to the lean, mean native compiled applications of the past, I wonder if we've gone astray. Granted, the browser has opened up opportunities that were only dreams 25 years ago, and web assembly offers to upset the balance, but the current state-of-the-art in (web) application development seems like it could learn a lot from the previous generations of desktop development.

Developers are always going to be restless souls, wanting to find an easier or better way of doing something, and we should never let the past get in the way of the future. However, we should also be thoughtful about the past, otherwise we will be doomed to continually reinvent the wheel.