"Scoped Mutable Variables"
Chen Liang
chen.l.liang at oracle.com
Thu May 22 15:56:58 UTC 2025
Hello, I don't think this proposal "reduce unintended side effects caused by variable mutations in nested blocks". This massively decreases the readability of code. Your purposed problem can be solved by declaring new non-final local variables in the nested scopes and making the main local variable final, and there is no proof that your proposed problem actually happens in development. You can search for Static Single-Assignment form for more efficient usages of variables that is both more human and machine friendly. Also on a side note, Java Language feature discussions usually happen on compiler-dev list.
Regards, Chen Liang
________________________________
From: jdk-dev <jdk-dev-retn at openjdk.org> on behalf of Alaa Mohamed <333alaamo at gmail.com>
Sent: Wednesday, May 21, 2025 8:54 PM
To: jdk-dev at openjdk.java.net <jdk-dev at openjdk.java.net>
Subject: "Scoped Mutable Variables"
Dear OpenJDK Reviewers and Community,
I hope this message finds you well.
Please find attached my draft Java Enhancement Proposal (JEP) titled "Scoped Mutable Variables" (JEP XXXX), which introduces a new variable declaration modifier scoped. This modifier allows variables to be mutable exclusively within a limited lexical scope (such as inside if, for, or while blocks) without affecting the variable’s value in the enclosing or global scope.
This proposal aims to reduce unintended side effects caused by variable mutations in nested blocks, thereby improving code safety and readability in large-scale Java projects.
I would appreciate any feedback or suggestions you may have on the design, naming, integration approach, or any other aspect of the proposal.
Please find the full proposal text attached (or below).
Thank you very much for your time and consideration.
Best regards,
Alaa Mohamed
[Your email]
[ GitHub - alaa-333/scoped-variable-jep<https://github.com/alaa-333/scoped-variable-jep.git> ]
[ LinkedIn : https://www.linkedin.com/in/alaa-mohamed-1468a3304?lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_contact_details%3BOH8SwytOQoO2HCH0VxvdBA%3D%3D ]
Also for more details : Java Enhancement Proposal (JEP) (1).pdf<https://drive.google.com/file/d/1P-k9XfpRzLdnuOYUpBUFfPaHBGWHjM9z/view?usp=sharing>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20250522/58e8bd1a/attachment.htm>
More information about the jdk-dev
mailing list