Chad Perrin: SOB

6 February 2009

Let them use let.

Filed under: Geek — apotheon @ 02:04

Sterling wrote an introduction to functional programming for [GAS]. It’s a pretty good introduction — but don’t expect it to make you a functional programming expert. It’s called an “introduction” for a reason.

I’ve previously written about how functional programming techniques can improve software security at TechRepublic, in its Weblog about IT Security.

An interesting, kind of throw-away bit about imperative variable assignment syntax at the beginning of Sterling’s article caught my interest:

Way back in the dark ages when I first started programming in BASIC, the first stumblingblock I encountered on my quest for programmerhood was the statement:

X = X + 1

My High School algebra training screamed out, “That’s an unsolvable equation!” I soon learned that the above is not an equation at all, but rather a command. It’s not a statement of fact, it’s an instruction to alter a fact. This command begins with an implied “LET” (in some BASIC versions, “LET” is even required) and the correct interpretation of the command relies not only on the previous value of X, but also on the fact that the right side is evaluated before the assignment occurs.

(pardon the formatting — I’m using WordPress here)

I’ve had some vague, background unease about the way most imperative programming languages handle assignment and equality comparison ever since I first encountered it, lo these many years ago. I’m not generally one to say a kind word about BASIC (I think it may have actually permanently damaged my brain, though thankfully not too much since I encountered Logo not too long afterward), but back in the “good ol’ days” it did do something more “right” than other imperative languages have tended to do things since:

It used = to mean “equals”, and not as an assignment operator. The actual assignment operator in old-school BASIC was, in effect, actually the keyword let. One would use something like this to assign a value to a variable:

let X = 1

That’s very easily distinguished from the syntax used for comparisons, where actual equality is assumed as the meaning of the = symbol, even if == isn’t used:

if X = 1

Of course, Microsoft has since screwed that all up with VB.NET — now the only really widely used direct descendant of BASIC (unless you count VB 6) — but that’s a separate matter entirely.

Anyway . . . my point is that using = as an actual equation sigil as doG intended, rather than as an assignment operator, and using let to indicate assignment, strikes me as a much clearer and “better” way to do things. Only long tradition in the imperative programming world makes it difficult to use comfortably, these days, much the way that only long tradition in the desktop computing world makes it difficult for many Microsoft-habituated people to get used to using workspaces or tag-groups to best effect rather than a hobbling around on a taskbar crutch in their daily computing environments.

I’ve always liked let in this kind of context (which is also used in more reputedly good languages, such as OCaml and Haskell). I’ve never much liked the kludgey elision of let in most of the mainstream programming world, even though that’s where I’ve spent the vast majority of my programming time.

2 Comments

  1. I agree. Unfortunately, the “let” in BASIC didn’t provide scope like its functional counterpart. But the word “let” at least lets (ha) you know in no uncertain terms that this is an assignment.

    Comment by Sterling Camden — 6 February 2009 @ 02:26

  2. […] Let them use let."Lets do it." — Cole PorterTags: programming assignment imperative functional basic apotheon Tags: 3m, advertising, apotheon, assignment, basic, consulting, del.icio.us, dougkarr, functional, imperative, programming, techrepublic, tools […]

    Pingback by Chipping the web: February 6th -- Chip’s Quips — 7 February 2009 @ 06:02

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

All original content Copyright Chad Perrin: Distributed under the terms of the Open Works License