nioh's town

Day 2 of becoming a mainframe programmer: COBOL fundamentals

I actually wrote during the Day 1 about the basics of COBOL, but I forgot to publish it >< Not a problem actually, I was overstimulated and writing absolute shit, so it's cool. Little disclaimer that I learn the things as I write so it will probably be shit. Let's start with the thing that is needed to know about this language.

That language was designed for punch card, our lad is this old. An 80 columns wide punch card to be exact, of course you can't put things everywhere. But just listing where you put all things is boring (I tried, I'm tired), I guess I will talk about that at another moment, probably. If you can't wait you can here. Something a more helpful at the moment (my feeling) and this how a COBOL program is divide. You have divisions, that is subdivided by sections, sections are by paragraphs made of sentences, and sentences are actually statements I think it's the right moment to do a little Hello World (no, the right moment was 30 minutes away at my time, when I started writing, but I ain't rewriting that for third time)

       IDENTIFICATION DIVISION.
       PROGRAM-ID HELLO-WORLD. 
       PROCEDURE DIVISION.
                    DISPLAY "Hello World".
                    STOP RUN.

In this program, that of course display a text. I honestly don't know how to test it because as a write I remember I didn't set up anything to run COBOL program, no experiments today. It's okay. I'll see that later. But what we are sure about is that we can see divisions and sentences. What is fascinating about COBOL is how well you can read program (of course more complex one need more knowledge) and being one of the ugliest, unelegant and boring piece of software you will ever see of your life (Python is out of competition). And it's make sense, because it's a programming language made for businesses, therefore people who work in boring business. And this people do not come from software, they're not nerds who jerk off on hacker culture (like me :3). S

Let's end today by explaining a more, and also I want to start to compare COBOL piece of code with a more modern programming language This may or may not be a good idea, I don't know, we'll see. I'll use C for this, and here is the typical hello world written in C

#include <stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}

The first thing we can note is that it is way less verbose. Someone with no background will likely understand faster the COBOL program than the C one. Second, the program is structured differently and C doesn't need all that bunch of divisions, and if we try to make a tree on how a program in organize in this two language, I think that see will look more like a bruise. Now let me explain how the COBOL program work line by line and how we can actually compare the two together

IDENTIFICATION DIVISION : it's the mandatory part where you have the PROGRAM-ID and some optional metadata. In C we got nothing like that as long as I know, but I know that some languages have this, the first in my head is Pascal PROCEDURE DIVISION : in C it will be an equivalent of the int main() on the case of semantic but in how they work and how the compiler treat that. We'll see another day DISPLAY "Hello World" : equal the printf("Hello World"), not exactly equal yes I KNOW. i'm tired. i'm dumb. be patient STOP RUN. : is similar to return 0; in the fact the mean the end of the program.

Before I finish today I want to a little bit of meta. What on my mind is for thinking that writing about something I know shit was a good idea. And soon I will update my main webstite to make it prettier first but also include some study notes notably about COBOL and all the shit around where you can learn a thing or two without me yapping every line.

Bye