Skip to content

Add missing documentation to String methods#8447

Merged
RX14 merged 10 commits intocrystal-lang:masterfrom
jan-zajic:feature/string-doc
Apr 9, 2020
Merged

Add missing documentation to String methods#8447
RX14 merged 10 commits intocrystal-lang:masterfrom
jan-zajic:feature/string-doc

Conversation

@jan-zajic
Copy link
Contributor

n/c

@jan-zajic
Copy link
Contributor Author

Hi @Sija, @asterite, @straight-shoota, @r00ster91, second round. Also i fix bug that i found during creating code samples in byte_slice(Int): currently it raises Negative count (ArgumentError) for large index (for example "hello".byte_slice(6)), which makes no sense. It should raise IndexError.

@straight-shoota
Copy link
Member

Could you please squash the changes into two commits: One fixing the exception, the other adding the docs?

@jan-zajic
Copy link
Contributor Author

@straight-shoota yes, of course.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

  1. To avoid confusion, I'd suggest to always specify "byte index" to distinguish from character index. Maybe we should also use "character index" in the other cases as well, but I'm not sure.
    Perhaps even rename the arguments to byte_index or byte_offset? I'm not sure that's necessary, though. And it should be a different PR.

  2. You're sometimes referring to "out of bounds", sometimes "out of range". I'm not sure if one is strictly better than the other but it would be best to use the same terminology everywhere.

  3. Regarding: "Returns true, if [...], otherwise false.": IMO the last part should be omitted. It's unnecessary and only clutters the description. It should be evident that Bool methods return false in all other cases where it's not true.

  4. Probably also a thing for another PR, but I'd like to standardize some of the argument names. For example byte_slice(start : Int, count : Int) vs. unsafe_byte_slice(byte_offset, count) (see also 1.). And short argument names like str or re should IMO be properly named.

@jkthorne
Copy link
Contributor

@jan-zajic thank you for all your work on docs!

@jan-zajic
Copy link
Contributor Author

@straight-shoota i made fixes according to yours review + according to your comment:
ad 2, it's almost 50:50 in current String doc. All replace range to bounds in whole file..
ad 3, I agree with you, done.
1, 4, good point but left for another PR, as we already have a lot here.

@straight-shoota
Copy link
Member

Thank you very much!

@straight-shoota
Copy link
Member

@jan-zajic Could you please rebase on master?

@jan-zajic jan-zajic force-pushed the feature/string-doc branch 2 times, most recently from 5afa152 to 8b21790 Compare January 2, 2020 14:04
@jan-zajic
Copy link
Contributor Author

@straight-shoota yes, of course. It's done.

src/string.cr Outdated
end

def byte_index(byte : Int, offset = 0)
# Returns the index of *byte* in the string, or `nil` if the byte is not present.
Copy link
Member

Choose a reason for hiding this comment

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

"Returns the index of the first ocurrence"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@straight-shoota what you think about this proposal? Is it not against previous considerations? I think my draft is in line with other docs in string file..

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure, did we discuss this before? @RX14's suggestion sounds reasonable, it's more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but it's same with current existing documentation for index method .. So maybe i have to change it too? And please write always complete formulation, what about for example:

1, Returns byte index of the first ocurrence of byte in the string, or nil if not present.

or

2, Returns the index of the first ocurrence of byte in the string, or nil if not present.

or

3, Returns the index of the first ocurrence in the string, or nil if not present.

or

4, Returns byte index of the first ocurrence in the string, or nil if not present.

or?

Copy link
Member

Choose a reason for hiding this comment

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

Number 2 please.
And I'd like to change #index accordingly, that is add "first occurrence" to the existing phrase. For the regex overload: "first match"

Copy link
Member

Choose a reason for hiding this comment

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

It seems this change was lost.

jan-zajic added a commit to jan-zajic/crystal that referenced this pull request Jan 3, 2020
jan-zajic added a commit to jan-zajic/crystal that referenced this pull request Jan 6, 2020
@straight-shoota straight-shoota added kind:docs pr:needs-work A PR requires modifications by the author. topic:stdlib:text labels Jan 28, 2020
@jan-zajic jan-zajic force-pushed the feature/string-doc branch from 7c4d8a9 to 2620493 Compare April 8, 2020 09:08
@jan-zajic
Copy link
Contributor Author

@straight-shoota i rebase this on current master (again). Please can we finally merge this, before another conflicts arise?

@straight-shoota straight-shoota requested a review from RX14 April 8, 2020 09:21
@straight-shoota straight-shoota removed the pr:needs-work A PR requires modifications by the author. label Apr 8, 2020
Copy link
Member

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

Just one thing got lost in the rebase I think.

src/string.cr Outdated
end

def byte_index(byte : Int, offset = 0)
# Returns the index of *byte* in the string, or `nil` if the byte is not present.
Copy link
Member

Choose a reason for hiding this comment

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

It seems this change was lost.

@jan-zajic
Copy link
Contributor Author

@RX14 it's done

@RX14 RX14 added this to the 0.35.0 milestone Apr 9, 2020
@RX14 RX14 merged commit cf0edd8 into crystal-lang:master Apr 9, 2020
carlhoerberg pushed a commit to carlhoerberg/crystal that referenced this pull request Apr 29, 2020
Co-Authored-By: Johannes Müller <johannes.mueller@smj-fulda.org>
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.

6 participants