Functional Programming Patterns in Scala and Clojure
eBook - ePub

Functional Programming Patterns in Scala and Clojure

Write Lean Programs for the JVM

  1. 256 pages
  2. English
  3. ePUB (mobile friendly)
  4. Only available on web
eBook - ePub

Functional Programming Patterns in Scala and Clojure

Write Lean Programs for the JVM

Book details
Table of contents
Citations

About This Book

Functional languages have their own patterns that enable you to solve problems with less code than object-oriented programming alone. This book introduces you, the experienced Java programmer, to Scala and Clojure: practical, production-quality languages that run on the JVM and interoperate with existing Java. By using both the statically typed, type-inferred Scala and the dynamically typed, modern Lisp Clojure, you'll gain a broad understanding of functional programming.

For each pattern, you'll first see the traditional object-oriented solution, and then dig into the functional replacements in both Scala and Clojure. These patterns are common in the functional world and deserve to become part of your problem-solving toolkit. On the object-oriented side, you'll see many common patterns, such as Command, Strategy, and Null Object. On the functional side, you'll learn core functional patterns such as Memoization, Lazy Sequence, and Tail Recursion.

Each pattern helps you solve a common programming problem. Working through them gives you a set of patterns you can use to solve problems you come across while writing programs. Finally, you'll learn how to work your existing Java code into new Scala or Clojure projects. You can start off small, adding functional code little by little, so you can complement your existing knowledge with Scala and Clojure as these languages gain popularity on the JVM.

Q&A with Michael Bevilacqua-Linn, author of Functional Programming Patterns in Scala and Clojure

Why did you write Functional Programming Patterns?
Languages with a functional flavor are getting more and more mainstream, and I wanted to write something that would help folks with a lot of traditional OO pattern knowledge start to make the transition.

I don't know Scala or Clojure. How hard would it be for me tounderstand the examples in the book?
This book is written for programmers who are new to Scala and Clojure, but who have significant experience with Java and object-oriented patterns. One of its goals is to help ease experienced object-oriented programmers into a more functional style.

What can I do with functional patterns I couldn't do before?
It's not so much what you can do, as what you can do better! Functional programming, and the patterns that go along with it, tends to be more declarative than imperative programming, so you can solve problems with code that's both more straightforward and shorter. The functional focus on immutable data reduces bugs in large programs, especially ones involving concurrency.

Functional programming has no place in the object-oriented world, does it?
While object-oriented programming and functional programming are often seen as opposite paradigms, the truth is a bit more complex. Even Java is getting more of a functional style with Java 8's Lambdas. Scala explicitly blends object-oriented and functional styles. While Clojure is explicitly not object-oriented, it does borrow many good ideas from the object-oriented world, such as polymorphism and programming to interfaces.

Which one should I use? Scala or Clojure? What are the differences andwhich would be easier to start with?
Scala tends to provide an easier on-ramp for object-oriented programmers, as they can start working with it in a mainly object-oriented style and transition to a more functional style as they gain more experience. Scala also has a sophisticated static type system, and blends object-oriented and functional programming together. Clojure, on the other hand, is a modern, practical Lisp and comes with the powerful macro system inherent to Lisps.

Both are excellent, general-purposelanguages, but I have to confess that I prefer Clojure. I find that I can write clear, concise code it in much more easily than I can in any other language. However, knowing both will give you a very broad understanding of modern languages with a functional flavor.

5 tips when you dive into the functional programming world

Tip 1: Look for opportunities to replace object-oriented patterns with simpler functional language features.

Tip 2: Don't be afraid to create functions that return functions.

Tip 3: Consider composing behaviors using higher order functions rather than building hierarchies.

Tip 4: Reach for higher order functions over collections before recursion.

Tip 5: You often don't need mutability, even when you think you do! Try to find a higher order function that helps you transform an immutable data structure into a new, immutable data structure rather than modifying it in place.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Functional Programming Patterns in Scala and Clojure by Michael Bevilacqua-Linn in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Algorithms. We have over one million books available in our catalogue for you to explore.

Information

Table of contents

  1. Functional Programming Patterns in Scala and Clojure
  2. For the Best Reading Experience...
  3. Table of Contents
  4. Early Praise for Functional Programming Patterns
  5. Acknowledgments
  6. Preface
  7. Chapter 1: Patterns and Functional Programming
  8. Chapter 2: TinyWeb: Patterns Working Together
  9. Chapter 3: Replacing Object-Oriented Patterns
  10. Chapter 4: Functional Patterns
  11. Chapter 5: The End
  12. Bibliography