logoalt Hacker News

kibwen10/01/20241 replyview on HN

It's a bit odd to say these programs are comparable when the Cobol version isn't handling errors whereas the Rust program is (by panicking, but that's better than the silently wrong behavior of the Cobol one). Here's a runnable version of the above Cobol program (adding the necessary boilerplate); note that it prints "even" for an input of `abc` and "odd" for an input of `12`:

    identification division.
        program-id.
            even-or-odd.
    data division.
        working-storage section.
            01 num pic 9.
            01 result pic x(4).
    procedure division.
        display 'Enter number: '
    
        accept num
    
        if function mod(num, 2) = 0
            move 'even' to result
        else
            move 'odd' to result
        end-if
    
        display 'The number: ', result
    stop run.
It's peculiar to call out Rust's syntax specifically when, like most other languages these days, is mostly C-like (though with a sprinkling of OCaml). And syntax aside, Rust and Cobol have wildly different goals, so "just use Cobol" doesn't suffice to obviate Rust's purpose for existing.

Replies

palisade10/01/2024

Good catch! My cobol is rust-y. :D

I guess my post is getting misread as "just use cobol" when it was more of a XKCD-like reflection; e.g. why did we all do that / keep doing that. We done did Cobol, and Rust. And, one is "dead" but not really and now here we are.

https://xkcd.com/927/