Menu
Sign In Search Podcasts Libraries Charts People & Topics Add Podcast API Blog Pricing

Anders Hejlsberg

๐Ÿ‘ค Speaker
701 total appearances

Appearances Over Time

Podcast Appearances

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And then when my result is ready, then I can come back and continue executing here.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

Well, in order to do that in

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

in an inverted architecture like that you have to build a state machine and state machines are notoriously hard for for people to implement because you've got to move all of your state off of the stack into objects you've got to remember where and then you have this big case statement that envelopes your entire logic and it's it's like it's a nightmare to to figure out right but the transformation from

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

serially executing code into a state machine, this continuation processing style translation, is actually one that you can do in a machine-based fashion.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

You can have the compiler write the state machine if you introduce syntax that allows you to indicate where you want to yield.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And that's what await is.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

Await is basically, I'm saying, I want to yield here, and then when, and I want

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

to yield this promise.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And then when the promise completes, I want you to come back here and continue executing.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And then the compiler writes a state machine around it.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And it actually turns it into this big switch statement, you know, and moves all of the state that survives across the await into something that's heap allocated so it can be brought back.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And doing all of that work is something that compilers are great at.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And so that was sort of the idea that

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

We have this new style of programming where we're using promises or the equivalent of promises and the ability to yield, and then we have callbacks.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

But trying to write your program in that style, that's also what JavaScript suffers from a lot, right?

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

It's like all this...

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

callback style stuff.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And with async await, you get sort of the illusion that you're just writing normal sequential code.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And then the compiler does the painful transformation for you.

The Pragmatic Engineer
TypeScript, C# and Turbo Pascal with Anders Hejlsberg

And that turns out to be really useful.