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

Semantic of the const keyword #7

Closed
gallandarakhneorg opened this issue Feb 6, 2014 · 2 comments
Closed

Semantic of the const keyword #7

gallandarakhneorg opened this issue Feb 6, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@gallandarakhneorg
Copy link
Member

Is the semantic of the keyword "const" coming from the "const" in C++, "const" or "immutable" in D, "const" or "readonly" in C#, or "final" in Java?

The code from the "counting" demo indicates that the semantic of "const" is the same as the semantic of "final" in Java:

const AtomicInteger count = new AtomicInteger
...
count.incrementAndGet 

It may be confusing for developers because "const" means "read only" for most of them.

Moreover, it seems correct to write with the current semantic:

const BigInteger abc = new BigInteger(4)
abc.add(6)

I think it is in contradiction with the use of "const" in the other programming languages. The following "equivalent" code is not working with these languages:

const int abc = 4;
abc = abc + 4;
@srodriguez
Copy link
Member

I agree that "const" may not be best choice.
Just to notice, the code

const int abc = 4;
abc = abc +4;

Will also fail on SARL, since you can't assign abc twice.

Following our exchange on the subject we will use the keyword val instead of const

@srodriguez srodriguez self-assigned this Feb 13, 2014
@srodriguez srodriguez added this to the 0.1.0 milestone Feb 13, 2014
@gallandarakhneorg
Copy link
Member Author

Approved.

srodriguez added a commit to sarl/sarl-demos that referenced this issue Feb 13, 2014
Updates demos to use `val` keyword instead of `const` (sarl/sarl#7).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants