Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Functional Programming in Go

You're reading from   Functional Programming in Go Apply functional techniques in Golang to improve the testability, readability, and security of your code

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781801811163
Length 248 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dylan Meeus Dylan Meeus
Author Profile Icon Dylan Meeus
Dylan Meeus
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1: Functional Programming Paradigm Essentials
2. Chapter 1: Introducing Functional Programming FREE CHAPTER 3. Chapter 2: Treating Functions as First-Class Citizens 4. Chapter 3: Higher-Order Functions 5. Chapter 4: Writing Testable Code with Pure Functions 6. Chapter 5: Immutability 7. Part 2: Using Functional Programming Techniques
8. Chapter 6: Three Common Categories of Functions 9. Chapter 7: Recursion 10. Chapter 8: Readable Function Composition with Fluent Programming 11. Part 3: Design Patterns and Functional Programming Libraries
12. Chapter 9: Functional Design Patterns 13. Chapter 10: Concurrency and Functional Programming 14. Chapter 11: Functional Programming Libraries 15. Index 16. Other Books You May Enjoy

Modern functional programming

After our brief look at the history of FP, it’s time to dive into modern functional languages. One of the languages that is popular today within the strict FP languages is Haskell. When people study FP or become exposed to it, it is often through this language. Haskell is a statically typed FP language. It has goodies such as type inference (like ML) and lazy evaluation (like Miranda).

When people want to learn more about pure FP, my recommendation is always to start with Haskell. It has a great community and plenty of resources and teaches you all there is to know about the FP domain.

It might very well be the most popular pure FP language around, yet it accounts for less than 1% of the active users on GitHub (https://www.benfrederickson.com/ranking-programming-languages-by-github-users/). For fun, if we take a look at Go, it currently sits at about approximately 4% of active users. Not bad for a language that’s just about a decade old at this point!

In the .NET world, another language that is relatively popular is F#. While this is not a purely functional language such as Haskell, it is a functional-first language. It prefers the functional paradigm over others but does not enforce it. Similarly to Haskell, it has less than 1% of active users on GitHub. C# seems to get all the popular features of F# though, so at least the functional concepts that F# spearheaded for .NET will find popularity.

So does that mean functional programming is dead on arrival? Well, not quite. The book you are reading now is all about Go, and Go is not a purely FP language. My take on it is that the concepts from FP are generally useful and can create better code, even in object-oriented languages – and I’d like to think I’m not alone in thinking this. Many of the languages that we think of as object-oriented languages have become more and more functional.

We can see this shift happening even in the most popular mainstream object-oriented languages. Java is introducing FP concepts with each iteration, offering such things as pattern matching, higher-order functions, and declarative programming through Lambda functions. C# is looking more and more like F# (Microsoft’s functional programming counterpart of C#) with each release. They have implemented pattern matching, immutability, built-in tuple support, and more.

This shift is happening because, although purely functional languages might not always suit the industry, the concepts from functional languages allow us to write our object-oriented code with more confidence. They lead to code that is easier to test, easier to read, and faster to debug.

The most popular programming language used today is JavaScript. While this would perhaps not pop into people’s minds when talking about FP, it does meet a subset of the “requirements” we have for a functional language. It has the following:

  • First-class functions
  • Anonymous (Lambda) functions
  • Closures

When combining these features, we can create many constructs that allow us to leverage code in an FP style.

For those of us who want to have a purely functional language in the browser, there are languages that transpile to JavaScript, such as Elm and PureScript.

Let’s now take a look at the star of this book, Go, and how this fits into the picture.

You have been reading a chapter from
Functional Programming in Go
Published in: Mar 2023
Publisher: Packt
ISBN-13: 9781801811163
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image