Skip to content

Conversation

@JackStouffer
Copy link
Contributor


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.
Copy link
Member

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:"

s.munch(whitespace);

// new
size_t i = s.byCodeUnit.countUntil!(a => !isWhite(a));
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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)); ?

Copy link
Member

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);

Copy link
Contributor

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) 😢

Copy link
Member

Choose a reason for hiding this comment

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


// new
bool flag = !"x".matchFirst(regex("[a-z]")).empty;
-------
Copy link
Member

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.

"hello".squeeze;

// new
"hello".unique;
Copy link
Member

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.

@JackStouffer
Copy link
Contributor Author

@CyberShadow Fixed

@CyberShadow
Copy link
Member

CyberShadow commented Jun 19, 2017

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?

@JackStouffer
Copy link
Contributor Author

@CyberShadow I guess that's just part of understanding range code.

I've added a note just in case.

@CyberShadow
Copy link
Member

CyberShadow commented Jun 19, 2017

I guess that's just part of understanding range code.

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.


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.
Copy link
Member

@CyberShadow CyberShadow Jun 19, 2017

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.

Copy link
Member

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;
Copy link
Contributor

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
---
)

@wilzbach
Copy link
Contributor

wilzbach commented Jun 20, 2017

Thanks a lot for doing this @JackStouffer!

This should be targeting stable now. Change the target branch via the GH UI and locally you can use e.g. git rebase --onto upstream/stable

@JackStouffer
Copy link
Contributor Author

Won't be able to get back to this until Monday. Vacation awaits!

@JackStouffer JackStouffer changed the base branch from master to stable June 20, 2017 21:19
@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 24, 2017

Thanks for your pull request, @JackStouffer!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@MartinNowak MartinNowak dismissed CyberShadow’s stale review June 24, 2017 14:52

Changes addressed.

- also add ref to replacement function
@MartinNowak MartinNowak merged commit e59ce88 into dlang:stable Jun 25, 2017
@JackStouffer
Copy link
Contributor Author

Thanks @MartinNowak for handling this.

@JackStouffer JackStouffer deleted the pattern-changelog branch June 26, 2017 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants