Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occurences in Java. Don't expose setters for Scope vars. #11464

Merged
merged 4 commits into from
Nov 1, 2024

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Oct 31, 2024

Pull Request Description

Another change motivated by work on #11365. Continuation of #11419.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
  • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Oct 31, 2024
@JaroslavTulach JaroslavTulach self-assigned this Oct 31, 2024
@JaroslavTulach JaroslavTulach changed the title Don't expose setters for Scope variables Occurences in Java. Don't expose setters for Scope vars. Oct 31, 2024
public abstract String symbol();

/** The definition of a symbol in the aliasing graph. */
public static final class Def implements GraphOccurrence {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not declare it as record? It used to be sealed case class in Scala.

Copy link
Member Author

@JaroslavTulach JaroslavTulach Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with record is that all (default) constructor fields are publicly accessible. I plan to control the encapsulation more in some subsequent changes. Thus I went the more verbose way and created a class.

var childScopes: List[Scope] = List(),
var occurrences: Map[Id, GraphOccurrence] = HashMap(),
var allDefinitions: List[GraphOccurrence.Def] = List()
private[Graph] var _childScopes: List[Scope] = List(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this refactoring. Why not simply define these fields as private var childScopes: List[Scope] = ... without the rename and define public plain old getters?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only guessing but it looks like he wanted to limit the scope of variables so that one does not accidentally mutate them? But yes, the motivation is unclear.

Copy link
Member Author

@JaroslavTulach JaroslavTulach Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title of this PR is:

Don't expose setters for Scope vars.

Renaming the fields to private var _xyz and adding def xyz = _xyz achieves that goal. If there is a better way in Scala to have public getters, but private setters, feel free to propose it.

@enso-bot
Copy link

enso-bot bot commented Nov 1, 2024

Jaroslav Tulach reports a new STANDUP for today (2024-11-01):

Progress: .

- Summary of vacation work
- Mon:
   - benchmarks aren't compiling: 
   - no `Scope.flattenToParent`: 
- Tue:
   - PR integrated: https://github.com/enso-org/enso/pull/11393
   - Cannot have argument b and local variable b anymore: 
   - Give IfThenElseNode a location: 

- Thu:
   - talking with Pavel about `IfThenElse` scopes
   - trying various approaches to scopes
   - more of encapsulation: https://github.com/enso-org/enso/pull/11464
   - rewriting `GraphOccurrence` to Java: 

- Fri:
   - Fixing `runtime-integration-tests`:
   - PR integrated: https://github.com/enso-org/enso/pull/11464 It should be finished by 2024-11-04.

Next Day: Vacation is over. Back to work.

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label Nov 1, 2024
@mergify mergify bot merged commit 4cb943b into develop Nov 1, 2024
40 of 41 checks passed
@mergify mergify bot deleted the wip/jtulach/EncapsulateSetters11365 branch November 1, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants