NON-BREAKING CHANGE: Lazy initialization has landed!

Showing 1-4 of 4 messages
NON-BREAKING CHANGE: Lazy initialization has landed! Kasper Lund 9/14/12 6:34 AM
Dartisans,

We now have one of the major new language features of M1 implemented
across the board. That's right -- you can now use lazy initialization
for top-level and static variables (both final and non-final). This
means that the restriction that used to force the initialization
expression for such a variable to be a compile-time constant is no
more. You can now write:

  final worklist = new Queue();
  var compiler = new Compiler(worklist);

and both worklist and compiler will be initialized on first access.
We've also lifted the restriction for instance fields so the following
code now runs just fine:

  class Cache {
    final Map table = new Map();
    ...
  }

as long as the initialization expressions do not refer to [this]. Such
expressions are evaluated when the object is created (not lazily on
first access as we do for static and top-level variables), but it cuts
down on the need for lengthy initializer lists in your constructors.

Cheers,
Kasper
Re: [dart-misc] NON-BREAKING CHANGE: Lazy initialization has landed! Paul Brauner 9/14/12 6:42 AM
Awesome! I can now simplify the API of dart-enumerators.

On Fri, Sep 14, 2012 at 3:34 PM, Kasper Lund <kas...@google.com> wrote:
Dartisans,

We now have one of the major new language features of M1 implemented
across the board. That's right -- you can now use lazy initialization
for top-level and static variables (both final and non-final). This
means that the restriction that used to force the initialization
expression for such a variable to be a compile-time constant is no
more. You can now write:

  final worklist = new Queue();
  var compiler = new Compiler(worklist);


A very random example ;)
 
and both worklist and compiler will be initialized on first access.
We've also lifted the restriction for instance fields so the following
code now runs just fine:

  class Cache {
    final Map table = new Map();
    ...
  }

as long as the initialization expressions do not refer to [this]. Such
expressions are evaluated when the object is created (not lazily on
first access as we do for static and top-level variables), but it cuts
down on the need for lengthy initializer lists in your constructors.

Cheers,
Kasper

--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart



Re: NON-BREAKING CHANGE: Lazy initialization has landed! John Evans 9/14/12 8:12 AM
Huzzah!! So happy about this!  Great work Dart team.
Re: [dart-misc] Re: NON-BREAKING CHANGE: Lazy initialization has landed! Bob 9/14/12 9:49 AM


On Fri, Sep 14, 2012 at 8:12 AM, John Evans <pru...@gmail.com> wrote:
Huzzah!! So happy about this!  Great work Dart team.

Me too! :D

- bob
 
--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart