-
-
Notifications
You must be signed in to change notification settings - Fork 747
Added pattern migration guide to the change log #5493
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
Conversation
7ac4f9b to
6566128
Compare
changelog/pattern-deprecate.dd
Outdated
|
|
||
| If you still need to use these, please see $(LINK2 https://github.com/dlang/undeaD, undeaD). | ||
|
|
||
| Here's a simple guide on how to migrate your existing code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid "Here's X" and adjectives describing the text itself ("simple"); consider: "Examples of the deprecated functions, and their modern replacements:"
changelog/pattern-deprecate.dd
Outdated
| s.munch(whitespace); | ||
|
|
||
| // new | ||
| size_t i = s.byCodeUnit.countUntil!(a => !isWhite(a)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not have skipOver with one argument + alias? Maybe we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s = s.find!(a => !isWhite(a)); ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Ever shorter: s = s.find!(not!isWhite);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but now you need to import std.functional (overall more key strokes) 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/CyberShadow/AutoFix + https://dump.thecybershadow.net/16b165ae82f44e8b0cb61975ace6ecb6/my-dfix.el = I forgot what writing imports manually is like :)
|
|
||
| // new | ||
| bool flag = !"x".matchFirst(regex("[a-z]")).empty; | ||
| ------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// old
if (inPattern('x', "a-z")) { ... }
// new
if ("x".matchFirst(regex("[a-z]"))) { ... }Avoids the awkward bool conversion.
changelog/pattern-deprecate.dd
Outdated
| "hello".squeeze; | ||
|
|
||
| // new | ||
| "hello".unique; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fairly sure this should be uniq, not unique.
6566128 to
b3a2c08
Compare
|
@CyberShadow Fixed |
|
Looks nice, though it's a bit weird how it's using expressions without side effects as statements on their own, as if they mutate the string like the first example. What do you think? |
b3a2c08 to
6b32ac2
Compare
|
@CyberShadow I guess that's just part of understanding range code. I've added a note just in case. |
Changelogs are one part of the website that people unfamiliar with D are likely to check, to see how the language is evolving in the present day. So I think we shouldn't be scarce on clarity there. Better than a note, would be to simply assign them to a dummy variable. |
changelog/pattern-deprecate.dd
Outdated
|
|
||
| The following are examples of the deprecated functions, and their modern replacements. | ||
| Note that the new code is based on the range model, and therefore does not have | ||
| mutate against the original string, unlike the old code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just wrong. removechars, squeeze and munch all return a string; only munch also takes the argument by value and mutates it. inPattern doesn't return/mutate a string at all.
I think it's better to remove this note and illustrate the example with dummy variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| $(REF munch, std, string): | ||
| ------- | ||
| import std.algorithm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: There's a new RUNNABLE_EXAMPLE macro, e.g.:
$(RUNNABLE_EXAMPLE
---
// my executable code
---
)
|
Thanks a lot for doing this @JackStouffer! This should be targeting |
|
Won't be able to get back to this until Monday. Vacation awaits! |
|
Thanks for your pull request, @JackStouffer! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
- also add ref to replacement function
6fa620f to
29b5a68
Compare
|
Thanks @MartinNowak for handling this. |
Ping @andralex @wilzbach