Skip to content

[Issue 13409] std.range.padLeft/Right #3765

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

Merged
merged 1 commit into from
Mar 24, 2016
Merged

Conversation

JackStouffer
Copy link
Member

https://issues.dlang.org/show_bug.cgi?id=13409

Added the new function padLeft to std.range. Separated padLeft and padRight into separate PRs.

@JakobOvrum
Copy link
Member

I don't see any purpose in splitting it up into separate PRs. We want to merge both at the same time.

@JackStouffer
Copy link
Member Author

In previous PRs, I was told by quickfur and burner to split up functions that do not depend on each other into separate PRs in order to keep the diffs smaller and easier to review.

@JakobOvrum
Copy link
Member

You can accomplish that by putting them in separate commits.

Changes that need to be merged together should be in the same PR (unless, of course, the patches apply to different repositories). The issue with big PRs is when multiple orthogonal changes are bundled together, delaying merging of one change because of issues with an unrelated change.

@JackStouffer
Copy link
Member Author

@JakobOvrum added another commit with padRight.

*/
auto padRight(R, E)(R r, E e, size_t n) if (
isInputRange!R &&
(hasLength!R && !is(CommonType!(ElementType!R, E) == void)) ||
Copy link
Member

Choose a reason for hiding this comment

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

The padRight version that doesn't require length seemed to be much of the point of the issue report. Will you work on adding that to this PR?

@JakobOvrum JakobOvrum changed the title [Issue 13409] std.range.padLeft/Right (Part 1) [Issue 13409] std.range.padLeft/Right Oct 26, 2015
@JackStouffer
Copy link
Member Author

@JakobOvrum changed padRight to use an internal struct so the length isn't needed.

!isInfinite!R &&
!is(CommonType!(ElementType!R, E) == void))
{
static struct Result(R, E)
Copy link
Member

Choose a reason for hiding this comment

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

Result doesn't need to be templated, it already has access to R and E (as it's defined inside the padRight template).

Copy link
Member Author

Choose a reason for hiding this comment

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

A static struct cannot access the frame of the function.

Copy link
Member

Choose a reason for hiding this comment

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

Accessing template parameters doesn't require access to the frame of the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't making the struct non-templated also get rid of automatic function attributing?

Copy link
Member

Choose a reason for hiding this comment

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

Since a few compiler versions ago, member functions of structs nested in templates have attribute inference. The unit tests will show.

@JakobOvrum
Copy link
Member

Looks good! Note that you can test @nogc by statically allocating test arrays in the unit test body (or use only instead of arrays).

@JackStouffer JackStouffer force-pushed the pad branch 3 times, most recently from c401ae9 to 7edd8fa Compare October 27, 2015 14:58
@JackStouffer
Copy link
Member Author

@JakobOvrum fixed issues and added @nogc tests.

{
static struct Result(R, E)
{
R data;
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, these data members should be private.

@JackStouffer
Copy link
Member Author

Fixed everything this time :)

@JakobOvrum
Copy link
Member

Discussion here is relevant to this PR. Hopefully there won't be long until a decision is made.

@JackStouffer
Copy link
Member Author

@JakobOvrum The forum thread ended, I don't see any thing else blocking this.

@JakobOvrum
Copy link
Member

@JackStouffer, we don't merge non-trivial PRs with just one reviewer giving the go-ahead. So far it's just me, so another reviewer (or several) will have to look over it before we can merge.

@JackStouffer
Copy link
Member Author

@JakobOvrum I'm sorry if I seemed like I was asking you to merge this. What I meant by my comment is to point out that this can be reviewed again now that the forum discussion is over.

@JakobOvrum
Copy link
Member

@JackStouffer, indeed, thank you for posting it here. Sometimes it's hard for potential reviewers to see if a PR is being blocked by something or not, so posting helps. I'll add the relevant label.

@JakobOvrum
Copy link
Member

How do these relate to std.string.leftJustifier and std.string.rightJustifier?

@JackStouffer
Copy link
Member Author

@JakobOvrum I didn't know about those functions, but here are my observations after looking at their source:

  • Those functions only seems to work on strings, and it's API is slightly different in that it has a default padding element (space)
  • Those functions do not provide any of the other range primitives if the underlying range provides them
  • It's counter intuitive that left justify appends to the right, right justify appends to the left
  • One thing that I can copy from it for padLeft is not requiring a length member if the input is a forward range. I'll static if and use the current implementation if the input has length, or return an static struct

e = element to pad the range with
n = the length to pad to

Return:
Copy link
Member

Choose a reason for hiding this comment

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

"Returns:"

@andralex
Copy link
Member

I approve the addition, but I recommend one more careful pass through the documentation. Reviewers, free to pull after that. Thanks!

@JackStouffer
Copy link
Member Author

All comments fixed.

@JackStouffer JackStouffer force-pushed the pad branch 2 times, most recently from 5d2c4c9 to f7b4b3f Compare March 22, 2016 21:10
@@ -9360,3 +9368,293 @@ if (is(typeof(fun) == void) || isSomeFunction!fun)

auto r = [1, 2, 3, 4].tee!func1.tee!func2;
}

/**
Extends the length of the input range `r` by padding out the start of the
Copy link
Member

Choose a reason for hiding this comment

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

I just want to point out that this sentence also begins with a verb and omits the subject...

Copy link
Member

Choose a reason for hiding this comment

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

Nice, but that's an exception because it's the opener of the dox.

@JackStouffer
Copy link
Member Author

The auto-tester errors have nothing to do with this change.

Can anyone give a reason why this shouldn't be merged?

EDIT: and another release goes by without this.

n = the length to pad to

Returns:
a range containing the elements of the original range with the extra padding
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: new sentence start with a capital letter - A.

@JackStouffer
Copy link
Member Author

People can make fun of JavaScript's quadratic, 11 line left-pad all they want, but at least that one isn't sitting in PR where no one can use it.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
13409 std.range.padLeft/Right

@quickfur
Copy link
Member

I agree. I'm gonna stick my neck out here and merge this. Any complaints, please submit followup PRs. Our current approach of requiring perfection before merging is a great discouragement to new contributors and hampers progress. It's time to change that.

@quickfur
Copy link
Member

Auto-merge toggled on

@quickfur quickfur merged commit 1651c78 into dlang:master Mar 24, 2016
@JackStouffer
Copy link
Member Author

Thanks!

@JackStouffer JackStouffer deleted the pad branch March 24, 2016 20:04
@andralex
Copy link
Member

yay

@brad-anderson
Copy link
Member

If you'll forgive a bit of off topic noise I found the timing of this merge unintentionally hilarious given what is going on in the npm world right now. I guess D users won't be forced to use left-pad.io.

@quickfur
Copy link
Member

lol... Given the current trend, I'm starting to wonder when people will start turning glue code into packages too, so that you don't even need to write any code to glue various micro-libraries together to do something you could, for example, accomplish in 25 lines of code without any dependencies. Hilarious.

@wilzbach
Copy link
Member

@JackStouffer you might want to add a follow-up PR that adds a note to the changelog.

@ others: it's quite easy to forget adding stuff to the changelog and with git one can still go through the lists of commits between a release. However - if i may ask - what is your current policy for the changelog?

a) Should a submitter provide the change in his PR (might lead to many unnecessary git conflicts as this file is changed often)
b) Should a submitter provide a follow-up PR to the changelog (easy to forget, might lead to git log clutter)
c) Will someone of the maintainers go through the git log (a lot of work, might be challenging to summarize an addition to a non-familiar part of Phobos)

It might make sense to document such guidelines (see the forum discussion on a better contribution guide)

@JackStouffer
Copy link
Member Author

This is not in the changelog because the current one is for 2.071, and this will be going into 2.072. I have to wait until 2.071 is released to add it.

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.