text
stringlengths
0
1.36k
**Mikeal Rogers:** \[08:11\] No, it was Denicola.
**Alex Sexton:** Yeah, Denicola.
**Mikeal Rogers:** And Kris Kowal.
**Alex Sexton:** Yeah, Kris Kowal, that's the wizard. Yeah, so all the Promises A, plus all that kind of stuff... It was right when people were like "Okay, we definitely want this set of bags of tools and we should standardize it."
I think that's when the front-end world finally -- a lot of the front-end stuff actually... They got around it in different ways. Rather than putting handlers whenever you get data, a lot of the stuff is just like automatically updating. We didn't actually solve any control flow async stuff, it was just like the way th...
There are so many cases in asynchronicity that you have to handle, like loading error states, completion states with errors versus completion states that are successful... There's just so many things that by default you just think "Oh, I wrote this code and it'll be perfect every time." It just adds so much unknown, an...
**Kyle Simpson:** I have a throwback reference that I think at least some listeners would maybe appreciate. This is a metaphor I use to describe the state of managing state over time. I remember way, way back in 1986 when the original Nintendo came out, and I still think the best game ever made, Legend of Zelda on the ...
**Kyle Simpson:** Exactly.
So you could move around the whole map, but you couldn't see the whole map at once. That is to me what modern JavaScript applications and asynchronous programming are. We can understand this one little part; I can understand these two or three steps of the flow control, but then it forks over to this other part, and as...
I think that's a big contributor to why people keep trying to reinvent the wheel with frameworks; it's because we didn't really solve one of the core problems, that we can't with the language - or we couldn't for a long time - express sophisticated flow control in a way that people are gonna be able to read. So we just...
**Alex Sexton:** Yeah, I agree with that.
**Mikeal Rogers:** So there's been a lot of work that's happened on this over the past few decades. We had a discussion a few episodes back about if you're learning JavaScript today, is there any reason to even learn the function keyword, or should you just go straight to arrow functions and just be done with it? When ...
**Alex Sexton:** \[12:15\] I don't think it's necessarily an equivalent thing to arrow functions, to all functions... Because there are times when you still need the old thing, whereas theoretically you could completely replace the async control flow stuff -- or, sorry, I'm not talking any sense. I guess what I mean is...
**Kyle Simpson:** People are gonna have different answers on that one for sure, they will have a lot of different opinions among those that are listening, and I'm sure many of my peers in the teaching world have strong opinions on it. Speaking for myself only, I do teach the fundamentals. I teach a course called "Rethi...
Then we talk about thunks. The reason for thunks is because they are a really good conceptual base for promises, and the reason promises are useful is because generators can let you do the sync/async thing. I build from the ground up, not that I expect that people will write lots and lots of callbacks still, or will ev...
**Mikeal Rogers:** You kind of glossed over some of the other fundamental problems with callbacks... What are some of those issues? In Node core right now there's actually an argument about "How do we make promises as good as callbacks are for a lot of the debugging stuff and a lot of the error tracking stuff that we h...
**Kyle Simpson:** I would say to me there are three main drawbacks that callbacks alone don't solve. The first one is that callbacks, unless you introduce a pattern like a thunk or something with closure, the callbacks don't have any memory, they don't have any way to pair state with them, and managing state over time ...
The callback -- you just pass in a callback to a function and latently close over some state object is not good enough for the kinds of complexity that we're typically modeling. The second major drawdown...
**Mikeal Rogers:** So hold on, I wanna dig into that just a little bit more. I wanna explain a little bit deeper, so that some of the newer listeners can follow as well... So when you create a callback, you create this sort of inline function, and if you reference any variables on the top, those get closed over; that's...
**Kyle Simpson:** \[15:56\] There is that aspect, you're absolutely right, but I think I'm going at something even deeper, and some of this is that I've over the last few years become a lot more interested in applying functional programming concepts. When you just willy-nilly close over variables out of any scope, and ...
Now, closure itself is not anti-functional programming, it's actually right at the heart of functional programming. But when you use closure in functional programming, you have to close over something that isn't gonna change. If you close over something that is going to change, you're asking for all of the problems tha...
That makes composing, as you said earlier, those different pieces, those functions with each of their different states closed over - composition of those is a lot easier when that state doesn't change. So that's what I mean by a callback by itself is not a great pattern for that. But when you apply some extra formality...
**Alex Sexton:** Yeah, I definitely agree that, even in the promises case, we're almost always generally adding more state and more process around any async action, to the point where there are still fundamental pieces, but we need things like -- the actual async action might not be cancelable if it's a promise, but we...
So I guess, to some extent, if I'm often wrapping promises in a certain way, then I guess I could wrap callbacks in that same way and manage all that state with the thunk, and that kind of stuff, and I suppose that's fine. But it seems to me I always need at least as much state as promises give me, in any complex appli...
**Mikeal Rogers:** And the states that promises have are just success & error, right? But you know, it also says if it's done doing the action or not.
**Alex Sexton:** Sure.
**Kyle Simpson:** Yeah, the done is implicit in whether or not there has been a resolution to success or error, but as of yet, promises don't have a canceled state, so as Alex is saying, people create ad-hoc wrappers on top of promises to represent that particular... And I think there's at least some that believe - and...
Alex, I think your point is taken - that state is necessary, and that's the whole reason why I tell people, look at the pain of all of the ad-hoc stuff you have to do when all you have is a callback. Then when you put a promise on, see how much of that you don't have to do anymore. Then when you put an observable on to...
\[20:24\] The second problem that I believe plagues callbacks is inversion of control. And by the way, inversion of control as a general concept is actually generally a good thing. Martin Fowler says that's the difference between libraries and frameworks, it's inversion of control. I think that's a good thing. But spec...
One of my getaphise laws, if you will, is "Code that you don't trust is code that you don't understand, and vice-versa." So I think that inversion of control problem is a big deal, and promises are actually really well designed to fix that, because promises un-invert that; instead of me passing a callback to you and yo...
The third one is a little softer to describe, but it's essentially that callbacks - the syntax promotes a very non-local, non-sequential reasoning, but the way our brains work... Neuroscientists tell us that our brains are very synchronous at the highest level of cognition; the way we plan things out is very sequential...
You hear people talk about observables and things like functional programming being more declarative - it's because we can list out a flow control in a program in a much more linear way. My preference is the synchronous style that you get out of async/await style functions. That works a lot closer to the way our brains...
So those I think would be the three things that I consider to be callback hell.
**Mikeal Rogers:** Alright, I think that's pretty good. I can definitely say this has been really enlightening. I think we got a lot of the good arguments out. I personally will continue to use callbacks because my brain is broken, I guess.
**Alex Sexton:** Yes.
**Mikeal Rogers:** It's just better... \[laughs\] We're gonna take a break now, and when we come back we're gonna talk a little bit about the future of the web and who's trying to kill it.
**Break:** \[23:24\]
**Mikeal Rogers:** Let's talk a bit about the web. There was an interesting thread recently from Joe Hewitt on Twitter... For those of you that are newer to programming, did not use Firebug back in the day, a long precursor to the Chrome DevTools was this Firefox plugin called Firebug. It introduced really the first we...
Generally, I don't think that Joe has to work anymore, I think that he's pretty set... But he's a really ardent defender of the web; he really tries to make sure that the web is going to win, and really sees it as being attacked on all sides right now, and probably not going to move into the future, and that we're gonn...
**Kyle Simpson:** Well, where do we start...? First off, I didn't follow that thread. Some people that follow me know that a while back I kind of stepped away from Twitter, so I did not follow that particular thread and it sounds like, just doing a quick Google search, that I'm probably glad I didn't, because I might h...
To me, that's what an open web means - a web that we are a part of the future of that; it's not just being dictated to us. If you compare that to - and I'm old enough and have been around long enough to remember vividly and have participated in a web where we were just handed the web by what Adobe shipped to us in Flas...
\[27:45\] We now are in control in the sense that anyone of us can participate in the specification bodies, for example. We can go participate in W3C, or WHATWG, or whatever specification bodies for web platform features; you can participate in discussions around TC39, maybe even get invited to one of their meetings or...
**Mikeal Rogers:** I wanna challenge just even the presumptions that you've already laid out. First of all, Firefox has lost a lot of market share, and a lot of people don't really see Mozilla pushing at the forefront of a lot of new standards, because they're so resource-constrained. A lot of new standards now are bei...
On the standards front--
**Kyle Simpson:** Well, wait a minute... We've gotta give credit to Microsoft Edge, because they're a whole lot more present in that discussion than they ever were before, and they deserve credit there.
**Mikeal Rogers:** Yes, I apologize... Yes.
**Kyle Simpson:** And I don't know that we should be so quick to throw Firefox under the bus either, because...
**Mikeal Rogers:** No, I mean, they're losing market share, and that has a real impact on how much that they can really do. Things aren't looking very great. I still have a lot of love in my heart for Mozilla having worked there and really believing in that institution, but to say that they are not hurting right now wo...
Yes, I apologize - Edge is doing an awesome job. In particular, they're pushing a lot of offline use cases and stuff like that right now too, so they're doing great work. But I really wanna challenge these standards part. The W3C in particular has a structure in which members buy seats, and part of buying a seat at a c...
**Alex Sexton:** I think to be fair, Apple would be able to scare the W3C away from implementing touch standards, regardless of whether they're a member or not. I don't think it was their member status that made that hard, I think it was the fact that they have a bunch of lawyers.
**Mikeal Rogers:** I actually don't agree. We step on open patents all the time in web standards, and one of the things that standards bodies try to do is get all of those companies to agree to -- yes, they get them to agree to not assert those patents, but there are also outside patents.