Holochain Forum

Is Functional Programming a Thing?

[Warning: I am not a coder, just interested in the topic. So I don’t really know what I am talking about :wink: ]

Recently I stumbled across a presentation about the paradigm of Functional Programming.
Two important aspects of this coding approach are:

  1. Write “clean functions”: You pass an input (or many) into the function and return an output - no calling or writing of global variables from inside the function, no “side-effects”, only the return value

  2. Immutable Data: To avoid data being changed under your nose while running a function, you make all data storage immutable. E.g. instead of changing (overwriting) an element in an array, you create a copy with the updated element. To prevent lots of redundant copies of data, you only write new entries and use some clever tree-structure to reference all the most up-to-date data.

It sounded extremly Ceptr-ly to me. So I wanted to ask:

Is Functional Programming a thing with Holochain developers? And if not, should it be?

Would love to hear your thoughts!

Hi @jakob.winter there is a relationship between Category Theory and Functional Programming.

And I have seen some refer to Ceptr as “…a planetary distributed semantically rich functional reactive programming environment…AKA processing of immutable streams, which reminds me strongly of receptors.”

A great comment from @pospi on Mattermost:

“My pro-tip on Rust is that the book will fool you into thinking it is a nice high-level functional language where you can write very elegant, terse code. It is not. It is much more like writing some weird hybrid of C & LISP than it is like writing modern functional JavaScript or Haskell. There is no currying. It is a low-level systems programming language where the memory semantics of the language are encoded into the type system for safety. Because it wants to be highly optimised, nothing is for free. If you want to pull a bunch of fields out of a struct into somewhere else, you are going to have to write some big verbose bit of code that accesses every field in that struct manually. To reduce that verbosity, you use macros- hence why it’s a bit LISPy as well as a bit Cy. Hope that helps with your learning curve a bit… realising this freed me from the hells I was encountering!”

I imagine @pospi @dellams may want to share their thoughts on this topic.

Functional programming is pretty neat, and I’m curious to see how people will uncover the overlaps between it and Ceptr/Holochain. Seems like many threads in the computing world are converging… @jakob.winter which parts seemed particularly Ceptr-ly to you?

Interesting thoughts from @pospi on how functional Rust isn’t, @dhtnetwork :slight_smile: My gut feeling is that anyone who learns the basics of functional programming will write more disciplined, bug-free programs, which will put them in good stead even when they’re writing in languages like Rust that don’t make FP style easy. This’ll be especially important in validation functions!

1 Like