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

Add: Example usage to fillRange method. #37313

Conversation

abhishekkanojia
Copy link
Contributor

No description provided.

@kevmoo
Copy link
Member

kevmoo commented Jun 19, 2019

@lrhn ?

@abhishekkanojia
Copy link
Contributor Author

@kevmoo Added one more commit which updates the insert method documentation.

@mit-mit
Copy link
Member

mit-mit commented Jul 1, 2019

@@ -674,6 +674,22 @@ abstract class List<E> implements EfficientLengthIterable<E> {
* A range from [start] to [end] is valid if `0 <= start <= end <= len`, where
* `len` is this list's `length`. The range starts at `start` and has length
* `end - start`. An empty range (with `end == start`) is valid.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for future reference: You can use the code-block syntax:

```dart
List<int> list1 = ...
etc...
```

It's easier to maintain than the old "four-space-indent" for code blocks, so I'd prefer that for new comments even if it's inconsistent with the surrounding code.

(No need to change the code already written, though, so this is fine).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted

@@ -464,7 +464,7 @@ abstract class List<E> implements EfficientLengthIterable<E> {
* This increases the length of the list by one and shifts all objects
* at or after the index towards the end of the list.
*
* An error occurs if the [index] is less than 0 or greater than length.
* A `RangeError` occurs if the [index] is less than 0 or greater than length.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not say whic error is throws. Instead replace this entire section by:

 * The list must be growable. 
 * The [index] value must be non-negative and no greater than [length].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this applies to insertAll method as well. I am updating it for that as well.

@@ -674,6 +674,22 @@ abstract class List<E> implements EfficientLengthIterable<E> {
* A range from [start] to [end] is valid if `0 <= start <= end <= len`, where
* `len` is this list's `length`. The range starts at `start` and has length
* `end - start`. An empty range (with `end == start`) is valid.
*
* List<int> list1 = new List(3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd start with:

 * 
 * Example:

to set the expectation.

Also, change list1 to just list, the "1" doesn't add anything to the example.

*
* List<int> list = new List();
* list.fillRange(0, 2, 1); // throws `RangeError: Invalid Value` exception.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of what not to do, which we try not to do (unless the error is particularly interesting, this one isn't).

I'd just drop this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this keeping in mind it as an extra note or gotcha while using the fillRange method. But with your suggested comment:
The list must be growable.
It give user a sense that using this method might result in some error.
I will go ahead and remove this example.

*
* List<int> list2 = new List()..length = 3;
* list2.fillRange(0, 2, 1);
* print(list2); // [1, 1, null]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is exactly the same as the first one, except that the list is growable. Since this function doesn't care about being growable, the example is not adding anything new. I'd remove this example too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Change: documentation for `insert` and `insertAll` method.
@mit-mit
Copy link
Member

mit-mit commented Jul 2, 2019

Thank for contributing @abhishekkanojia

@dart-bot dart-bot closed this in 9ed728e Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants