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

"@" instead of "this." #10

Closed
yegor256 opened this issue Nov 12, 2016 · 8 comments
Closed

"@" instead of "this." #10

yegor256 opened this issue Nov 12, 2016 · 8 comments

Comments

@yegor256
Copy link
Member

How about we use @ sign in front of attribute names instead of this. (like in Java)? Sounds practical to me. This is how Ruby works.

@monsieurluge
Copy link

Is this keyword really usefull ?

I mean, if all the properties owned by the object are private and immutable, why should we add this keyword to access these properties ?

Same for the methods.

@mdbs99
Copy link
Contributor

mdbs99 commented Nov 14, 2016

@monsieurluge
Using a prefix like @ turns the code more readable.
But, I agree, if we want we can cut both (this and @) defining a pattern: All variable created inside the constructor, will be attributes. The only problem is a colision names between arguments and attributes.

@yegor256
Copy link
Member Author

@monsieurluge well, but what about method arguments? We have to distinguish them somehow from attributes:

Integer {
  int @value;
  void add(int value) {
    @value += value;
  }
}

See?

@monsieurluge
Copy link

Of course, but in many case it's just a naming convention issue.

"@" reminds me annotations. But, i agree that it's a very short way to see where are the object's properties.

If you want to keep a keyword, why not "self" ? The object is composed by its internal properties so the "self" keyword sounds better for me in an object oriented context.

@mdbs99
Copy link
Contributor

mdbs99 commented Nov 16, 2016

I like the word, self — because Object Pascal — but this isn't good. The same for this.
Sometimes developers will write self.value, sometimes not (because the argument name is just v). This is a inconsistence.

IMO It's better to use only one way, one style.

@mdbs99 mdbs99 mentioned this issue Nov 16, 2016
@yegor256
Copy link
Member Author

@mdbs99 I also like @ notation. It's explicit and can't be skipped.

yegor256 pushed a commit that referenced this issue Nov 17, 2016
@yegor256
Copy link
Member Author

pull request is here: #18 If there are no strong objectives, I will merge it

yegor256 added a commit that referenced this issue Nov 17, 2016
@yegor256
Copy link
Member Author

no objectives, merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants