Posts tagged with functional programming

Join 9,500+ smart developers

Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Deep dive: How do React hooks really work?

www.netlify.com

Hooks is feature was added recently to React that I really like.

In this article, we reintroduce closures by building a tiny clone of React Hooks. This will serve two purposes – to demonstrate the effective use of closures, and to show how you can build a Hooks clone in just 29 lines of readable JS. Finally, we arrive at how Custom Hooks naturally arise.

Read more [www.netlify.com]

Short closures in PHP

stitcher.io

Short closures are coming to PHP 7.4. In this blogpost, my colleague Brent exaplins what they look like and how they can be used

Short closures, also called arrow functions, are a way of writing shorter functions in PHP. This notation is useful when passing closures to functions like array_map or array_filter.

Read more [stitcher.io]

Lambda To The Rescue: Recursion

engagor.github.io

Toon Daeleman, developer at Engagor, explains how functional languages use recursion instead of loops.

Most programming languages have language structures to loop through lists and do interesting stuff with those lists. When you're used to programming using one of those languages, it can be pretty terrifying to have your basics taken away from you when you jump into a functional programming language like Scheme or Haskell. Let's see what the problem is that functional languages have with loops and how they solved it.

Read more [engagor.github.io]

FP vs. OO

In a new post Uncle Bob explains that you shouldn't have to choose between functional programming and object orientation.

In this blog I will make the case that while OO and FP are orthogonal, they are not mutually exclusive. That a good functional program can (and should) be object oriented. And that a good object oriented program can (and should) be functional. But to accomplish this goal we are going to have to define our terms very carefully.

http://blog.cleancoder.com/uncle-bob/2018/04/13/FPvsOO.html

Read more

Building Blocks

Steven Vandevelde wrote a beautifully illustrated post on some cool functional concepts.

This is a more visual approach to the topic of purely-typed functional programming. What does it mean to have a “functional” programming language? What are types? What makes a functional-programming language “pure”? These are the questions we will answer here, with a focus on simplicity.

https://icidasset.com/writings/building-blocks/

Read more

Enabling PHP method chaining with a makeshift pipe operator

Sebastiaan Luca, a freelance Laravel developer from Antwerp, coded up a couple of functions that mimic a pipe operator.

An interesting RFC proposal by Sara Golemon submitted in April 2016 suggested the use of a pipe operator to enable method chaining for any value and method. Yet as of today, it's still being discussed and there's no saying if it will ever make its way into PHP. So in the meantime, here's a solution!

https://blog.sebastiaanluca.com/enabling-php-method-chaining-with-a-makeshift-pipe-operator

Let's hope a real pipe operator will land someday in PHP.

Read more

Language features and code properties

Josh Justice gives some solid advice on how to pick the right language for your next projects.

So to ask the question “should I use an OO or FP language (or style)” is to skip several steps. I think a better series of questions are: First, what properties would be beneficial for your application to have: concurrency? Immutability? Encapsulation? There are a lot of things you won’t know about your application at first, but you can at least know if it will be a backend app, JavaScript browser app, or native mobile app; if it will be CPU-bound or IO-bound; and if it will process data inputted by humans or automatically generated by machines. All of those factors can influence which properties you need.

Once that’s decided, the next question is, in a given language, are those properties guaranteed, easy, difficult, or not realistically achievable?

http://codingitwrong.com/2017/07/27/language-features-and-code-properties.html

Read more