Fortran vs Cobol vs Haskell

There’s nowt like a bit of retro. I have been learning Haskell for about 6 months now, and I am starting to get to grips with monads. Fortran is something I used in the 90’s for my PhD. I used F77 style, though. The Fortran spec from the 90’s was too avant garde for me to worry about. Cobol is something I am just picking up, having spent a few days on it.

I am using gnucobol. As an exercise, I tried to join key fields together on two separate files, and then order the results by percentages.

There was much huffing and puffing involved, but I think I got a got hang of it. Here’s some things I noticed about Cobol: * it’s fairly hackable
* Use of ‘.’ seems a bit arbitrary, but it is critical to the way the code is constructed. Why do I leave off the ‘.’s when I am inside a PERFORM, but not when I am outside it? I guess the compiler works out that you are starting a new statement by the key words that it sees.
* Subsequent to that, I think Cobol could benefit from the notion of a “block”, with delimiters after each “function”. A dot before a word is used to signify a jumpable label. It’s a bit of a mish-mash of syntax.
* PERFORM THRU. Really? Mix that in with the ‘.’s, and it becomes puzzling as to what code you’re actually executing. * control structures are really weird, and seem to almost force gotos.
* can I not have a control mechanism that basically just goes through a file, reading and advancing? Do I really have add my own control structures here?
* seeming endless repetition of file descriptors. It doesn’t support the notion that a file may have the same record structure as another file. This is frustrating in, say, a sort operation, where the temporary workfile will have exactly the same layout as the source data file
* I couldn’t get reporting to work on gnucobol. I believe that it is functioning, but it is possible that particular flag was switched off for the Arch Linux distro
* Sorting seems bugged in gnucobol?? It seems to truncate the record length to 32. I don’t know if it’s a bug, or something I have done wrong.
* Decimals are a bit quirky. For example if I declare a number with a “picture” like 999.99, you can’t do normal decimal arithmetic. It’s OK if you declare it like 999v99, though. Maybe it has to do with the way that memory is laid out internally in memory, or something.
* And talking of decimals, I’m suspecting the arithmetic in gnucobol. This is odd, because Cobol is renowned for getting its decimal arithmetic right. However, the results were a little askance from the results that Haskell produced. I did some calculations by hand, and it does seem that Haskell gets it right where Cobol got it wrong. Hmmm.

So, in the end, I thought Cobol had some interesting ideas, but could do with a bit of tidying up. I almost wonder if you could knock yourself up a Cobol by using a macro processing system like m4.

Fortran, OTOH, I found surprisingly hackable. I was able to interface with the Gnu Scientific Library fairly readily through FGSL. I was then able to sort values without having to roll my own routine.

Both Cobol and Fortran are interesting in that you get the feeling that the layout on the machine is close to the way you write your code.

I learnt an interesting trick with Fortran today. By using the read statement with the iostat parameter, you can gracefully detect end of files. Inside a do loop, just call “if (myiostat /= 0) exit”. You don’t even need labelled jumps. Very neat.

The thing about Haskell is that monads can be a little tricky to reason about.

Anyhoo, I’m too lazy for checking grammar on this blog. That’s me done.

44b0bd758f8ee5c81362923f0d5c8e017c9ddf623925e60c29a4c015b89fbb45

Advertisements

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s