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

add downcase option to String#camelcase #7717

Merged
merged 4 commits into from
May 1, 2019

Conversation

jkthorne
Copy link
Contributor

resolves #7709

@ysbaddaden
Copy link
Contributor

Just lower would be enough. Both variants (lower camel case, upper camel case) should be documented, too.

src/string.cr Outdated
@@ -3503,10 +3503,10 @@ class String
# "eiffel_tower".camelcase # => "EiffelTower"
# "isolated_integer".camelcase(Unicode::CaseOptions::Turkic) # => "İsolatedİnteger"
# ```
def camelcase(options : Unicode::CaseOptions = Unicode::CaseOptions::None)
def camelcase(options : Unicode::CaseOptions = Unicode::CaseOptions::None, lowercase_first_letter = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def camelcase(options : Unicode::CaseOptions = Unicode::CaseOptions::None, lowercase_first_letter = false)
def camelcase(options : Unicode::CaseOptions = Unicode::CaseOptions::None, *, lowercase_first_letter = false)

to prevent just false as argument, suggested in #7709 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd stand for just lower as the argument name. It's clearly understandable that lower in context of camelcase means exactly lower camelcase, which is a common term. No need for a long and explicit name here.

@straight-shoota
Copy link
Member

lowercase_first_letter is too long.

I'd suggest one of the following (in order of preference):

  • downcase_first
  • lower
  • lower_first

@jkthorne
Copy link
Contributor Author

@straight-shoota @ysbaddaden what do you think about downcase as the argument?

src/string.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota changed the title add lowercase option to String#camecase add lowercase option to String#camelcase Apr 25, 2019
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.

I'm okay with this, but I'd prefer to name the argument more explicitly downcase_first.

src/string.cr Outdated Show resolved Hide resolved
@vladfaust
Copy link
Contributor

vladfaust commented Apr 30, 2019

That’s bad. camelcase(downcase: true) is confusing. camelcase(lower: true) is better. And I am for breaking change if needed to move the argument to the first place.

@j8r
Copy link
Contributor

j8r commented Apr 30, 2019

Or lower_first, that's about a bit longer than the current downcase and remove any ambiguity

@straight-shoota
Copy link
Member

And I am for breaking change if needed to move the argument to the first place.

No. It should only be usable as a named argument to clearly express the semantics.

Co-Authored-By: wontruefree <[email protected]>
@jkthorne
Copy link
Contributor Author

jkthorne commented May 1, 2019

@straight-shoota CI seems to be failing due to running too long. Is this common for CI and how can I rerun it?

@jkthorne
Copy link
Contributor Author

jkthorne commented May 1, 2019

@straight-shoota thank you for re-running this.
Can we merge this?

@asterite asterite merged commit e398c4c into crystal-lang:master May 1, 2019
@asterite asterite added this to the 0.29.0 milestone May 1, 2019
@vladfaust
Copy link
Contributor

That's disturbing.

@jkthorne jkthorne deleted the camelcase branch May 1, 2019 19:13
@jkthorne
Copy link
Contributor Author

jkthorne commented May 1, 2019

@vladfaust Which part is disturbing?

@ysbaddaden
Copy link
Contributor

ysbaddaden commented May 1, 2019

I'm late to the party, but where the hell did downcase came from? Downcase camelcase doesn't mean anything, it's just confusing.

This is lower or upper camelcase (which affects the first letter) not downcase —a completely different method and meaning 😕

@straight-shoota
Copy link
Member

@ysbaddaden It downcases the first character, the equivalent method is #downcase not #lower, so it makes some sense. As mentioned, I'd have prefered downcase_first or lower_first.

@straight-shoota
Copy link
Member

straight-shoota commented May 1, 2019

Hm, actually, it doesn't even downcase the first character when it's uppercase: "Foo".camelcase(downcase: true) => "Foo". I think this behaviour should be changed to return "foo".

@asterite
Copy link
Member

asterite commented May 1, 2019

I think the API is fine, the above is just a bug in this PR's implementation.

@wooster0
Copy link
Contributor

wooster0 commented May 2, 2019

Isn't this method generally behaving incorrectly? This method returns "EiffelTower" for "eiffel_tower" but that's wrong. "EiffelTower" is PascalCase, not camelCase. The first letter should be lowercase by default. I think there should be another method, pascalcase that has the current behavior of camelcase.

@j8r
Copy link
Contributor

j8r commented May 2, 2019

@r00ster91 Pascal case was discussed in the related issue, please do not duplicate the discussion in this PR.

@bcardiff bcardiff changed the title add lowercase option to String#camelcase add downcase option to String#camelcase May 31, 2019
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.

Titlecase vs Camelcase
8 participants