3 ms·
> "As an incompetent programmer, you may write code that sets a variables value unexpectedly, which is turn used by some other thread, which will create a bug.
by xupybd 4y ago
> "As an incompetent programmer, you may write code that sets a variables value unexpectedly, which is turn used by some other thread, which will create a bug. So you need functional programming to avoid making this mistake"
Ouch, don't hold back tell us what you really think.
But that is not the entire meaning. If I have a function that has side effects such as a typical OO setter function it may change the state of the object in ways that are encapsulated from the consumer of the function. If someone has to come in years later and change that function it's not always obvious what state changes the function is required to make in order for the other functions in the class to operate. So we have regression tests to ensure any misunderstandings are caught.
Pure functions take in state as data. So we lose the encapsulation but gain clarity.
You are correct however, if we programmers could only do our jobs competently we'd have no need of such things.
Personally I like to setup tools that catch my mistakes, because I make lots of them.
- sweezyjeezy 4y ago> You are correct however, if we programmers could only do our jobs competently we'd have no need of such things. That's the thing though - comparing "good FP" vs "good OO" is a false equivalence, in reality you will need to deal with other people's code, or yourself when you didn't know better. Bad OO << bad FP, that's basically all I need to make my mind up!
- xupybd 4y agoTo quote someone smarter than me. "100% pure functions are the way to go where possible" You don't need to throw out OO to introduce some functional ideas that help improve the correctness and make it easier to maintain. Bad FP to me often means the unreadable mess of complexity that some choose to introduce with their functional code. Personally I try to avoid anything that I'd consider "fancy". But using pure functions is functional programming IMO.
- sweezyjeezy 4y agoThat's true, if someone's fallen in love with recursion or currying, that's often going to end in tears.
- schwartzworld 4y agoCurrying is amazing though.
- sweezyjeezy 4y agoAmazing to write, often insane to read / debug
- ActorNightly 4y ago> I like to setup tools that catch my mistakes If you write unit/integration tests for your code, you already have all the tools necessary to catch those mistakes. You also have general knowledge at your disposal on writing code smartly as to avoid potential mishaps. You don't need a whole another programming paradigm to do all of this.
- xupybd 4y ago>You also have general knowledge at your disposal on writing code smartly as to avoid potential mishaps. Exactly that's why I use pure functions where possible.