Learning to program without BASIC
While browsing around the net today I ran across the Wikipedia article on BASIC, which led me to David Brin’s September 2006 article blaming lack of a BASIC-like language for why Johnny can’t code:
BASIC used to be on every computer a child touched—but today there’s no easy way for kids to get hooked on programming.
I have a nostalgia for BASIC too, but Brin is way off base here. BASIC was never the reason for us getting hooked on programming, it was the act of programming itself and the uses to which we put it. We learned programming on BASIC in spite of BASIC, not because of it. BASIC was popular for three reasons, and none of them had anything directly to do with BASIC itself.
- It was the only choice.
- To paraphrase Henry Ford, home computer hobbyists could program in any language we wanted, as long as it was BASIC. If you wanted to write software for your computer, you had two choices: learn to program in BASIC, or learn to program in machine code. And I’m talking machine code here, not assembly language. If we wanted fast code, we literally had to look up the opcodes and POKE them into memory. Using BASIC, of course. Later, people would write assemblers in BASIC for some computers, and you could also buy expensive assemblers or compilers for languages like FORTRAN, but BASIC was the only high level language available to most people. We will never return to that level of universality, nor would we want to.
- We had to.
- Computers didn’t come with software that did anything useful other than let you write software yourself to make it do something useful. When we wrote programs in BASIC, we didn’t do it because we wanted to write programs in BASIC. We did it because we wanted our computers to do something useful that they otherwise would not be able to do. That’s why we stuck with it. Did you want to balance your checkbook? You wrote a program for it. Needed a calculator or address book? There was no widget or desk accessory to handle the job. You wanted it, you wrote it yourself. Later, you could buy it from someone else who wrote it, but that someone else was probably only a few months ahead of you, and their software was in BASIC too.
- Other people used it.
- Because it was the only choice, and because we had to, a community built up around BASIC. Local computer group gurus all knew it. It was the only language that they could assume people had available to them. Magazines printed software written in it, so you learned it as you typed in other people’s computer programs. Computer magazines at the time were often little more than page after page of BASIC code to type in. I owned a TRS-80 Model I. That meant I subscribed to Wayne Green’s 80-Microcomputing. In its heyday, it ran over five hundred pages an issue, twelve issues a year.
That was what made BASIC useful to us. We programmed using it, and textbooks used it for samples, because it was the only option at the time. When other options became available, we stopped using BASIC. BASIC didn’t die out because manufacturers stopped including it with computers. Manufacturers stopped including it with computers because nobody—not even kids—wanted to use it once they had better options.
Even if manufacturers were to start including BASIC with every Macintosh, Windows, and Linux computer, nobody would use it. It’s no longer the only choice and it is no longer necessary (or even useful) for creating useful software on our computers. BASIC would still disappear from textbooks as a waste of space.
Brin goes on to complain that scripting languages like Perl are too high-level compared to BASIC, that they “hide the algorithm”:
The “scripting” languages that serve as entry-level tools for today’s aspiring programmers—like Perl and Python—don’t make this experience accessible to students in the same way. BASIC was close enough to the algorithm that you could actually follow the reasoning of the machine as it made choices and followed logical pathways. Repeating this point for emphasis: You could even do it all yourself, following along on paper, for a few iterations, verifying that the dot on the screen was moving by the sheer power of mathematics, alone. Wow! (Indeed, I would love to sit with my son and write “Pong” from scratch. The rule set—the math—is so simple. And he would never see the world the same, no matter how many higher-level languages he then moves on to.)
I don’t even get what he’s saying here. Perl has the same structural commands that BASIC does. You can even use GOTO if you want to. Further, if he’s writing Pong in BASIC, it’s no longer universal. Even that simplistic level of graphics required different code for each machine. And not only can you still follow along on paper “for a few iterations”, some of us still recommend it when we’re teaching PHP or Perl or any of the other modern tools.
But further, BASIC was not easy to follow. It was easier to use than the alternative: machine code or (at best) assembly. Looking at BASIC programs for this article, I was struck by how much it resembles FORTRAN and by how much it resembled alphabet soup. And by how hard it was to determine what a given program actually did. Yes, I cut my teeth on BASIC, and I can still remember DELETE and GOTO. But these programs are not easy to read. I took this short example from the Wikipedia page:
- 10 INPUT "What is your name: "; U$
- 20 PRINT "Hello "; U$
- 30 REM
- 40 INPUT "How many stars do you want: "; N
- 50 S$ = ""
- 60 FOR I = 1 TO N
- 70 S$ = S$ + "*"
- 80 NEXT I
- 90 PRINT S$
- 100 REM
- 110 INPUT "Do you want more stars? "; A$
- 120 IF LEN(A$) = 0 THEN GOTO 110
- 130 A$ = LEFT$(A$, 1)
- 140 IF (A$ = "Y") OR (A$ = "y") THEN GOTO 40
- 150 PRINT "Goodbye ";
- 160 FOR I = 1 TO 200
- 170 PRINT U$; " ";
- 180 NEXT I
- 190 PRINT
Is that really easier to follow than this example in Python?
[toggle code]
- #ask them how many stars they want to see
- #then show them how many stars they asked for
-
def showstars():
- starcount = raw_input("How many stars do you want? ")
- starcount = int(starcount)
- stars = ""
-
for counter in range(starcount):
- stars = stars + "*"
- print stars
- #ask them if they want to see more stars
-
def morestars():
- wantmore = ""
-
while not wantmore:
- wantmore = raw_input("Do you want more stars? ")
-
if wantmore.lower()[:1] == "y":
- return True
-
else:
- return False
- name = raw_input("What is your name? ")
- print "Hello", name
- showstars()
-
while morestars():
- showstars()
- print "Goodbye",
-
for counter in range(200):
- print name,
I’m pretty sure I got everything right, but not completely sure, because I couldn’t get the BASIC version to run in BWBASIC. It kept dying on line 140. Yeah, BASIC came on every computer, but it was never universal. Each computer had its own flavor (even when the flavors were all written by Microsoft). Even simple BASIC programs weren’t guaranteed portability. That’s part of why I subscribed to a TRS-80 computer magazine and not some universal computer magazine.
What is today’s BASIC?
Today there are a whole lot of languages that can take the place of BASIC’s functionality without inheriting its drawbacks. We no longer have to program in BASIC. Mac OS X comes with AppleScript, Java, JavaScript, Perl, PHP, Python, and Ruby built in. If you want to install the free developer’s package, you can also get C, C++, Objective C, AppleScript Studio, and more Java. If you want to download something else, the sky is pretty much the limit for Mac, Linux, and Windows. Every computer with a web browser has JavaScript built in, and all of the major scripting languages are available for download if they aren’t already installed.
And these choices are better and easier to use than BASIC was. Recursion and subroutines no longer drain CPU time and RAM: we have both to spare. Just about every language in the list even supports objects, something that CPU killers in the eighties like PL/I never even dreamed of. Some of the scripting languages can even be used to create cross-platform scripts.
Since there are a lot of choices, you can look for languages that help you do something useful and that have a community behind them. Finding a community isn’t difficult. With the Internet, even the crappiest scripting language or programming language has a community larger than anything we could have tapped into back in 1982. So the important criteria is, does this language do something useful for you? Does it do something that will make you want to stick with it after you start learning it?
If you don’t find the language interesting, and if it doesn’t do something for you, then you won’t likely be able to learn programming with it. We learned programming in BASIC because we could produce useful (at the time) software using BASIC. Whatever language you choose, it should be one that lets you produce something you find useful and interesting. Pointless exercises don’t create a love of programming.
It will also help if the language can provide instant feedback.
- Persistence of Vision
- To my mind, one of the best scripting languages for learning programming today is the Persistence of Vision 3D raytracer. If you think you would enjoy creating surreal or photorealistic images, but can’t draw like Dali or the Hildebrandts, you should check this out. I’ve written a basic tutorial, and have other tutorials on-line, but its claim to fame is a simple scripting language that lets you program 3D imagery. If that appeals to you, this is a great way to learn programming.
- AppleScript
- If there are repetitive tasks you would like your Macintosh to do, AppleScript is a great choice for learning programming. It uses an English-like syntax that has you typing commands such as “tell application "Firefox" to Get URL "http://www.hoboes.com/"”. If you want to make the Finder do something, you can create a script automatically by telling Script Editor to record your actions as you do them. It will record your actions as script steps, which you can then modify as needed. AppleScript is a great way to tie multiple applications together on Mac OS X, or to automate some repetitive task in an application. I use it on GraphicConverter, for instance, to automatically resize album covers. And I use it in iTunes to play a song backwards. Feel like going further? Use AppleScript Studio to write a custom web browser with your own controls and backgrounds. What kid wouldn’t love that?
- Just remember that your AppleScript scripts, unlike the other choices here, will only run on the Macintosh.
- PHP
- If you are already making web pages, but need to add some dynamic content to them, PHP can be a great choice to learn programming. With PHP, you take an already-existing web page and insert PHP code in the location on the page where you want things to change automatically. You can use PHP with most hosting services that charge you money, and you can also use it directly on your computer.
- JavaScript
- If you’re making web pages and want to add some dynamic display to them, JavaScript can be a great choice to learn programming. With JavaScript, the script runs in your browser, or in the browser of the person downloading your web pages, which means that any web page on any host can have JavaScript built into it. Besides building functionality into web browsers, you can also, on Mac OS X, use JavaScript to create Dashboard widgets. Widgets are little more than HTML, CSS, and JavaScript—and you can leave out the CSS and JavaScript while you’re learning the basics. Or, you can (on Mac OS X) download JavaScript OSA and write JavaScript in Script Editor.
- Python: Django or Snakelets
- If you’re the kind of person who can ignore the stuff you don’t understand until such time as you understand it (and if you’re not, BASIC was never useful for you), then you might find Django useful. At least on Mac OS X it is easy to install, and you can create some very useful web models without really understanding Python. As you learn more Python, you can create ever more detailed web sites using it. If you want to dive into Python immediately, Snakelets can get you going with a simple web application server. You can easily use Python, then, to create a simple blog or other web application that you can use and improve. If you’re interested, look at O’Reilly’s Learning Python•. It’s a great tutorial.
- Second Life
- For all Brin’s complaints about “dressing up avatars”, programming avatars can be a whole lot of fun. I used to do it with MOO, but that was text-only. Today’s budding programmers will find the scripting languages built in to on-line worlds such as Second Life more interesting and more useful—and more likely to keep them programming than pointless exercises.
- Perl
- If you desperately need something BASIC-like, Perl will do you well. You can program in a very BASIC-like manner if you wish; you can also conceptualize your programs in different ways: line-by-line, as objects, or as a text sieve. Take a look at my own Perls Before Swine for a simple tutorial. However, while I find Perl very useful, I don’t necessarily recommend it for beginners. It can be as hard to understand and follow as BASIC was.
What isn’t today’s BASIC?
- A language designed only for learning is not today’s BASIC.
- A language that pretends to emulate how the computer works by jettisoning basic programming concepts is not today’s BASIC.
- A language that artificially holds back its users by requiring them to program in arbitrarily tiny steps for no apparent reason is not today’s BASIC.
- A language that ties itself to what textbook writers thought was current years after it wasn’t, isn’t today’s BASIC.
We’ll never be able to go back to the world where everyone used BASIC—or any single programming language—and we wouldn’t want to. That doesn’t mean we don’t have universally-available languages. JavaScript is available on any computer with a web browser; and Perl and Python are available pretty much on any computer either through a download or pre-installed. We don’t need a language designed solely for learning, and we never did.
If we create a language that we don’t expect people to use for real software, then it isn’t today’s BASIC. When BASIC was installed on most computers, our expectations were lower: our computers didn’t come with any pre-installed software. The software we could write with BASIC was software that filled a purpose on our computers. If we want a language to “replace” BASIC today, it needs to be a language that people want to use to make useful software.
If programming snippets disappear from textbooks, it isn’t going to be because of the lack of a universal language. It will be because of a fear of letting kids know that they can run their own software; programming requires free-time play. More and more, that is being discouraged. Give kids free time, and an unrestricted computer to use it on, and some of them will use it to play around with programming.
- When I was seventeen
- It was a very good year.
- It was a very good year for GOSUB routines
- and POKE and PEEK soup.
- Our GOTOs would loop
- and CLS cleared the screen
- When I was seventeen.
- When I was twenty-one
- It was a very good year.
- It was a very good year for HyperCard stacks
- that kept my addresses stored.
- ’til XCMDs corrupted my fork,
- and events came undone
- When I was twenty-one.
- When I was thirty-five
- It was a very good year.
- It was a very good year for HTML
- and Perl CGIs.
- Thought I’d print ’til I died.
- Then PHP arrived.
- When I was thirty-five.
- But now my DEFs grow short.
- I’m in the Python of my year
- and now I write my scripts as packages
- in a file-based scope
- from local to import
- It traces sweet and clear.
- It is a very good year.
- 80-Micro Magazine
- Covers from many issues of 80 Micro, the TRS-80 computer magazine.
- Creative Computing Magazine archive
- “Full text of 35 issues” from the Classic Computer Magazine Archive.
- Simple Photorealism using Persistence of Vision
- Simple photorealism for people who can’t draw. This tutorial guides you through using the free Persistence of Vision ray-tracer. You’ll create a planet, with rings and an orbiting moon set against a starry background.
- Why Johnny can’t code
- “BASIC used to be on every computer a child touched—but today there’s no easy way for kids to get hooked on programming.”
- BASIC programming language at Wikipedia
- “Most programming languages required more memory (and/or disk space) than were available on the small computers most users could afford. With the slow memory access that tapes provided and the lack of suitable text editors, a language like BASIC which could satisfy these constraints was attractive.”
- PL/I at Wikipedia
- “Typically a PL/I compiler was two to four times as large as comparable Fortran or COBOL compilers, and also that much slower. This was a considerable drawback in the days of 256K byte mainframes and paying for CPU time by the second, but was often offset by programmer productivity.”
- Rebuttal to David Brin’s “Why Johnny Can’t Code”
- “Kids prefer environments without the artificial limitations on power built into old BASIC interpreters; writing programs in old BASIC dialects doesn’t get you any closer to producing something your friends will mistake for store-bought software when they see it.”
- POV-Ray
- POV-Ray is a ray-tracing program for Macintosh, Unix, DOS, and Windows. It is very powerful, full-featured, reliable, and free. It also uses a “programmer-style” interface rather than a graphical one. The tutorial that comes with it is well-written, so it’s worth a look .Persistence of Vision is very useful for those of us who like to automate our image creation. It uses a simple scripting language to build up complex 3-dimensional imagery.
- Persistence of Text
- A series of useful Persistence of Vision tutorials, starting with the very basics of simple object creation and progressing to automation and the usefulness of math.
- Create a web browser in AppleScript Studio
- AppleScript Studio is a powerful means of putting a graphic user interface onto AppleScript applications. Interface Builder lets us use any of the simple and complex controls that any other application can use.
- Developing Dashboard Widgets
- “At its simplest, a Widget is simply a web page that is displayed in the Dashboard rather than in a browser, such as Safari.”
- JavaScript OSA
- “JavaScript OSA is a port of the Mozilla JavaScript scripting system to the Macintosh in the form of a OSA (Open Scripting Architecture) component. You can use JavaScript OSA as a scripting language in any Macintosh application supporting OSA languages, such as the Script Editor included with the MacOS or our own Script Debugger product.”
- goto for Python
- “The ‘goto’ and ‘comefrom’ keywords add flexibility to Python’s control flow mechanisms, and allow Python programmers to use many common control flow idioms that were previously denied to them. Some examples are given below.”
- Django
- “Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.” Oh, the sweet smell of pragmatism.
- Snakelets
- “Snakelets is a very simple-to-use Python web application server. It provides a threaded web server, Ypages (Python HTML template language) and Snakelets: code-centric page request handlers. Snakelet’s focus is to make the creation of dynamic web sites as quick and easy as possible.”
- Learning Python•
- This book balances its primary purpose as a tutorial with its long-term use as a reference for programmers new to the Python language. I found it very useful when learning Python.
- Quick & dirty Snakelets “blog”
- This “No Second Chances” blog engine was fun to write during spare time at ETech 2007. Snakelets appears to be a useful Python webapp server if you need a webapp server immediately.
- Using the Linden Script Language
- “SecondLife includes a facility for defining scripts within existing objects.”
- Getting started with LSL
- “Scripts can make an object move, listen, talk, operate as a vehicle or weapon, change color, size or shape. A script can make an object listen to your words as well as talk back to you, scripts even let objects talk to each other.”
- Perls Before Swine
- A basic Perl tutorial covering reading files, filtering files, importing into SQL databases, and displaying on the web.
- Internet and Programming Tutorials
- Internet and Programming Tutorials ranging from HTML, Javascript, and AppleScript, to Evaluating Information on the Net and Writing Non-Gendered Instructions.
More BASIC
- Simple game menu for the Color Computer 2 with CoCoSDC
- This simple menu provides one screen for cartridges saved in the CoCoSDC’s flash ROM, and any number of screens for your favorite games for your friends to play.
- BASIC tokenization examined
- Why do old BASIC programs have strange characters in their .BAS files? Why do they look like they’re compiled code?
- Read BASIC out loud
- Reading BASIC out loud is a great tool for verifying that what you’ve typed in from an old-school magazine or book is correct.
- Convert PCBASIC code to TRS-80 Extended Color BASIC
- If you have a book of code written in PCBASIC, it usually isn’t hard to convert it to other Microsoft BASICs, such as on the TRS-80 Color Computers.
- SuperBASIC for the TRS-80 Color Computer
- Make BASIC Fun Again. Use loops, switches, and subroutines while writing Extended Color BASIC code for the Radio Shack Color Computer.
- Six more pages with the topic BASIC, and other related pages
More free-time play
- Childish things: the decline of toys and the fall of man
- The old admonishment to put away childish things misses, in a very important sense, a critical point: we can never put away childish things. The way we interact with toys as children is how we interact with life as adults. If your toys have not taught you to sift evidence, weigh risks, and make decisions, the world becomes a very frightening place.
- What children don’t do, adults don’t know
- What children learn, the adult they become understands better.
- Lost children
- “No one was able to reach us all day.”
- The basement was my university
- Free play is how children become scientists. It inspires creativity, which can be both dangerous and rewarding, often at the same time.
- Young chemists under the law
- When chemistry sets are outlawed, only outlaws will know chemistry.
More get off my lawn
- What children don’t do, adults don’t know
- What children learn, the adult they become understands better.
More programming for all
- 42 Astoundingly Useful Scripts and Automations for the Macintosh
- MacOS uses Perl, Python, AppleScript, and Automator and you can write scripts in all of these. Build a talking alarm. Roll dice. Preflight your social media comments. Play music and create ASCII art. Get your retro on and bring your Macintosh into the world of tomorrow with 42 Astoundingly Useful Scripts and Automations for the Macintosh!
- Internet and Programming Tutorials
- Internet and Programming Tutorials ranging from HTML, Javascript, and AppleScript, to Evaluating Information on the Net and Writing Non-Gendered Instructions.
- Our Cybernetic Future 1972: Man and Machine
- In 1972, John G. Kemeny envisioned a future where man and computer engaged in a two-way dialogue. It was a future where individual citizens and consumers were neither slaves nor resources to be mined.
- No premature optimization
- Don’t optimize code before it needs optimization or you’re likely to create unoptimized code.
- Why should everyone learn to program?
- Anything that mystifies programming is wrong.
- Two more pages with the topic programming for all, and other related pages
More technology policy
- Why should everyone learn to program?
- Anything that mystifies programming is wrong.
- Macs still easier to use?
- Twenty years down, does buying a Macintosh still save help desk time and user trouble? According to IBM, it does.
- Copyright reform: Republican principles in action?
- Their initial copyright policy brief was a brilliant example of how Republicans could tie small government and freedom to actual, concrete policy changes that will help the average person—while at the same time cutting the rug from under their traditional anti-freedom enemies. It was far too smart to last.
- Health care reform: walking into quicksand
- The first step, when you walk into quicksand, is to walk back out. Health providers today are in the business of dealing with human resources departments and government agencies. Their customers are bureaucrats. Their best innovations will be in the fields of paperwork and red tape. If we want their innovations to be health care innovations, their customers need to be their patients.
- All roads lead up
- Whatever happened to programming? It became more interesting.
- 13 more pages with the topic technology policy, and other related pages
Following the Brin article referenced above a community of us on-line have tried to create an open-source BASIC that could be a spark for new programmers. Check out the language at http://www.basic256.org and a free ebook to learn to program in the language at http://www.basicbook.org
Jim Reneau at 8:32 p.m. March 8th, 2011
4XBLe