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

Constant (read-only) member functions #7908

Closed
DartBot opened this issue Jan 15, 2013 · 3 comments

Comments

@DartBot
Copy link

commented Jan 15, 2013

This issue was originally filed by phlo...@gmail.com


I really like this feature from C++.

MSDN Constant member functions (http://msdn.microsoft.com/en-us/library/6ke686zh(v=vs.80).aspx):
"Declaring a member function with the const keyword specifies that the function is a 'read-only' function that does not modify the object for which it is called."

example C++ code:
class Foo
{
public:
...
   void bar() const; // Clear that it doesn't modify object
   void baz(); // Unclear on if it modifies the object
...
};

I would like to see some Dart equivalent.

@lrhn

This comment has been minimized.

Copy link
Member

commented Jan 15, 2013

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@lrhn

This comment has been minimized.

Copy link
Member

commented Jan 15, 2013

It sounds simple, but it isn't really if done right.
Even if there is only const annotations on methods, I'd assume that the const-ness is inherited. That means that subclasses overriding the method must also have const-only methods.
And what is the restriction: Only able to use getters and const methods on [this]? Or also on other objects? What if getters have side-effects? Does that mean that you can't call code that doesn't use const at all?

Should there be a way out of const-jail like C++'s const_cast? If not, it can get very restrictive.

@gbracha

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2013

This is a rathole.


Set owner to @gbracha.
Added Accepted label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.