↑ Software Insights ↑

GEONius.com
19-Sep-2022
 E-mail 

Trains and Programming!
What's not to love?


[Night train]

A freight train passing through College Park, heading north from the former Calvert Road crossing towards Baltimore on the double-track mainline of the Baltimore & Ohio Railroad in the early 1970s. On the right is a siding with a boxcar; I was probably leaning against it or another car to take this available light photograph at a slow shutter speed and with a wide-open aperture. A single track, not seen and unused by then, branched off the siding and curved around up to the power plant at the University of Maryland. (Not completely unused; occasionally the track hosted a couple of freight or railway maintenance cars, but coal and freight no longer traveled along the rest of the heavily overgrown rails up to the power plant. Also see this forum discussion of the power plant spur, with thumbnail pictures from the 1960s; paid membership is required to view the full-size images.)

On the opposite side of the tracks to the left, also unseen, is College Park Airport. From M-NCPPC's history of the airport, I was interested to learn that the numerous, abandoned, overgrown home foundations in the woods between College Park and Riverdale, known to us kids simply as "airco", were apparently where ERCO employees lived in the late 1930s through the late 1940s; I don't know why the development was razed. (Wikipedia: Baltimore & Ohio Railroad, Washington-Baltimore Main Line, College Park Airport.)


Wow, two hobbies of mine put together to describe a style of programming I've used for decades: Railway Oriented Programming! Early on in my career, I got annoyed with programs that avoided gotos by using deeply nested IF-THEN-ELSE blocks:

    Perform Step1
    if (successful) then
        Perform Step2
        if (successful) then
            Perform Step3
            if (successful) then
                ... etc., etc. ...
            else
                ... error processing ...
            endif
        else
            ... error processing ...
        endif
    else
        ... error processing ...
    endif

(If I tilt my head to the right, the code above kind of looks like a small mountain and I'm reminded of the song, "On Top Of Spaghetti". Okay, that's a weak attempt at humor by juxtaposing goto-riddled spaghetti code with a goto-less pile of spaghetti!)

And, of course, there were the programmers who used tabs for indentation, so the code quickly shot off the right side of the terminal screen. At the time, in the early 1980s, we were using VAX/VMS FORTRAN-77 for building a NASA image processing ground system, but deeply nested IF-THEN-ELSE blocks have been the bane of my existence in lots of languages. In response, I adopted what I would now call a "bail out on error" approach that gives a straightforward, line-of-processing structure to code:

    Perform Step1
    if (unsuccessful) then
        ... report error and return or goto cleanup processing ...
    endif

    Perform Step2
    if (unsuccessful) then
        ... report error and return or goto cleanup processing ...
    endif

    Perform Step3
    if (unsuccessful) then
        ... report error and return or goto cleanup processing ...
    endif

    ... etc., etc. ...

Not an earth-shattering concept, but it results in much cleaner code and, as an added bonus, allows for neater block comments before each step. And now the idea has a name—railway-oriented programming—and a visual scheme:

[Railway switches]

If a processing step is unsuccessful, execution is shunted off onto the error "siding". In the article linked above, scottw digs into F# and functional programming to provide an implementation with more bells and whistles. While this was interesting, I don't expect it to be of much practical use to the larger population of non-functional programmers (no pun intended). In one satellite control center we built, the spacecraft engineers specified the derived-parameter equations in a variant of Scheme. (The semantics of the standard repertoire of Scheme functions were changed to take into account whether telemetry points were fresh or stale.) Knowing LISP and having read R4RS a few years before, I was the only one who recognized it as Scheme. I wrote a Scheme program (using Guile with my own CORBA extensions) to load, rewrite, and calculate the 800+ equations for incoming telemetry; my manager blew a gasket when he discovered I had written the program in Scheme, a language no one knew, etc., etc.

In short, considering LISP is over 50 years old, I don't foresee functional programming taking the world by storm and I'd just be happy if people adopted my basic approach in more commonly used languages. (Yes, in languages that support them, exceptions and TRY-CATCH blocks supposedly offer a "more structured" form of this method than the simplistic, well-defined RETURNs and GOTOs of my old FORTRAN code.) Anyway, hurrah for trains and model railroading! Perhaps someone can work out a programming analog of John Allen's Timesaver layout! (See Shunting Puzzles.)


Alex Measday  /  E-mail