Funny because it’s (often) true.
(You might also want to check out this post of mine from 2018.)
Funny because it’s (often) true.
(You might also want to check out this post of mine from 2018.)
It’s been an age since I last played with COBOL. The last time I got to noodle with it was on a terminal in the math building at my alma mater, Queen’s University. The terminal was hooked up to a large time-sharing system running software that couldn’t be run on my computer at the time — a 640K PC-XT made by Ogivar, which was once the top PC manufacturer in Canada — but could probably be handled by even the bottom-of-the-line laptop at Best Buy running a copy of Ubuntu Linux.
I wrote my first COBOL program in a long time today: Stupid Interest Calculator. It’s not unlike an old starter assignment from an “Intro to COBOL” course that a university in the late ’70s and early ’80s would put on the curriculum.
****************************************************************** * * Stupid Interest Calculator * ========================== * * A sample COBOL app to demonstrate the programming language * and make me doubt that I’m living in the 21st century. * ****************************************************************** IDENTIFICATION DIVISION. PROGRAM-ID. STUPID-INTEREST-CALCULATOR. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. * In COBOL, you declare variables in the WORKING-STORAGE section. * Let’s declare a string variable for the user’s name. * The string will be 20 characters in size. 77 USER-NAME PIC A(20). * Simple one-character throwaway string variable that we’ll use * jusr to allow the user to press ENTER to end program. 77 ENTER-KEY PIC A(1). * The standard input variables for calculating interest. * The principal will be a 6-digit whole number, while * the interest rate and years will be 2-digit whole numbers. 77 PRINCIPAL PIC 9(6). 77 INTEREST-RATE PIC 9(2). 77 YEARS PIC 9(2). * And finally, variables to hold the results. Both will be * 5-figure numbers with 2 decimal places. 77 SIMPLE-INTEREST PIC 9(5).99. 77 COMPOUND-INTEREST PIC 9(5).99. PROCEDURE DIVISION. * Actual code goes here! MAIN-PROCEDURE. PERFORM GET-NAME PERFORM GET-LOAN-INFO PERFORM CALCULATE-INTEREST PERFORM SHOW-RESULTS GOBACK. * Get the user’s name, just to demonstrate getting a string * value via keyboard input and storing it in a variable. GET-NAME. DISPLAY "Welcome to Bank of Murica!" DISPLAY "What's your name?" ACCEPT USER-NAME DISPLAY "Hello, " USER-NAME "!". * Get the necessary info to perform an interest calculation. GET-LOAN-INFO. DISPLAY "What is the principal of your loan?" ACCEPT PRINCIPAL DISPLAY "What is the interest rate (in %)" ACCEPT INTEREST-RATE DISPLAY "How many years will you need to pay off the loan?" ACCEPT YEARS. * Do what who-knows-how-many lines of COBOL have been * doing for decades, and for about 95% of all ATM transactions. CALCULATE-INTEREST. COMPUTE SIMPLE-INTEREST = PRINCIPAL + ((PRINCIPAL * YEARS * INTEREST-RATE) / 100) - PRINCIPAL COMPUTE COMPOUND-INTEREST = PRINCIPAL * (1 + (INTEREST-RATE / 100)) ** YEARS - PRINCIPAL. SHOW-RESULTS. DISPLAY "Here’s what you'll have to pay back." DISPLAY "With simple interest: " SIMPLE-INTEREST DISPLAY "With compound interest: " COMPOUND-INTEREST DISPLAY " " DISPLAY "Press ENTER to end." ACCEPT ENTER-KEY. * Yes, this needs to be here, and the name of the program * must match the name specified in the PROGRAM-ID line * at the start of the program, or COBOL will throw a hissy fit. END PROGRAM STUPID-INTEREST-CALCULATOR.
Just look at that beast. It’s got all the marks of a programming language that came about in the era of punch cards, teletype terminals, and all the other accoutrements of computing in the Mad Men era. Note the way variables are defined, procedures without parameters or local variables, ALL-CAPS, and clunky keywords like PERFORM
to call subroutines and COMPUTE
to assign the result of a calculation to a variable.
Here’s the output from a sample run:
Welcome to Bank of Murica! What's your name? Joey Hello, Joey ! What is the principal of your loan? 10000 What is the interest rate (in %) 18 How many years will you need to pay off the loan? 5 Here’s what you'll have to pay back. With simple interest: 09000.00 With compound interest: 12877.57 Press ENTER to end.
I’ll go over this app in more detail in an upcoming post. In the meantime, if curiosity or boredom got the better of you and you followed the instructions in an earlier post of mine and downloaded GnuCobol and OpenCobolIDE for macOS, you can either enter the code above or download the file and take it for a spin (1KB source code file, zipped).
Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? Someone who can pick up COBOL well enough to write useful articles about it on short notice? The first step in finding this person is to check out my LinkedIn profile.
Don’t forget that today, Thursday, April 16, 2020, is the last day that you can get Apress’ Beginning COBOL for Programmers at a discount! Use the coupon code SPRING20A when checking out to get $20 off orders $40 and above. That knocks down the price to $29.99 — but only for today.
Every time ancient banking and government software that’s still in use on “big iron” runs headlong into a problem it was never meant to handle, from Y2K to the COVID-19 stimulus check program, COBOL returns to the spotlight. Here are some recent news articles featuring the language. Most of these have been published in the last seven days:
There’s a fine line between genius and madness, and Cloudflare are riding that line by making it so that you can code Cloudflare workers in COBOL! They have a number of simple examples posted, including a Rock, Paper, Scissors web applet written in COBOL (pictured in the screenshot above).
It looks as though they’re using GnuCobol to compile COBOL code into C, and then compiling that C into WebAssembly. I like to refer to this sort of cobbling as “the Flintstones-Jetsons approach”.
If you’re on a Mac and want to dive into COBOL coding, don’t forget that I have a quick and dirty to installing a COBOL compiler and IDE on macOS. If you’ve already got Homebrew and Python 3 installed, you can probably go through the process in about a minute.
Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? Someone who can pick up COBOL well enough to write useful articles about it on short notice? The first step in finding this person is to check out my LinkedIn profile.
In an earlier post, I played around with an online COBOL compiler. Seeing as I’m a COVID-19 unemployment statistic and there’s a call for COBOL developers to help shore up ancient programs that are supposed to be issuing relief checks, I’ve decided to devote a little more time next week (this week, I have to finish revising a book) to playing with the ancient programming language. I’ll write about my experiences here, and I’ll also post some videos on YouTube.
If you want to try your hand at COBOL on the Mac, you’re in luck: it’s a lot easier than I expected it would be!
COBOL isn’t used much outside enterprise environments, which means that COBOL compilers and IDEs are sold at enterprise prices. If you’re an individual programmer without the backing of a company with a budget to pay for developer tools, your only real option is GnuCOBOL.
On macOS, the simplest way to install GnuCOBOL is to use Homebrew.
If Homebrew isn’t already installed on your system (and seriously, you should have it if you’re using your Mac as a development machine), open a terminal window and enter this to install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
If Homebrew is installed on your system, first make sure that it’s up to date by using this command in a terminal window:
brew update
Then install GnuCOBOL by entering the following:
brew install gnu-cobol
Once that’s done, GnuCOBOL should be on your system under the name cobc
. You can confirm that it’s on your system with the following command…
cobc -v
…which should result in a message like this:
cobc (GnuCOBOL) 2.2.0
Built Aug 20 2018 15:48:14 Packaged Sep 06 2017 18:48:43 UTC
C version "4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.43.1)"
loading standard configuration file 'default.conf'
cobc: error: no input files
Unless you’ve got some way to configure your text editor to deal with the language’s quirks, you really want to use an IDE when coding in COBOL. Once again, an open source project comes to the rescue: OpenCobolIDE.
OpenCobolIDE relies on Python 3, so make sure you’ve installed Python 3 before installing OpenCobolIDE. I installed it on my computer by installing the Python 3 version of Anaconda Individual Edition.
If Python 3 is already on your system, you have a couple of options for installing OpenCobolIDE:
I strongly recommend going with option 1. OpenCobolIDE is no longer maintained, so you might as well go with the latest version, which you can only get by installing it using Homebrew. Version 4.7.6 has a couple of key additional features that you’ll find handy, including:
-W
and -Wall
— and hey, warning flags are useful!To install OpenCobolIDE using the Python 3 package installer, pip3, enter the following in a terminal window:
pip3 install OpenCobolIDE --upgrade
To launch OpenCobolIDE, enter this:
OpenCobolIDE
You’ll be greeted with this window:
Tap New file. You’ll see this:
For Template, select Program, enter the name and location for your program file, and tap OK.
You should see this:
Don’t mistake those red vertical lines for glitches. They’re column guides. COBOL is from the days of punched cards, and is one of those programming languages that’s really fussy about columns:
There aren’t many current books on COBOL out there. Apress’ Beginning COBOL for Programmers is probably the best of the bunch, and unlike many old COBOL books, makes sense to developers with a solid grounding in modern programming languages.
The ebook is available for US$49.99, but if you use the coupon code SPRING20A by the end of Thursday, April 16, you can get a $20 discount, reducing the price to $29.99. If you want the book for this price, take action before it’s too late!
Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? Someone who can pick up COBOL well enough to write useful articles about it on short notice? The first step in finding this person is to check out my LinkedIn profile.
Want to experience the clunkiness that is COBOL? CodingGround’s online compiler awaits!
Wondering what the title of this article is all about? Start here:
I may be out of a job, but from now until the end of next week, I do have work: finishing the revision of iOS Apprentice, Eighth Edition, a book that teaches you how to write iPhone and iPad apps, even if you have no prior programming experience.
In its 1200+ pages, the book walks you through building 4 apps:
iOS Apprentice is a special book for me, because I learned iOS programming back in 2012 (when the iPhone 4S was the newest model) from an earlier edition. The book launched me into the world of iPhone development, and as a result of that, into the world of mobile and IoT development in general. Since then, I’ve always wanted to repay the book by writing a later edition. Last year, I got my chance when I interviewed to become one of its authors and was chosen.
For a taste of what iOS Apprentice is like, check out this video series below, which is based on the first 8 chapters of the book, which I wrote. It shows you how to get started as an iOS developer by walking you through the process of making Bullseye, a simple game:
You can get your hands on this book in a couple of ways. If you want the paperback edition, you can get it at Amazon.com…
…and if you want the ebook edition (which comes with free updates, including the one I’m working on right now), you can get it at the RayWenderlich.com site:
I’m also bringing back the Tampa iOS Meetup in the next couple of weeks, where I’ll use the programming exercises in iOS Apprentice as a starting point. If you’ve been meaning to learn iOS programming, keep an eye on Tampa iOS Meetup — it’s coming back!
Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? The first step in finding this person is to check out my LinkedIn profile.
Now that I’m looking for my next gig (my last one was a victim of COVID-19), it’s time to revive this video that New Relic released a few years back to promote their application monitoring service.
Titled We Love Developers, it features some of the brightest lights in the industry:
At the end of the video, they wanted to use the image of a more “everyman” developer to represent you, their customer. Guessed who they picked:
My photographer friend Adam P. W. Smith (my old business partner; together, we were datapanik software systems and we worked on some pretty interesting projects back in the late ‘90s) took the picture back in August when I was visiting him in Vancouver. I’d arrived a day early for the HackVAN hackathon and was sitting in his kitchen getting some work done when he decided to get a couple of shots. He poured me a glass of scotch, set it on my accordion, which I’d set down on the chair beside me, and started taking pictures.
Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? The first step in finding this person is to check out my LinkedIn profile.