Chris Lattner
๐ค SpeakerAppearances Over Time
Podcast Appearances
Also, it's called zero-cost exceptions, but it's not zero-cost by any stretch of the imagination because it massively blows out your code, your binary.
It also adds a whole bunch of different paths because of destructors and other things like that that exist in C++.
And it reduces the number of optimizations.
It has all these effects.
And so this thing that was called zero-cost exceptions...
It really ain't.
Now, if you fast forward to newer languages, and this includes Swift and Rust and Go and now Mojo.
Well, and Python's a little bit different because it's interpreted, and so it's got a little bit of a different thing going on.
But if you look at compiled languages...
many newer languages say, okay, well, let's not do that zero cost exception handling thing.
Let's actually treat throwing an error the same as returning a variant, returning either the normal result or an error.
Now, programmers generally don't want to deal with all the typing machinery and like pushing around a variant.
And so you use all the syntax that Python gives us, for example, try and catch, you know, functions that raise and things like this.
You can put a raises decorator on your functions, stuff like this.
And if you want to control that, and then the language can provide syntax for it.
But under the hood, the way the computer executes it, throwing an error is basically as fast as returning something.
And so this is actually, I mean, it's a fairly nerdy thing, right?
Which is why I love it.
But this has a huge impact on the way you design your APIs, right?
So in C++, huge communities turn off exceptions because the cost is just so high, right?