← Back to context

Comment by antonvs

14 days ago

> I would argue that imperative programming is most natural - it's what everyone gravitates to in the beginning.

Why do you believe this is anything more than an historical accident?

For example, it wasn't what Alonzo Church gravitated to when he invented the lambda calculus in the 1930s, before any programming languages or indeed general-purpose computers existed.

> 99 Bottles of Beer implemented with a loop is intrinsically going to be easier to read than an implementation with tail recursion

First, you don't need to use explicit tail recursion. See e.g. https://99-bottles-of-beer.net/language-haskell-1070.html

Second, this sounds like unfamiliarity, not anything inherent. Why is it "intrinsically easier to read"? For a tail recursive version, the main tail recursive function would look like this in Haskell:

    _99bottles 0 = printVerse 0
    _99bottles n = do
        printVerse n
        _99bottles (n - 1)

In fact, with a bit of experience you might write this as:

    _99bottles 0 = printVerse 0
    _99bottles n = printVerse n >> _99bottles (n - 1)

It's only less easy to read if you're completely unfamiliar with the concepts of pattern matching and recursion. But the same is true of any programming language.

Given the above, what's a "for loop" and why would you need one? Sounds complicated and unnatural.