Skip to content
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

String: rename split without separator to words #4646

Conversation

makenowjust
Copy link
Contributor

See #4644 (comment)

Now, String#split without separator is deprecated (breaking change).

See crystal-lang#4644 (comment)

Now, `String#split` without separator is deprecated (breaking change).
@straight-shoota
Copy link
Member

straight-shoota commented Jun 30, 2017

I think it could be argued to add String#words() besides String.split() handling leading and trailing whitespace differently. But removing String.split() makes no sense to me.

@need47
Copy link
Contributor

need47 commented Jun 30, 2017

I think we just need a clear documentation on this, and that's enough.

@makenowjust
Copy link
Contributor Author

@straight-shoota We can use s.split(/\s+/) explicitly if need such a result. Of course, there is performance issue, however I don't know when such a behavior is needed.

@makenowjust
Copy link
Contributor Author

To fit String#split without separator semantics, Ruby decided to remove leading and trailing empty strings from other split result. However Crystal decided to keep them. At that time, String#split without separator is broken.

@RX14
Copy link
Contributor

RX14 commented Jun 30, 2017

I believe String#split should behave exactly the same as String#split(' ') (except for splitting on all unicode whitespace (current is ascii-only)). Adding a String#words with the old implementation would be a good idea.

@makenowjust
Copy link
Contributor Author

We take care of String#split's default separator. For example, in JavaScript String.prototype.split makes an array containing the entire string if separator is not given. You may believe String#split's default separator is whitespace and it is the only answer without reason, but I am not believer. I think String#split should be given separator explicitly.

However, in fact, strangely, current Crystal behavior is almost same as Python's one (Python does not support empty string separator, but others are same). As @need47 said, we may have to write a clear documentation like Python. I agree with it if prefer simple solution.

@makenowjust makenowjust closed this Jul 1, 2017
@makenowjust makenowjust deleted the fix/string/split-without-separator-ranames-words branch July 1, 2017 15:26
@bew
Copy link
Contributor

bew commented Jul 1, 2017

For others not following everything, this PR has been closed because this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants