Live data from Hacker News

Functional programming is finally going mainstream

github.com

31–40 of 171 posts

Re: Functional programming is finally going mainstream

#31
post #22

Great I am looking forward to seeing mode code like this: timeslotRepo.findAll().stream().filter(timeslot->timeslot.getEndDate()==null).first().ifPresentOrElse(()->{}, ()->{new Timeslot(DateTime.now())})

Well, that's an ignorant reduction of functional programming but suit yourself.

It's exactly the experiences I've had trying to read functional-style Rust code that uses higher-order function methods as a replacement for control flow primitives.

Re: Functional programming is finally going mainstream

#32

I'm not sure how I feel about this. If you look at my code in "multi-paradigm" languages like typescript, there's not a heck of a lot of loops, mutations or side effects. I like expressions, and immutability, and higher order functions. They make things shorter and means there's less state for me to keep track of - or screw up. But at the same time, I like objects. Almost all of mine are immutable. I went through a p…

With immutable objects, aren't you just left with syntactic sugar around structs and functions? I'm picturing CLOS, which is undoubtedly an OO system but lacks 100% of what you use objects for. Are there languages which let you use dot-syntax for "methods" which just wrap normal functions?

At that point you're left with two benefits: 1) Organizing your codebase so that it is easy to find which functions operate on which data 2) Controlling access to those methods on the programming language level. I.E, TankerService is the only class with Tanker instances and therefore the only part of the code with access to those methods.

Re: Functional programming is finally going mainstream

#33

I'm not sure how I feel about this. If you look at my code in "multi-paradigm" languages like typescript, there's not a heck of a lot of loops, mutations or side effects. I like expressions, and immutability, and higher order functions. They make things shorter and means there's less state for me to keep track of - or screw up. But at the same time, I like objects. Almost all of mine are immutable. I went through a p…

The problem with state in objects is that in more complex systems you often need to change a bunch of related state at one time. When it's all bound up in individual objects that manage their own state this becomes very complicated.

Re: Functional programming is finally going mainstream

#34
post #22

Great I am looking forward to seeing mode code like this: timeslotRepo.findAll().stream().filter(timeslot->timeslot.getEndDate()==null).first().ifPresentOrElse(()->{}, ()->{new Timeslot(DateTime.now())})

Well, that's an ignorant reduction of functional programming but suit yourself.

Yes, it’s far too readable to be actual functional programming.

Re: Functional programming is finally going mainstream

#35

I'm not sure how I feel about this. If you look at my code in "multi-paradigm" languages like typescript, there's not a heck of a lot of loops, mutations or side effects. I like expressions, and immutability, and higher order functions. They make things shorter and means there's less state for me to keep track of - or screw up. But at the same time, I like objects. Almost all of mine are immutable. I went through a p…

The problem with state in objects is that in more complex systems you often need to change a bunch of related state at one time. When it's all bound up in individual objects that manage their own state this becomes very complicated.

Sorry, I don't get what how that's harder.

    newData = f(oldData)
VS

    newObject = oldObject.f()

Re: Functional programming is finally going mainstream

#36
post #16
post #2

Functional programming with immutable state cannot possibly win in the general case. There are two truths that ensure the dominance of imperative software: 1. At some level of software complexity, programmers MUST start to organize data into composite objects. They have to do this because working outside of well-defined problem domains is a recipe for buggy software and spaghetti code. 2. Copying memory around to ena…

The biggest problem I have with functional programming is debugging. On imperative code, execution is easy to follow. Instructions go one after the others, loops loop, function calls and local variables go on the stack, globals are always visible. Optimization aside, what you code is what the computer runs. You often have a debugger to step through your code, or some logging facilities, even if it is just a printf. O…

This isn't my experience at all. Imperative code with side effects is harrowing to debug because it may do different things depending on what execution path got you there.

Pure functions are easy to debug. Run it, check the result against expectations. Step in if necessary.

Re: Functional programming is finally going mainstream

#37

Earlier quoted context omitted.

Koka-lang and Roc-lang? What are those?

https://koka-lang.github.io/koka/doc/index.html https://www.roc-lang.org/ Both working on making functional programming practical and very fast. Koka is more of a research language, also developing Algebraic Effects and making them practical, which is very cool.

90% sure these are Malaysian soft drinks

Re: Functional programming is finally going mainstream

#38
post #29
post #22

Great I am looking forward to seeing mode code like this: timeslotRepo.findAll().stream().filter(timeslot->timeslot.getEndDate()==null).first().ifPresentOrElse(()->{}, ()->{new Timeslot(DateTime.now())})

So you're filtering specifically for timeslots where the end date is null and therefore guaranteeing that you return a timeslot dated to now?

  if timeslots.stream().matchNone(Timeslot::hasntEnded) {
    new Timeslot()
  }
Would be an improvement I guess. The way I found this code it was also wrapped in a @Transaction so it creates a new object in the database with spring magic. There was a lot of other things wrong with the code, that was not my point though. Lots of people just think FP better and of course in theory they are right but most people don't think for themselfs.

People are quick to act insulted whenever I give some critical remarks about FP.

When would you use a forEach function instead of a for each statement, I suggest maybe only use the function if the callback is actually a higher order function you get from somewhere else as I don't see the point of wrapping your logic in a closure.

Same thing with the use of observables/reactivity in UI programming, again it is illegal to question this orthodoxy. But then you take a look at how graphics programmers use immediate mode programming and fancy compute shaders to draw the entire frame every frame it makes me smile at how much simpler everything becomes.

Re: Functional programming is finally going mainstream

#39

Earlier quoted context omitted.

The problem with state in objects is that in more complex systems you often need to change a bunch of related state at one time. When it's all bound up in individual objects that manage their own state this becomes very complicated.

Sorry, I don't get what how that's harder. newData = f(oldData) VS newObject = oldObject.f()

Furthermore, it chains nicely and offers pleasant autocompletion in your IDE:

    newObject = oldObject.f().g().h().i().j().k()
VS

    newData = k(j(i(h(g(f(oldData))))))

Re: Functional programming is finally going mainstream

#40
post #2

Functional programming with immutable state cannot possibly win in the general case. There are two truths that ensure the dominance of imperative software: 1. At some level of software complexity, programmers MUST start to organize data into composite objects. They have to do this because working outside of well-defined problem domains is a recipe for buggy software and spaghetti code. 2. Copying memory around to ena…

Others already argued against your point, but I want to point out that (2) is simply wrong. You can have mutability in functional programming -- not in general, but there are cases where this can be expressed. For example, in a very simple example:

   a = [1, 2, 3]
   b = a.append(4) // append: list->int->list
   // Rest of the code never refers to a, but refers to b
In this code, you can prove that it's safe to move a's memory into b and thus append operation can be done without copying a. I'm not implying this is easy to implement, but it's clear that this is not a fundamental issue in functional programming, rather a deficiency in its current implementations.
Post reply on HN