JEP draft: Scope Locals

Douglas Surber douglas.surber at oracle.com
Thu May 13 17:28:26 UTC 2021


In most of you examples the ScopeLocal could easily be replaced with a local variable.

    record Point(int x, int y) {}
    static final ScopeLocal<Point> position = ScopeLocal.forType(Point.class);

    {
        ScopeLocal.where(position, new Point(33, 66),
            () -> System.out.println(position.get().x()));
    }

could be written as

    record Point(int x, int y) {}

    {
        Point position = new Point(33, 66);
        System.out.println(position.x()));
    }

This works even if code that uses position is a lambda. This made the value of ScopeLocals unclear.

The CREDENTIALS example though does show the value of ScopeLocals, that CREDENTIALS can be dereferenced in the method connectDatabase() which is outside the lexical scope where creds is defined. It would help if the first example was along this line and clearly called out how a ScopeLocal (really a DynamicScopeLocal) is different from a lexically scoped local variable.

As written the JEP relies a bit too much on the reader having prior knowledge of ScopeLocal. Yes, the reference to special variables in LISP is descriptive, to those who know what it means. A significant number of readers will not. You are careful to distinguish ScopeLocals from ThreadLocals. Also distinguishing them from lexically scoped local variables would help.

Douglas Surber

On May 12, 2021, at 4:23 PM, loom-dev-request at openjdk.java.net<mailto:loom-dev-request at openjdk.java.net> wrote:

Date: Wed, 12 May 2021 15:42:21 +0100
From: Andrew Haley <aph at redhat.com<mailto:aph at redhat.com>>
To: "core-libs-dev at openjdk.java.net<mailto:core-libs-dev at openjdk.java.net>" <core-libs-dev at openjdk.java.net<mailto:core-libs-dev at openjdk.java.net>>,
loom-dev <loom-dev at openjdk.java.net<mailto:loom-dev at openjdk.java.net>>
Subject: JEP draft: Scope Locals
Message-ID: <d3137d65-44b4-182a-ab91-844f0e8114fe at redhat.com<mailto:d3137d65-44b4-182a-ab91-844f0e8114fe at redhat.com>>
Content-Type: text/plain; charset=utf-8

There's been considerable discussion about scope locals on the loom-dev list,
and it's now time to open this to a wider audience. This subject is important
because. although scope locals were motivated by the the needs of Loom, they
have many potential applications outside that project.

The draft JEP is at

https://bugs.openjdk.java.net/browse/JDK-8263012

I've already received some very helpful suggestions for enhancements to
the API, and it'll take me a while to work through them all. In particular,
Paul Sandoz has suggested that I unify the classes Snapshot and Carrier,
and it will take me some time to understand the consequences of that.

In the meantime, please have a look at the JEP and comment here.


For reference, earlier discussions are at

https://mail.openjdk.java.net/pipermail/loom-dev/2021-March/002268.html
https://mail.openjdk.java.net/pipermail/loom-dev/2021-April/002287.html
https://mail.openjdk.java.net/pipermail/loom-dev/2021-May/002427.html

--
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com<https://www.redhat.com/>>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671





More information about the loom-dev mailing list