Added pattern migration guide to the change log#5493
Added pattern migration guide to the change log#5493MartinNowak merged 2 commits intodlang:stablefrom
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.
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.
Do we not have skipOver with one argument + alias? Maybe we should.
There was a problem hiding this comment.
There was a problem hiding this comment.
s = s.find!(a => !isWhite(a)); ?
There was a problem hiding this comment.
Nice! Ever shorter: s = s.find!(not!isWhite);
There was a problem hiding this comment.
Agreed, but now you need to import std.functional (overall more key strokes) 😢
There was a problem hiding this comment.
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.
// 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.
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.
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.
|
|
||
| $(REF munch, std, string): | ||
| ------- | ||
| import std.algorithm; |
There was a problem hiding this comment.
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