Description
This issue was originally filed by le...@google.com
What steps will reproduce the problem?
- Use RegExp, get a Match
- Try to find out where it starts and ends:
main() {
Match m = new RegExp("h").firstMatch("hello");
print(m.start);
}
What is the expected output? What do you see instead?
Expected: 0 Got: Object
It is not conceptually a method, as I am not telling the Match to start something.
What version of the product are you using? On what operating system?
DartPad, Dart Editor
Please provide any additional information below.
From http://www.dartlang.org/articles/style-guide/
DO use a getter for operations that conceptually access a property.
If the name of the method starts with get or is an adjective like visible or empty that's a sign you're better off using a getter. More specifically, a getter should:
Not take any arguments.
Return a value.
Be side-effect free. Invoking a getter shouldn't change any externally-visible state (caching internally or lazy initialization is OK). Invoking the same getter repeatedly should return the same value unless the object is explicitly changed between calls.
Be fast. Users expect expressions like foo.bar to execute quickly.
You should also consider adopting naming conventions for distinguishing properties and methods while you can still get away with renaming APIs and breaking everyone's code; for example the .NET style guide states that properties should generally be nouns and methods should start with verbs. (http://msdn.microsoft.com/en-us/library/bzwdh01d(v=vs.71).aspx) This not only helps users distinguish them but it also helps writers think about which they are writing.
As an example, hashCode() could either be made a property, or, if the point of making it a method is to let the user know it does something, then its name should be changed to something that suggests that it does something, like getHashCode() or even computeHashCode(). Because properties are a feature of this language, methods should not be named like they are properties; that just causes people to closurize them all the time. Methods get these kinds of names in languages that don't have properties; fight these habits.