-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Inconsistent naming of String#chomp after adding String#lchomp #3729
Comments
I'd say |
I personally see no reason why the inconsistency exists.
@asterite Breaking changes happen, it's been happening for a while now, this really isn't a good reason for keeping an inconsistency this early on.
I can find a few, csv file line starts and ends with a empty delimiter
This is a simple use case, I've seen many where I'd need to chomp both from the beginning and end of a string. |
OK, what should be the steps to do this? I guess these:
Also, do we also get an argless I'm not totally convinced with the above... Another alternative is to just leave the argless
This is also present in Ruby. And it doesn't have any args. So maybe we could make What should be done here for the API to be perfect and consistent? |
This is what I think is best:
I think this is the most consistent API I can imagine. It might not be the easiest to implement, or mirror ruby, but I think that in the long run it's probably the best API. |
@RX14 What about |
@asterite yes, and provide a lchomp option too (just set both for chomp) |
@RX14 What's the use case for string = gets('d', lchomp: true) # ??? |
Hmm, maybe lchomp doesn't make sense. You could specify what to chomp with a named arg, but maybe not. I think that the proper long term solution would be to make string manipulation cheaper while remaining composable. Being able to compose string operations via a mutable intermediate. |
Why not extend
|
@pkorotkov Because wanting to do |
@asterite Call for reopening the issue to let others see this discussion. |
I've yet again come across a need for I get a HTTP path either like |
Why's @asterite refusing to reopen this? |
We've been discussing this with @asterite. A simple way to fix this would be to rollback the On the other hand, having That being said, we'd propose:
Thoughts? |
I prefer to have |
I'm with @ysbaddaden , |
@spalladino This is an acceptable solution. I hope that in the future that crystal will grow independent enough from ruby to re-add @ysbaddaden @bararchy What's your reasoning behind this? I think string method naming in general is confusing, inconsistent and obsure currently. I hope we can come up with a consistent, descriptive naming scheme for string methods. |
@RX14 My reasoning is that gets.chomp is the most basic ruby operation, in almost every CLI program you have examples on it's usage and what it does, for me using the same name (chomp) but making it do something other then cutting the right side \n or \r\n is really confusing and unexpected (as a Ruby dev) It's like we will decide that puts will behave the same way as print (without a \n), it's just messing with basic assumptions |
If the only defence of the current naming is "ruby does it", isn't that a bit telling? |
It's not just that Ruby (and Perl) do it, I googled a bit and found other languages or libs that also have the same behaviour:
Having a string method named exactly as in several other libs that behaves differently is a potential cause for bugs, so I'd either keep |
@spalladino Please, don't remove |
Removing functionality to satisfy naming seems wrong, so again I vote for |
How about aliasing chomp to rchomp, and keep lchomp & rchomp ? this will pretty much satisfy everyone no ? |
@bararchy Crystal's stdlib will never have method aliases. By doing that, it means that half the devs will pick one naming and half the devs will pick the other. Devs will have to learn both name to read other people's code, and there will doubtless be endless discussion. It's best to pick one solution and stick with it, than compromise and annoy everyone. |
@RX14 If so then I think keeping This is also an argument for "Principle of least astonishment" |
@RX14 Same point I brought up in my thread, Now I personally don't know what your plans are for backwards compatibility in the future, but fixing this later seems like it would be a bigger hassle than it currently is at the moment. |
Here's another idea. We want to preserve
In summary, we'll only have these methods:
There's no inconsistency, although As for the missing methods I didn't mention:
In any case we could introduce |
...why not just add a direction argument to |
@kirbyfan64 That's a very good idea... I think that's a direction we should explore. It simultaneously solves the |
@RX14 Why would we need to rename The only issue I see with Another issue is that it will be kind of inconsistent: |
@asterite It's probably useless, but |
@asterite You don't have to change gets args, I was thinking we had |
Also, we'd probably change |
I just don't see a reason not to just add
(update all methods that rely on chomp's old functionality to use rchomp) no changes (works how you'd expect)
chop
Now the naming scheme is consistent.
No point in doing this if those two methods work completely different from each other PS:
Just because you don't have a use case for it doesn't mean others do, which have been mentioned in this thread many times that there are use cases for using those methods on the left and both sides of a string. |
@exts The problem is that |
Then what if we introduce a new method if the idea is to keep those methods as similar to ruby/perl as possible? Name it Best of both worlds and we don't have to have any breaking changes and those coming from ruby won't have to relearn how the chop/chomp methods function. |
@exts That's my proposal, except that I use |
Alright, i think that works then. Keep chomp the same, change chop. |
Makes sense to me too |
I think removing the |
So how would |
I think chomp should just be the exception, all future methods should stay |
But you could alter that to change the default args, for example |
"Have a syntax similar to Ruby (but compatibility with it is not a goal)" "It came from ruby" doesn't make much sense. Lots of things in Crystal came from other languages, it doesn't mean that it should keep inconsistencies just for the purpose of "it's like this in this language", especially in this stage where backwards compatibility breakage is to be expected. My opinion is that |
@zatherz if you consider that 99% of people who use chomp want to chomp the right side, then you use |
The problem is that to chomp the left side you'll have to write |
Here's a thought: what about using either symbols or an enum? e.g. |
I've thought about it some more and I think the accepted solution is probably the best one. It solves my previous complaint of |
Recent commit 60bf3cda has added two left chomp functions (lchomp) to String's instant methods as counterparts to existing String#chomp(Char), String#chomp(String). Having no issue with the commit implementation, I'd like to point out an inconsistency in method naming: String#lchomp corresponds to String#chomp while, analogously, String#lstrip corresponds to String#rstrip.
The text was updated successfully, but these errors were encountered: