Skip to content

Update Chapter 12 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dwhitney opened this issue Jun 8, 2019 · 9 comments
Closed

Update Chapter 12 #29

dwhitney opened this issue Jun 8, 2019 · 9 comments

Comments

@dwhitney
Copy link
Collaborator

dwhitney commented Jun 8, 2019

No description provided.

@milesfrain
Copy link
Member

milesfrain commented Feb 1, 2020

The theme of this chapter, "Callback Hell", isn't a problem anymore for modern JS with async / await. The motivating problematic example can now be nicely written as follows:

async function copyFile(file1, file2) {
  var fs = require('fs');
  let data = await fs.readFile(file1, { encoding: 'utf-8' })
  fs.writeFile(file2, data, { encoding: 'utf-8' })
}

copyFile('file1.txt', 'file2.txt')
.catch(e => {
  console.log('There was a problem with copyFile: ' + e.message);
});

So I think a better focus of this chapter is "Asynchronous Effects". Some Aff content has already been added to Ch8 and should probably be moved to Ch12.

I'm hesitant to update these remaining sections to working code, since Aff would make all of this material so much simpler:

  • The Continuation Monad
  • Putting ExceptT To Work
  • A HTTP Client
  • Parallel Computations

I think @drewolson's blog posts on Aff would be a great foundation for this chapter. We could then add some more examples (copyFile and HTTP client) and exercises.

Drew, how do you feel about us using your writing for the PureScript book?

@drewolson
Copy link

I'd be honored if you'd like to use my writing for the book. I'm also happy to write more on specific topics (and cross-post to my blog) that you're interested in covering. Somehow this notification just showed up for me, apologies on the slow reply.

@milesfrain
Copy link
Member

I'd like to get preapproval from at least one @purescript-contrib member before jumping into the Chapter 12 overhaul.

@drewolson No worries about a late reply. I just edited the post yesterday with the blog proposal and tagged mention.

@milesfrain
Copy link
Member

@hdgarrood What are your thoughts on this proposal to rewrite Ch12 based on Drew's post?

@milesfrain
Copy link
Member

milesfrain commented May 25, 2020

This chapter could also benefit by incorporating @JordanMartinez 's guide on Aff too (purescript-contrib/purescript-aff#191).

I think our goal should be to have:

  • A concise (yet comprehensive) API reference in the Aff repo
  • A more spoon-fed guide with exercises on Aff in this chapter

@hdgarrood
Copy link

Your proposal sounds good to me. I agree that the "callback hell" issue discussed feels a bit dated these days, and that @drewolson's posts would be a good introduction. In the vast majority of cases, there's not really any reason to use ContT for asynchronous code, since Aff exists, so I'm not sure ContT deserves as much coverage in the book as it has currently. I'm not sure that @JordanMartinez's guide fits in the book, though; it focuses a lot on the fact that monads don't compose, which probably ought to be beyond the scope of the book, and shouldn't be necessary to teach people the basics of what Aff is and how to use it anyway.

@JordanMartinez
Copy link

I'm not sure that @JordanMartinez's guide fits in the book, though; it focuses a lot on the fact that monads don't compose, which probably ought to be beyond the scope of the book, and shouldn't be necessary to teach people the basics of what Aff is and how to use it anyway.

@hdgarrood Not necessarily. There's a number of things my guide covers. Only one part of that is the Effect-lifting one needs to do while in the Aff context. The rest covers Aff in a lot more detail. For example:

  • Basics, which covers how to run an Aff via launchAff and various ways to join a fiber
  • Lifting Monads, which covers how to run Effect in Aff
  • Node.ReadLine, which mainly covers how runAff and makeAff works.

I think the only thing not covered is how killing fibers works.

@hdgarrood
Copy link

Sure, but more isn't necessarily better. I definitely don't think we should cover the entire Aff API in the book; for example, I think we have about 280k lines of PureScript across our various projects in my day job, and I don't think we use Fiber explicitly at all. Ideally I don't think the chapter should end up very much larger than how it is now.

@JordanMartinez
Copy link

@hdgarrood Good points!
@milesfrain I think using Drew's post makes the most sense here. If anything, there could be a final "for more information, see X" where X could be any/all of the following:

  • Nate's video on Aff
  • My repo's explanation on Aff after I fix the "monads don't compose" issue
  • My repo's explanation on makeAff and runAff (though maybe these explanations should be ported to Aff itself...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants