« Return to Thread: Question on lazy val

Re: Question on lazy val

by Nils Kilden-Pedersen :: Rate this Message:

Reply to Author | View in Thread

On Fri, Jun 6, 2008 at 5:18 AM, David MacIver <david.maciver@...> wrote:

I'm not sure how to answer this question. I get confused by questions
of the form "Why do you do it this way? Couldn't you have done it a
more complicated way instead?"

That's not the question. The question is "Why do you do it this way? Couldn't you have done it a more perfomant way instead?"
I like elegant code as much as the next guy, but when building a language compiler, I just think there are more important concerns than the code looking good or having minimal complexity. It's about providing features that hopefully will help thousands of programmers and do so in a way that will not require them to write custom code because it performs poorly in a given situation.
I think a good analogy to Java is the synchronized keyword. With Java 1.5 we were given ReentrantLock, a class that performed faster than the native monitor mechanism. Granted, the Lock interface provided some possibilities that wasn't available with the keyword, but in many cases it replaced synchronized merely for it's performance advantage, increasing complexity for the average programmer, because a language keyword didn't perform optimally.
As most know, with Java 6 synchronized is now as fast, if not slightly faster, than ReentrantLock, and maybe Scala's lazy keyword will go through the same process. I'd rather just see it perform optimally from the beginning.

 « Return to Thread: Question on lazy val