I’m starting to think that in order to really grok functional programming you need a certain kind of brain. the kind that doesn’t just understand math but enjoys doing it
and like I understand that the philosophy is to maximize the use of pure functions and to program declaratively. but I’m not sure if I’ll ever understand why certain people value those things so highly that they’d go out of their way to use languages that are designed to support them. especially the languages like Haskell that don’t support any other style of writing your code
I was hoping that trying functional languages would make this more clear to me but unfortunately I think all of my experience in imperative scripting languages is getting in the way, because every time I struggle to do something basic in E.G. Haskell all I can think about is how easy it would be to do in Python instead. but that’s because I’ve been using Python for 20 years and I’m very bad at math - so it’s not a fair comparison
at least to me as someone who was taught to hate math in school, it feels like programming a nontrivial function in a functional style gets arcane very quickly. it’s like you have to solve a difficult math problem in your head in order to figure out what code to write, and then when someone else reads it they have to re-solve the same math problem in their head in order to understand how your equation works. and I’m not sure if it’s supposed to feel like that or if that’s just me being bad at math again
maybe if someone is learning programming for the first time and they really grok math, it feels the other way around for them? like imperative code takes a lot of mental energy, but functional code is effortless to read?
I guess I feel like - if I was ever going to understand the appeal of functional programming - I would have by now. I’ve read so many “why learn this functional language?” chapters at the beginning of different books, that talk in vague terms about how the language is pure or elegant. but for me everything is so much harder in functional-land and I’m not sure if it’s supposed to be harder or if it’s actually easier for those who grok it
I still want to try more Lisps though. I’m just going to ignore the functional programming stuff about them. what I really like about Lisps are the S-expressions and metaprogramming
@kasdeya Just sharing my opinion in case it provides some insight.
I don’t think I understand math all that well, but I really like functional programming. To me it feels like building tiny factories, with “in” and “out” pipes, and stringing them together to make a pipeline. It doesn’t feel all that different from writing a long bash pipeline for instance.
I haven’t programmed in a fully functional language like Haskell or Lisp in a professional setting though, so maybe I would struggle with large codebases. The closest I get to it daily is through JavaScript, which is admittedly pretty functional as far as mainstream languages go but nothing actually forces you to use it that way.
@kasdeya maybe it's not that FP is inherently better; maybe i just experienced early on some of the worst of what imperative languages had to offer, and so was in the right headspace to be very willing to try out this weird thing that seemed to have the potential to not be that 😅🫠
these days my most productive language is actually Java; i just take the lessons i learned from FP about avoiding certain kinds of complexity and use them in Java. but i do the same with ideas from OOP!
@esheep interesting! the “in” -> “out” pipeline way of thinking about it does make sense to me because I often write parts of my Python code that way when I’m able to break a problem down into discrete data-processing steps like that
I think I just get really disoriented in an environment where there’s no concept of classes or objects, because I don’t know how to find functions that are relevant to what I’m trying to accomplish. also function currying makes sense to me conceptually but the way it’s used in E.G. Haskell really hurts my brain lol, having to keep track of a bunch of lambda calculus in my head
and there are other things like that - like recursive functions can really hurt my brain if they have more than like 3 arguments, and especially if the arguments aren’t named things that make sense to me
@liese omgg Java scares me as a language lol. it feels like the OOP stuff that I love in Python but taken to a sadistic extreme where literally everything is probably some kind of bespoke class or object
maybe i just experienced early on some of the worst of what imperative languages had to offer, and so was in the right headspace to be very willing to try out this weird thing that seemed to have the potential to not be that 😅🫠
this is so interesting to me btw because I have a partner who is really into functional languages and I think the same is true of them. they started off learning some really nasty languages that they hated like C++, and after that they learned Erlang and Elixir and loved them and now they’re interested in learning Gleam too
@kasdeya every language has crazy stuff lurking below the surface! python, for instance, allows some incredible magic using metaclasses. the key is finding a small subset of a language you can use to get your feet wet, then slowly wade into deeper waters as you become more comfortable :)
haskell is kind of infamous for having a *very* deep deep end, and a still rather deep shallow end. if you're super used to doing things with mutation, quitting cold turkey is extremely hard!!
@kasdeya i think it's really valuable to be able to learn how to do things without mutation, because in return you gain tools for *controlling* its complexity when you *do* want (or need) to use mutation. it's hard to find the happy medium without going too far to either side a few times! but haskell may not be the right way for *everyone* to have that experience :)
@kasdeya sorry, think i tangented there a bit. point is, take your time, don't worry about rushing into a new language and requiring yourself to "get" the entire mindset quickly. find a language that exemplifies the concept you want to learn without forcing you to totally change everything about how you think all at once!
@liese omg yeah the underlying eldritch nature of Python is a big part of why I’m so interested in languages like Lisp or Lua that are built up from very simple pieces. because I have no fucking clue how certain parts of Python work and I’m scared to touch them hehe
and yeah - in the past I tried writing functional-style code in Python but unfortunately Python doesn’t like that very much hehe. its syntax feels pretty clumsy for doing that - for example it doesn’t even have a pipeline operator. if I do decide to experiment with functional languages again I might give F# a try since it sounds like it won’t force me to write everything in a pure and immutable way right off the bat, and that would be nice
@kasdeya haha yeah, experimenting with functional techniques in a multi-paradigm language is good -- but python *really* doesn't want to be multi-paradigm 🫠
@kasdeya (lua is a hell of a great language btw, huge fan. it's so minimal but it's amazing for embedding into a host program for scriptability, and it's where i first learned about and fell in love with coroutines!!)
@liese I love Lua omg. I immediately fell in love with its import system and how OOP works in the language. the 1-indexing and ~= meaning “not equals” and a few other things are pretty annoying though. but yeah I still absolutely love it just for how dead simple and easy-to-understand it is
I’ve actually never needed coroutines though hehe so I have no idea how they work or what they are. I’m guessing they’re somewhat similar to async/await in Python and JS though
@kasdeya i was introduced to Lua because the MUD client I used, MUSHclient, is scriptable using Lua. it had support for "aliases" (scripted commands that are processed by your client instead of the MUD server) and "triggers" (scripted reactions to pattern-matched output coming from the MUD server), which could be used to heavily customize your experience interacting with the MUD.
sometimes, one alias isn't enough! sometimes you want to script some behavior to occur over the course of several successive aliases, or perhaps several successive uses of the same alias. (or perhaps you want to script something to occur over a sequence of recognized triggers!)
coroutines were magic for this, because you could write one script that "waited" for the next stimulis, and proceeded from that point in the script, instead of having to register a bunch of callbacks that would have to refer to some global collection of state to try to figure out where it had "left off" in the list of things it was supposed to do.
basically, i could write complex scripted interactions that were totally self-contained, instead of having to spill the inner guts of the scripts into the top-level global definitions and having to figure out what the heck the script was doing after several months of not using it