Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Add some extra functionality. #34

Merged
merged 7 commits into from
Sep 22, 2020
Merged

Add some extra functionality. #34

merged 7 commits into from
Sep 22, 2020

Conversation

@lrhn lrhn requested review from jakemac53 and mit-mit September 7, 2020 12:20
CHANGELOG.md Outdated
@@ -1,8 +1,15 @@
## 1.2.0-nullsafety
Copy link
Contributor

Choose a reason for hiding this comment

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

There hasn't been a stable 1.1.0 release yet - I would just do 1.1.0-nullsafety.3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Characters characterAt(int position) {
var breaks = Breaks(string, 0, string.length, stateSoTNoBreak);
var start = 0;
findIndices:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am personally not a fan of using labels in dart - they are just really uncommon and thus can be confusing or require additional research to understand exactly what they do (I had no idea you could even use them to break out from a whole block like this).

Consider just inlining the two throw statements instead of doing break findIndices; which really just throws - or call a method that throws. That has a lot more straightforward/explicit behavior imo.

Copy link
Contributor Author

@lrhn lrhn Sep 9, 2020

Choose a reason for hiding this comment

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

With that attitude, there won't ever be common use of labels 😉 .

This code is probably just as good with inlined throws. Will do.

FYI: You can label any statement, and you can break any surrounding label. It only really makes sense for composite statements (but you can write foo: break foo;). In that way, Dart precisely copied Java and JavaScript, so it's not anything fancy. Since Dart does not have loop else branches, like Python, I sometimes write what should be for (...) { ... if (...) break; ... } else { ... else code ... } as:

outer: {
  for (...) {
     ...
     if (...) break outer; 
     ...
  }
  ... else code ...
}

return StringCharacters(string.substring(0, endIndex));
var end = breaks.nextBreak();
if (end < 0) break findIndices;
;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That ; looks unnecessary :)

Characters characterAt(int position) {
var breaks = Breaks(string, 0, string.length, stateSoTNoBreak);
var start = 0;
findIndices:
Copy link
Contributor Author

@lrhn lrhn Sep 9, 2020

Choose a reason for hiding this comment

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

With that attitude, there won't ever be common use of labels 😉 .

This code is probably just as good with inlined throws. Will do.

FYI: You can label any statement, and you can break any surrounding label. It only really makes sense for composite statements (but you can write foo: break foo;). In that way, Dart precisely copied Java and JavaScript, so it's not anything fancy. Since Dart does not have loop else branches, like Python, I sometimes write what should be for (...) { ... if (...) break; ... } else { ... else code ... } as:

outer: {
  for (...) {
     ...
     if (...) break outer; 
     ...
  }
  ... else code ...
}

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

I think dartfmt changed a bit so it looks like the example needs to be formatted again to fix travis, otherwise lgtm

Travis won't run tests with the current set-up, the source span gets a version which doesn't work.
Try a later SDK version to see if that helps.
pubspec.yaml Outdated
@@ -5,7 +5,7 @@ homepage: https://www.github.com/dart-lang/characters

environment:
# This must remain a tight constraint until nnbd is stable
sdk: '>=2.10.0-78 <2.10.0'
sdk: '>=2.10.0-137 <2.10.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this might be past the 2.10 stable branch point (and never included in 2.10)

Copy link
Contributor

Choose a reason for hiding this comment

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

See dart-lang/sdk#43485, also please mention there that you also were mislead by this

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 wasn't actually misled, I was just guessing wildly at why Travis gives errors in the sourcespan package, so I updated to the same SDK version as that package. Didn't work, will revert.

@lrhn lrhn merged commit 0e910d0 into master Sep 22, 2020
@natebosch natebosch deleted the fix-issues branch September 22, 2020 14:57
mit-mit added a commit to mit-mit/characters that referenced this pull request Jul 26, 2021
mosuem pushed a commit to dart-lang/core that referenced this pull request Oct 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Small name changes
2 participants