I mean, it's great that it's not me, but it's not free either, right?
Also absolutely correct.
This shows up best in the Scala world in the form of "lazy val" -- basically, a value that will be computed the first time somebody tries to access it, and is then a constant from then on. Seems easy, right? Folks (including me) litter their code with these things -- it's a core piece of the language.
But in fact, doing this *correctly* -- such that it works in a multi-threaded environment, with confident guarantees that it will only run once, without deadlocks, as efficiently as possible -- is *crazy* difficult, so much so that this language construct has been re-implemented several times over the past fifteen years, and we still don't have it quite right.
Granted, concentrating the bug exposure in the compiler instead of distributing it among all programmers means that when a bug is found it's more likely to get fixed and benefit everyone. I'm not sure I'd want to be on the team that has to make that work, though.
Yep. This is why many of us are deeply grateful to the folks who make the compilers hum along, hiding many of these nasty details under the hood so that we can peacefully get along with our application programming.
(no subject)
Date: 2019-05-09 12:10 pm (UTC)Also absolutely correct.
This shows up best in the Scala world in the form of "lazy val" -- basically, a value that will be computed the first time somebody tries to access it, and is then a constant from then on. Seems easy, right? Folks (including me) litter their code with these things -- it's a core piece of the language.
But in fact, doing this *correctly* -- such that it works in a multi-threaded environment, with confident guarantees that it will only run once, without deadlocks, as efficiently as possible -- is *crazy* difficult, so much so that this language construct has been re-implemented several times over the past fifteen years, and we still don't have it quite right.
If you'd like a sense of just *how* crazy it is, see this proposal to get it entirely right. It's daunting.
Yep. This is why many of us are deeply grateful to the folks who make the compilers hum along, hiding many of these nasty details under the hood so that we can peacefully get along with our application programming.