8

A Skeptic’s Guide to Functional Programming with JavaScript

 1 year ago
source link: https://jrsinclair.com/skeptics-guide
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
cover-smaller.jpg

What if the team hates my functional code?

So you learned some functional programming. And it’s glorious! Your JavaScript is cleaner; more concise; elegant. It feels solid. You can’t wait to share it with the team. So you throw up a PR and wait for the comments to come in; eager to hear what they think.

And those comments come in all right. But they’re not complimentary. It starts slowly, but soon they’re flying in like a hailstorm of bullets:

  • This code is so elegant it’s impossible to read.
  • Recursion in JavaScript performs like absolute garbage.
  • I’ve never seen a single situation where currying improves the code. Why is this useful?
  • Trying to do immutable data in JS is just painful.
  • Bloated ivory tower rubbish.

It’s not what you expected. And you’re stuck. Frozen like a deer in the twin beams of an oncoming semitrailer. How do you even begin to respond to all this? Some of the team’s objections are reasonable. But which ones? Some of their comments are based on nothing but myth and personal bias. But, again, which ones? And how can you have an intelligent, reasonable conversation about it?

It’s like you’re caught in a trap. You know functional programming produces better code—even in JavaScript. You can’t go back to the old way of doing things. But the rest of the team don’t get it. There has to be a way to at least talk about this without starting some kind of blood feud. But how?

Trying to introduce functional concepts can feel like navigating a minefield. Especially when the team seems dead-set against it. But it doesn’t have to be that way. It’s possible to find safe paths.

Level up your code and bring your team on the journey with A Sceptics Guide to Functional Programming with JavaScript. Learn how to adjust your code to suit the team’s level of familiarity. Spot performance pitfalls. Use functional techniques to apply performance optimisations with guaranteed safety. Sort the myths from reality. Write functional JavaScript with confidence.

You can learn to defend your code intelligently and diplomatically. And write expressive, elegant code you can be proud of.


For a limited time, get $10 off either the eBook or the paperback bundle.

Get the book through my Shopify online store, or use one of the buy buttons below.

Prices are listed in USD, unless otherwise specified (see note below).


Answers to questions that I imagine I would ask, if I were buying a book

  • Hey! The price changed when I went to check out. Yeah, I’m really sorry about that. Shopify doesn’t allow you to automatically display local currency on an embedded purchase widget. So, it defaults to USD, then updates it once you set a shipping location. If it’s of concern, you can purchase through the online store, and it should show you the correct price before you check out.

  • What format(s) does the eBook come in? The eBook comes in ePub and PDF formats. Both should work okay with common eBook readers like Apple Books and Kindle. Though, if you’re reading on an actual computer, I recommend Calibre. It’s free. And it has much better typographic support than either Apple Books or Kindle. You can also use it to convert ePub files to other formats if you have a legacy device.

  • How many pages in the paperback book? The paperback has a total of 288 pages.

  • Can I contact you if I’m having trouble purchasing? Yes, send me an email and I’ll get back to you as soon as I can.

  • What’s in it? Can I see a table of contents? Sure. But to save space, I’ll stick the table of context into an expando-box:

    Table of Contents
    1. A Skeptic’s Guide to Functional Programming with JavaScript
      1. Introduction
        1. Who is this book for?
        2. What will you get out of this book?
        3. How this book is organised
      2. What’s so great about functional programming anyway?
        1. Algebraic structures
        2. Maybe
        3. Result
        4. So you used polymorphism. Big deal.
        5. So what?
      3. Functional programming makes JavaScript unreadable
        1. Currying
        2. Point-free style
        3. Readability, familiarity, and expressivity.
        4. Freedom of expression
        5. Great, tell that to my team full of haters
        6. But, my team still has to read my code
      4. Functional programming harms performance: Recursion
        1. Recursion
        2. Measure
        3. Performance and referential transparency
      5. Functional programming harms performance: Immutable data
        1. But, why?
        2. Immutable data and the virtual DOM
        3. Memoization
        4. Records and tuples
        5. What do we do in the meantime?
        6. But, performance matters
      6. JavaScript isn’t a functional language
        1. Don’t choose JavaScript if you want to learn functional programming
        2. Functional programming in JavaScript can be frustrating
        3. Functional programming with JavaScript is a cargo cult
        4. How to talk about it
      7. Functional programming is hard
        1. Functional programming is hard to learn
        2. The jargon problem
        3. The unlearning problem
        4. The beauty problem
        5. The snobbery problem
        6. Functional programming is hard work
      8. What’s so great about functional programming (again)?
        1. Functional programming produces more expressive code
        2. Functional programming gives us more confidence in our code
        3. Conclusion: What do we do?
    2. Appendices
      1. What are higher-order functions, and why would anyone care?
        1. Functions as first-class citizens.
        2. What is a higher-order function?
        3. Examples of higher-order functions
        4. So what?
      2. The marvellously mysterious JavaScript Maybe monad
        1. A quick recap of Promises
        2. A problem to solve
        3. The Maybe monad
        4. Maybe of a Maybe? Maybe not.
        5. But what do you do with it?
        6. Pointfree style
        7. Pipelines
        8. Further reading
      3. Elegant error handling with the JavaScript Either Monad
        1. A sample problem
        2. Exceptions: The good parts
        3. Problems with try…catch exception handling
        4. Coming up with an alternative
        5. Polymorphism
        6. Left and right
        7. Really? Is that it?
        8. Further reading
      4. How to deal with dirty side effects in your pure functional JavaScript
        1. Dependency injection
        2. Lazy functions
        3. The effect functor
        4. So What?
        5. Summary
      5. Recursion performance measurements
        1. Recursive array map performance
        2. Recursive array map performance with immutable data structures
        3. Recursive DOM traversal
      6. Acknowledgements

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK