Skip to content

Both.org

News, Opinion, Tutorials, and Community for Linux Users and SysAdmins

Primary Menu
  • About Us
  • Computers 101
    • Hardware 101
    • Operating Systems 101
  • End of 10 Events
    • Wake Forest, NC, — 2025-09-20
  • Linux
    • Why I use Linux
    • The real reason we use Linux
  • My Linux Books
    • systemd for Linux SysAdmins
    • Using and Administering Linux – Zero to SysAdmin: 2nd Edition
    • The Linux Philosophy for SysAdmins
    • Linux for Small Business Owners
    • Errata
      • Errata for The Linux Philosophy for SysAdmins
      • Errata for Using and Administering Linux — 1st Edition
      • Errata for Using and Administering Linux — 2nd Edition
  • Open Source Resources
    • What is Open Source?
    • What is Linux?
    • What is Open Source Software?
    • The Open Source Way
  • Write for us
    • Submission and Style guide
    • Advertising statement
  • Downloads
  • Home
  • My first programming language
  • Fun
  • Programming

My first programming language

Apple BASIC was how I first learned how to write my own computer programs.
Jim Hall May 18, 2024 6 minutes read
retro_old_unix_computer
1

Last Updated on May 25, 2024 by David Both

The BASIC programming language turned 60 years old this month. On May 1, 1964, professor John Kemeny with a student ran the first BASIC program on a Dartmouth College computer system. If you don’t know BASIC, the Beginner’s All-purpose Symbolic Instruction Code, it was a simple programming language that made it easy for beginners to write their first computer program.

BASIC became a popular programming language to include in early personal computers. The Commodore PET, TRS-80, and Apple computers (1977) all came with their own versions of BASIC. The IBM PC 5150 (1981) also included a version of BASIC. With BASIC, it was finally possible for everyday computer users to create their own useful and interesting programs.

And because BASIC has turned 60 years old, I’d like to look back and celebrate BASIC as my first programming language.

Apple BASIC

My family bought an Apple II computer, and my brother and I read books to teach ourselves how to write our own BASIC programs. My first programs were pretty simple: math quizzes and puzzles, like a game where the computer picked a random number from 1 to 100 and you had to guess it. BASIC made this easy for me. Its simple syntax and numbered lines gave me a certain flexibility to create programs. As I became more advanced, I learned about graphics programming and created more complex and visually interesting programs like adventure games and simulations.

I can go back to Apple BASIC thanks to an open source Apple II emulator called apple2js by Will Scullin. You can find the source code at apple2js on GitHub, under the MIT license.

Scullin’s Apple II emulator provides the virtual hardware, and you can select different virtual floppy disks using the menu. Booting from the DOS 3.3 Master gives me the same environment I used to create my Apple BASIC programs back in the late 1970s and early 1980s.

Apple provided a very simple environment that immediately put you into a “programmer” mode. You could enter one-line BASIC commands here, such as PRINT "Hello" to print some text, or a one-line instruction like FOR I = 1 TO 21 : PRINT I : NEXT I to print the numbers from 1 to 21. To start a new program, use the NEW command, and to clear all variables from memory, use the CLEAR instruction. The HOME command clears the screen and positions your prompt at the upper-left corner.

Low-resolution graphics

The Apple II had two graphics modes: low resolution and high resolution. The low-resolution mode provided blocky pixels from 0,0 in the upper-left to 39,39 at the lower-right, with a few lines of text at the bottom. You could also select an alternate mode that eliminated the text lines and gave you a few extra rows of graphics.

Let’s explore this graphics mode by writing a simple program to draw a chart. For this sample, we’ll start the graphics at the middle-left of the screen at x=0 and y=20. At each iteration, we’ll generate a random number using RND. This gives a floating point value from 0.0 to 0.999… We’ll move the next pixel “up” or “down” depending on the value of that random number; if it’s less than 0.5, we’ll move it up, otherwise we’ll move it down.

We can describe the functionality using this pseudocode:

y = 20
for x = 0 to 39 {
  plot x,y

  if (rnd<.5) {
    y--
  }
  else {
    y++
  }
}

With that overview of the program, we can enter the corresponding BASIC code into the Apple II:

If we run this program, we’ll see a series of low-resolution pixels that start at 0,20 and move up and down according to the values returned by the random number generator. In this case, the plot stays pretty close to y=20:

It might be interesting to draw a horizontal line across the finished chart, so we can see how much the random fluctuations deviated from the “zero” point. It’s easy to add to a BASIC program by just typing in new lines. Let’s replace the END instruction at line 90 with some extra lines to draw a horizontal line in a different color:

The new chart now shows a horizontal line across the middle of the screen, from 0,20 to 39,20.

High-resolution graphics

Apple BASIC also supported a higher graphics mode at 280,160 resolution, with a few lines of text at the bottom of the screen. As with low resolution graphics, you could also use an alternate mode that used full-screen graphics, and gave you more graphics lines. But let’s use the standard high graphics mode to write a simple program.

Sierpinski’s Triangle is a fun program that demonstrates how you can create a fractal image through successive random values. To generate the triangle, start by defining three points on the screen, and a random x,y starting value. To draw successive pixels, pick a vertex of the triangle, and draw a dot at the midpoint between the last location and the triangle corner. After many iterations, you will see Sierpinski’s Triangle.

Writing a nontrivial BASIC program can be challenging, so I always started by describing the program using a flow chart or by writing it out as words. In this case, we can describe this Sierpinski Triangle algorithm using pseudocode:

x(1) = 0 ; y(1) = 0
x(2) = 279 ; y(2) = 0
x(3) = 140 ; y(3) = 159

xi = random(0 to 279)
yi = random(0 to 159)

for n = 1 to 1000 {
  hplot xi,yi

  i = random(1 to 3)
  xi = int( (xi+x(i)) / 2 )
  yi = int( (yi+y(i)) / 2 )
}

Now we need to enter that program into the Apple BASIC environment:

There’s a lot to enter, but the Apple only shows 25 lines of text at a time, and we’ll need more than that to enter the entire program. Here’s what it looks like when I’m done:

and:

And when we run the program, the Apple will draw Sierpinski’s Triangle to the screen. This takes several minutes on the Apple II, because 4,000 iterations is a lot for a 1MHz processor, but eventually we’ll see this:

Exploring BASIC programming

Apple BASIC was how I first learned how to write my own computer programs. This simple interface and programming syntax made it easy for me to enter, run, and debug programs.

A few years later, my family replaced our Apple II at home with a new IBM Personal Computer PC-5150, running DOS and a new version of BASIC. But it was still BASIC, and I continued to use BASIC until I went to university and learned other programming languages like FORTRAN77 to write data analysis programs and C to write command line utilities. While I prefer more modern programming languages, I still found it fun to rediscover “retro” programming with Apple BASIC using this open source Apple emulator.

Tags: basic Fun Programming

Post navigation

Previous: 3 ways to read files in C
Next: My open source story

Related Stories

command_line_prompt
  • Command Line
  • Linux
  • Programming

Writing a replacement seq command

Jim Hall April 27, 2026
BUSINESS_twoforward
  • Fun
  • LibreOffice

Is there a better Pi Day than March 14?

Jim Hall March 14, 2026
A Stylized image of a Raspberry on a blue background
  • Fun
  • Raspberry Pi

Let’s measure pi with a Raspberry Pi

Jim Hall March 13, 2026

System upgrades this Sunday, May 3

Tools illustrationFedora 44 was released this week and I’ve upgraded all my systems except for the two that directly affect Both.org. I’ll be upgrading the hosts for my server and firewall to Fedora 44 this Sunday afternoon, May 3.

Both.org will be down for most of the afternoon for these upgrades.

Thanks for your patience.

Random Quote

Computers are unreliable; humans are even more unreliable.

— Gilb’s laws of unreliability

Why I’ve Never Used Windows

On February 12 I gave a presentation at the Triangle Linux Users Group (TriLUG) about why I use Linux and why I’ve never used Windows.

Here’s the link to the video: https://www.youtube.com/live/uCK_haOXPFM 

Why there’s no such thing as AI

Last October at All Things Open (ATO) I was interviewed by Jason Hibbits of We Love Open Source. It’s posted in the article “Why today’s AI isn’t intelligent (yet)“.

Technically We Write — Our Partner Site

Our partner site, Technically We Write, has published a number of articles from several contributors to Both.org. Check them out.

Technically We Write is a community of technical writers, technical editors, copyeditors, web content writers, and all other roles in technical communication.

Subscribe to Both.org

To comment on articles, you must have an account.

Send your desired user ID, first and last name, and an email address for login (this must be the same email address used to register) to subscribe@both.org with “Subscribe” as the subject line.

You’ll receive a confirmation of your subscription with your initial password as soon as we are able to process it.

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

License and AI Statements

Both.org aims to publish everything under a Creative Commons Attribution ShareAlike license. Some items may be published under a different license. You are responsible to verify permissions before reusing content from this website.

The opinions expressed are those of the individual authors, not Both.org.

You may not use this content to train AI.

 

Advertising Statement

Both.org does not sell advertising on this website.


Advertising may keep most websites running—but at Both.org, we’re committed to keeping our corner of the web ad-free. Both.org does not sell advertising on the website. Nor do we offer sponsored articles at this time. We’ll update this page if our position on sponsorships changes.

We want to be open about how the website is funded. Both.org is supported entirely by David Both and a few other dedicated individuals.

 

 

Copyright © All rights reserved. | MoreNews by AF themes.