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
Closed

Constant (read-only) member functions #7908

DartBot opened this issue Jan 15, 2013 · 3 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot 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
Copy link
Member

lrhn commented Jan 15, 2013

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

@lrhn
Copy link
Member

lrhn 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
Copy link
Contributor

gbracha commented Jan 22, 2013

This is a rathole.


Set owner to @gbracha.
Added Accepted label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jan 22, 2013
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants