News for hackers. Stuff that matters.
Re:A Plea for Lean Software (1995) [pdf] by mumblemumble on Wednesday August 05, 2020 @10:23AM (#24061086)
Those sentences form the opening of a rather peculiar paragraph. You don't have to read past the abstract of the seminal paper on functional programming, Backus's Can Programming be Liberated from the Von Neumann Style? to see that the goal isn't to eradicate state, just to tame it. "Unlike von Neumann languages, these systems have semantics loosely coupled to state." (emphasis mine) Loose coupling is not the same thing as elimination.

In the next paragraph, Wirth further indicates that he has chosen to argue against a caricature of functional programming when he suggests that "[Functional programming] probably also considers the nesting of procedures as undesirable." That's another strange thing to insinuate against a programming style that is noted for its use of closures.

(For that matter, where would closures be without state?)

Re:A Plea for Lean Software (1995) [pdf] by dgb23 on Wednesday August 05, 2020 @11:04AM (#24061588)
This is a weird phenomenon. There seems to be two conflicting philosophies in regards to reducing accidental complexity in software.

The "less is more" crowd adheres to avoiding and reducing feature bloat and writes lower level, often efficient, very consistent code that is easy to grok.

And the "correctness by concept" crowd, with many variants thereof. Expressive type systems, functional programming, abstraction and general "higher order-ness" are dominating themes here.

Languages and paradigms often land on the spectrum of these two. I wonder if these concepts can be married in some way and what we would have to give up to do so.

Re:A Plea for Lean Software (1995) [pdf] by mumblemumble on Wednesday August 05, 2020 @12:38PM (#24062745)
I'm not sure that they're all that different in the first place. At the one "less is more" place I worked, they also relied pretty heavily on abstraction and general higher-order-ness. They just had a different way of doing it: Service boundaries and protocols. Arguably the Unix philosophy is similar: A bunch of small programs that do one thing and do it well, which you can chain together with pipes.

The CTO's official reason for the "less is more" philosophy was not that he didn't think that more powerful language features weren't useful, it was that sticking to less powerful features discouraged the growth of individual modules into large complicated tangles, by making it actively painful to do that.

My one, somewhat guarded, criticism of that approach is that I think it may have depended critically on the company being in a position to maintain some very selective hiring practices. When you limit yourself to only hiring people who can really appreciate Chuck Moore's style, well, you've limited your hiring quite a bit. I could be convinced that the "correctness by concept" approach is less fragile and dependent on having a rigid corporate monoculture in order to work out properly.

Re:A Plea for Lean Software (1995) [pdf] by cxr on Wednesday August 05, 2020 @04:28PM (#24065205)
> That's another strange thing to insinuate against a programming style that is noted for its use of closures.

Let's be honest: there are two completely opposite meanings of "functional programming" that we're burdened with having to put up with, and most of what passes for "functional programming" straight up isn't. Somehow the people making heavy use of closures manage to pass themselves off as doing FP, even though that style is decidedly unfunctional. I wish there were wide recognition of the distinction between this pseudo-functional (PF) style from actual FP, and that we'd call it out as appropriate.

Frustratingly, the inhabitants of this bizarro world who program in the PF style still tend to undeservedly hold the same smug expressions on their faces as the one FP folks do with regard to OO—with lifted noses about OO being unclean, even though PF folks' closure-heavy style is no better—with PF being equivalent to OO, except for the former being being less syntaxy, which only leads it it being harder to spot the trickery employed in the PF folks' programs. This is fairly annoying.

Re:A Plea for Lean Software (1995) [pdf] by runald on Wednesday August 05, 2020 @10:26PM (#24067614)
Huh? I don't know if you are aware of this, but higher-order functions make heavy use of closures. I don't think there is even a purpose to higher-order functions without closures. I don't how haskell is implemented internally, but conceptually, it makes use of closures quite heavily. It uses closures on currying, it uses closures on monads, and on everything else. If you assert that heavy use of closures alone is decidely unfunctional, then haskell must be one, which is obviously false.

I don't know what definition of functional programming you are using[f], but you don't have to be arrogant about it. Your comment is fairly annoying.

[f] Let me guess, only immutable variables and pure functions? How PF.

Re:A Plea for Lean Software (1995) [pdf] by cxr on Thursday August 06, 2020 @12:22PM (#24072445)
> higher-order functions make heavy use of closures

No, you're conflating higher-order functions with closures. Higher-order functions that use closures make use of closures. Higher-order functions that don't use closures do not.

> I don't think there is even a purpose to higher-order functions without closures.

I'm not sure how anyone can say this with a straight face, let alone someone who considers themselves to be in a position to challenge somebody about whether or not they grok functional programming.

Re:A Plea for Lean Software (1995) [pdf] by runald on Friday August 07, 2020 @12:43AM (#24078404)
>No, you're conflating higher-order functions with closures

Well, if you are actually doing the real hardcore FP™, and not just the lame pretentious PF, then yes higher-order functions will indeed very much make heavy use of closures. Did you miss the part where I gave haskell as an example? And note that I didn't say that closures and higher-order functions are the same thing.

> Higher-order functions that use closures make use of closures. Higher-order functions that don't use closures do not

How are these tautologies even an argument? This does not say anything meaningful, like saying wet water is wet. Don't worry, I'm not even trying to keep a straight face while reading what all you have said so far.

> I don't think there is even a purpose to higher-order functions without closures.

Heh, I did qualify my statement with "I don't think" since I didn't really give that much though on that one.

But okay, I admit that statement is dumb and invalid since the usual map, filter, reduce functions are good examples where higher-order functions is not a closure. But more often than not, you really do need to use closures to do anything beyond simple cases like map(array, x => x*x).

My overall point still holds. I'm still in a very good position to challenge your dogmatic beliefs that: heavy-usage of closures is pseudofunctional and unfunctional.

Re:A Plea for Lean Software (1995) [pdf] by cxr on Friday August 07, 2020 @05:16AM (#24079964)
> How are these tautologies even an argument?

They're not, and that was exactly the point of my comment: it's a circular argument that you have to take responsibility for, not me. You seem to have missed that—it's your nonsense claims that are in focus when the tautology is being spelled out.

Higher-order functions and closures are different things.

> Well, if you are actually doing the real hardcore FP™, and not just the lame pretentious PF

I wouldn't call the pseudo-functional style "hardcore"—any more than OO is hardcore, given that they're equivalent. It's frequently portrayed as the naive/easy way out. Actual FP, on the other hand, is hardcore. (And pretentious—which is an odd attempt to try to stir me up; do you think I'm an advocate of FP or something? I suggest re-reading.)

> But more often than not, you really do need to use closures to do anything

Yes, which is why I'm not an FP advocate.

I was very clear in my original comment. The pseudo-functional style is a preference for how to write programs, and therefore immediately defensible as valid. What's not defensible, though, is equivocating on the meaning of "function" while simultaneously trying to lump the pseudo-functional style in with FP. The moment one starts making heavy use of closures and carrying around state is the moment one forfeits the right to be smug about how unclean OO is, given the equivalence of objects and closures and given that one is no longer actually practicing FP.

> I'm still in a very good position to challenge your dogmatic beliefs that: heavy-usage of closures is pseudofunctional and unfunctional

No, you're not. It's unfunctional by definition.

Re:A Plea for Lean Software (1995) [pdf] by runald on Friday August 07, 2020 @06:59AM (#24080573)
It sure is easy moving the goalposts around when you have no grounds to base on. Please, please you have said this much and haven't still even once defined what true functional programming™ is?

> It's unfunctional by definition.

There you go, more self-fulfilling tautologies. And for some magical reason, it's me that are making nonsense claims? How is "higher-order functions make heavy use of closures" a nonsense claim?

I have provided a very clear and direct counter-example that falsifies your core argument. On the other hand, you have provided zero actual rebuttals. In case it isn't clear, calling mine "nonsense, circular and tautological" and yours "by definition" doesn't count as an argument.

> The pseudo-functional style is a preference for how to write programs, and therefore immediately defensible as valid

Is the word style even relevant here? You can call it style, paradigm, or computational model, it doesn't change your point.

> What's not defensible, though, is equivocating on the meaning of "function" while simultaneously trying to lump the pseudo-functional style in with FP.

Ugh, I'm guessing your definition of "function" is a special amorphous one that changes meaning to conveniently support your claims.

> The moment one starts making heavy use of closures and carrying around state is the moment one forfeits the right to be smug about how unclean OO is, given the equivalence of objects and closures and given that one is no longer actually practicing FP.

No, repeating your statements don't make them true. Once again, see my original counter-example with haskell. If you insist in ignoring it, then fine with me. I'm done here.

Re:A Plea for Lean Software (1995) [pdf] by cxr on Friday August 07, 2020 @11:01AM (#24082573)
> It sure is easy moving the goalposts around

If I've moved the goalposts, you should be able to show where it happened. So do—point to it or fuck off.

As for the rest of your comment and being "done", that's fine. There's zero chance that I'm going to waste my time on a point-by-point rebuttal for anyone who's acting in this much bad faith, ignoring the points I've already made, and trying to pawn off the flaws in your arguments as mine.

Re:A Plea for Lean Software (1995) [pdf] by mumblemumble on Wednesday August 05, 2020 @10:54PM (#24067724)
Internally, Haskell's intermediate representation is a version of the lambda calculus. Which would mean that, practically speaking, Haskell is largely just one big pile of closures.

Which really shouldn't be a surprise. After all, you can't curry if you can't close.

Re:A Plea for Lean Software (1995) [pdf] by wk_end on Wednesday August 05, 2020 @07:24PM (#24066709)
In the case of the former, I think you're misunderstanding Wirth. His statement isn't predicated on the idea that functional programming 100% requires the language to eliminate state, necessarily; just that functional programming discourages state in lieu of primitives less aligned with the machine.

For instance, functional programmers would almost all tell you that `map (x => ...) xs` is "better" than `for i from 0..len(xs): xs[i] = ...`. But the former, implemented trivially, is very slow: from the allocation of the closure to the allocation of the new list to the function calls on each iteration and the lack of tail recursion in `map`'s implementation (this is a trivial implementation, remember?)

Of course, the functional programmer would tell you, "Well, it's easy to optimize that, the performance issues are just because your implementation is too trivial", and Wirth would rejoin, "Too trivial? What's that?"

Re:A Plea for Lean Software (1995) [pdf] by kqr on Thursday August 06, 2020 @02:28AM (#24068601)
I don't think this is a fair point, since the two snippets do different things. One creates a new list, and the other does not. If, as a functional programmer, I was actually interested in mutating the existing sequence (e.g. for performance reasons), I would definitely write the loop.

If you're interested in maximum constness (which I tend to be, because I find it's almost always easier to read code where values don't unexpectedly change in a branch somewhere) then you'd be comparing

    let ys = map f xs
to

    let ys = []
    for i from 0 .. len(xs):
        ys.push(f(xs[i]))
where the former obviously makes it much more clear what's going on.

Sure, it's using "primitives further from the physical machine" but that is exactly what programming is about! You create a new layer of primitives on top of the old ones, where the new layer makes it slightly easier to express the solution to the problem you're solving. You do this incrementally.

When someone has built a more easily handled set of primitives for you, it would be silly not to use them, all else equal.

----

In other words: the only real reason to mutate values is to improve performance at the cost of readability, and at the cost of losing the ability to safely share that data across concurrent threads.

If, indeed, that is a cost you're willing to pay for the additional performance, no functional programmer I know would shy away from the imperative mutating loop.

Re:A Plea for Lean Software (1995) [pdf] by wk_end on Thursday August 06, 2020 @02:53AM (#24068713)
They do two different things, but they do different things the way the style they're written in encourages. Performance-considerations aside, the functional programmer would rather create a new list (or, as you said, they're "interested in maximum constness" - the precise preference for statelessness Wirth is calling out); the imperative programmer would mutate the existing list.

Wirth is not talking about clarity, not in the sense of "can I look at the code and understand the high-level intent of the programmer"; Wirth is interested in clarity in the sense of "can I look at the code and understand exactly what it's doing, at every level"?

For Wirth, programming is not about using an endless stack of primitives that get you further and further from the physical machine, so much that they start to obfuscate what's happening at lower layers. It's about building the smallest, simplest stack of primitives such that you can express yourself effectively while still understanding the entirety of the system. The Oberon system includes everything from the HDL for the silicon all the way up to the OS and compiler in around 10,000 lines of code because you're supposed to be able to keep all of it in your head.

I'm not saying that any of this is correct, per se, nor am I arguing for it - I'm sympathetic to it in some ways and disagree with it in others (I am, in fact, very much into FP). I'm just trying to give a charitable and clear interpretation of his perspective. FP may not want to get rid of state in one sense, as you've pointed out; but it wants to get rid of state in another, and Wirth doesn't like that because it necessitates complexity - and Wirth hates that.

Re:A Plea for Lean Software (1995) [pdf] by kqr on Thursday August 06, 2020 @05:36AM (#24069441)
For Wirth, programming is not about using an endless stack of primitives that get you further and further from the physical machine, so much that they start to obfuscate what's happening at lower layers. It's about building the smallest, simplest stack of primitives such that you can express yourself effectively while still understanding the entirety of the system.

Now that is an interesting perspective I hadn't even considered. Also not sure I would agree – but if I was interested in finding out more but found the OP unconvincing, where would I go to find out more?

Re:A Plea for Lean Software (1995) [pdf] by cxr on Friday August 07, 2020 @12:08PM (#24083443)