Every so often I skirt my intern duties to (re)discover something weird and fascinating in the world of software development. If you follow me on Twitter @gaessaki, I’ll let you know when that happens.
© Computerworld 1984 - COBOL’s demise has been predicted since the Middle Ages (aka back in the era of print media.)
One of the first things my boss told me when I joined Microsoft as a technical evangelist was that you quickly grew a thick skin. Well, I’m certain that a decade as an IE evangelist wouldn’t have given me the skin to sustain the abuse hurled at COBOL throughout the years (well, okay… maybe). When Dijkstra himself says “The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence”, it becomes difficult not to afford at least a bit of sympathy for the sturdy and reliable language that once processed your insurance claims and tax returns and maybe secretly still does. COBOL was heavily criticized for having been developed without input from academia and was often derided as assembly language in English. When I asked my friends what they thought about me writing a blog post on COBOL, I was privy to puzzled expressions; kids these days don’t even know what COBOL is! (What do they teach them on the Hacker News?!) Being forgotten is in many ways worse than abhorred. © Scott Adams 1997
Despite this, COBOL is as persistent in large businesses as IE6 is in South Korea. According to a Computerworld survey of IT professionals conducted in 2012, over 50% of organizations represented in the survey claim to still have workloads on COBOL. Seeing as there are no major external actors keeping COBOL afloat, it’s somewhat intriguing to see it carry itself on its own inertia. Pragmatically speaking, I think it’s safe to say that COBOL is still a ‘good’ language. It’s easy for non-programmers to pickup (i.e. business people) and it supposedly excels at batch processing. Many of the criticisms leveraged at it are based off perceptions that are decades old as I would soon find out…
COBOL in Visual Studio 2015
You didn’t expect me to just pontificate on the faults and merits of COBOL and not play with it myself did you? You know when you hear COBOL in Visual Studio you just have to go try it out. I mean, I admit it sounded painful at first, but the prospect of coding like my grandparents would have coded back in the day (well, if they weren’t Basmati rice farmers on the Indian subcontinent) was too enticing.
Micro Focus very recently announced Visual COBOL for Visual Studio 2015. Apparently they’ve been releasing versions of Visual COBOL for years, but COBOL being the humble language that it is, it never received the fanfare that Node.js 4 or C# 6.0 could come to expect. Naturally, my first reaction was to download it and build something fairly simple, like a Reddit client. Well long story short, I spent a long time going nowhere. I know talking about the struggles I came across would probably make a more interesting story then what I ended up doing, but the truth is, there’s not much story to spending several hours binging and trying to figure out what to do.
I had a 6 hour train ride back to Montreal from Toronto coming up so I resolved to make something unambitious during that timeframe. It had to be something that I wouldn’t be afraid to ask my non-programmer friends to build on a general introduction to programming.
COBOLCalc I’d call it. The calculator Euler wish he had (because it’s any calculator at all and not because it’s a worthy calculator.) It would only have a subset of what the most basic calculators these days have, no order of operations, MVVM or even Twitter integration (though certain things like trig functions would have been easier than anything to implement), but given my mini-agile 2 hour sprints, I reckoned it was a reasonable affair.
I opened Visual Studio, went to new project, COBOL, lo and behold, COBOL supports everything from WinForms and WPF to Azure and ASP.NET.
I’m fond of XAML so I went with WPF. I couldn’t believe it, but there it was, a WPF app that with COBOL logic. Let’s poke it to see if it falls apart.
Hmm, so far so good. You can drag controls onto the UI as expected, then double click it to auto-generate event code on the logic page. Sadly this is where my luck had run out. I was an hour into the train ride and I couldn’t get anything to happen code-wise. There was a dearth of resources online for COBOL and the existing resources could only help me print hello world on a mainframe. Eventually, I gave up on searching and brute forced Intellisense until something worked.
COBOL being a peculiar rendition of English actually made this method quite ideal. Out of the first few words that popped up, set was one of them that made sense. Next, the name of my textblock tacoTextBlock came up. I cycled through different punctuation and shortly figured out that :: allowed to access the properties of the UI control. Then I completed the sentence with ‘to “More tacos for everyone!”.
My code still wouldn’t work however and Intellisense kept saying “‘.’ missing”. This made no sense until I realized there were black periods at the end of each phrase, but my Solarized theme’s background obscured them. I was able to rectify the oversight by changing the theme to allow for period highlighting.
No Intellisense errors… let’s see if it compiles.
My workflow was slow and steady for the next few hours and I was able to get a sizeable portion of the code complete. Eventually, I stumbled upon the official Micro Focus Documentation and at least kind of understood what I was writing. A lot of it was really different to what I had found on the web since COBOL had evolved so much from since way back when Grace Hopper was directly working on it. I’ve heard a lot about GOTO Hell, lack of OOP and built in functions, but the latest incarnations of COBOL deal with all these issues to some extent.
By the time I entered Quebec, COBOLCalc was more or less complete. I spent the last minutes trying to fix a bug that wouldn’t let me add together several numbers in one go, but I my train had arrived at the station so I shipped the last build.
COBOLCalc will likely never see production use, but it served its primary goal well, which was to give me a taste of COBOL. Yes, it’s a heavily adulterated form of the COBOL from the 1960s, but it made it palatable. I’ve released the source of COBOLCalc on Github. Hopefully it’ll serve as a good starting point for anyone interested in clawing with COBOL. Feel free to make contributions to make it useful for devs unfamiliar with COBOL. Also as mentioned earlier, you can make web apps using COBOL as well. Check out this brief tutorial to get an idea of how its done.
I’m not sure we’ll ever see the end of COBOL. There might not be many Valley startups hacking with COBOL, but there’s little inertia to wean LOB apps off of it. If anything, we’ll just see more COBOL code plugged into modern infrastructures. Although .NET and COBOL is kind of an appropriate fit, a node.js bridge for COBOL just made its rounds and is now ready for production use. Some things are timeless. For everything else, there’s COBOL and IE6.