r/functionalprogramming • u/Almesii • Aug 18 '26
Question Functional Programming in VBA
/r/vba/comments/1vrm5si/functional_programming_in_vba/
5
Upvotes
r/functionalprogramming • u/Almesii • Aug 18 '26
1
u/kinow mod Aug 18 '26
I haven't used VBA in a long, long time. I had a quick look at the code and it looks organised. But I think it'd be interesting to have some examples in the README.
1
u/RingularCirc Aug 23 '26
Looks very cumbersome to use. That's VBA's problem, of course, but it shows that it's hard to do some things in it that people are breathing as air by this time.
I attribute it to following properties of VBA:
Variants and it's a pain to imagine how costly that's both at runtime and for the fallible programmer. We can hardly do better by introducing something like interfaces for functions that take a single argument of each of mostly used primitive types and something to work withObjects as well. That way still lies madness, especially because return values should also be typed if we're trying to type arguments. That will fail badly because we can't type returned functions...I'm not sure the game's worth a candle at all. Sure this is an exercise, but it doesn't look as something that can become practical in real VBA code, especially given a lot of classes as dependencies.
I'm so so glad I haven't touched VB6-or-VBA code in almost decades. When I first started writing in Delphi 7 it was quite liberating an experience, even despite I was still very inexperienced then. BTW Delphi 7 would be a bad choice to try and write a general functional programming framework as well, despite at least Delphi can probably support some FP via concrete code. It doesn't have enough abstraction in its type system either.
There are IMO also questionable decisions in this code of yours like invoking functions by using their string name (why not write class implementations) and defining
HeadandTailamong examples when they don't serve much purpose in context of VBA except for adding tons of inefficiency. Compare them to a function of taking an arbitrary span out of an array or collection, at least.Other than all that, I can only sympathize with what you had to go through to get to at least something that works. 😅