-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Performance/Caller: Clearer message #99
Comments
Thanks for the reporting! 👍 |
See #4478 Note: the spec checks a message is correct. For example: ```ruby expect(caller(2)[1]).to eq(caller(3..3).first) ``` I think the checks are necessary, because `caller` is difficult to me.
Isn't this rather the tail wagging the dog? Surely Ruby should be preening its parse tree to optimise this sort of nonsense invisibly - not developers forced to waste brain cells creating increasingly unreadable code. In any case, when is caller called in time-critical situations? This is like the time someone optimised an RPC call failure mode by microseconds, ignoring that the network call was going to take milliseconds anyway. |
For those of you arriving via a google search as to what this cryptic message could possibly mean (and why this bizarre syntax is "preferable"), the answer seems to be along these lines: # bad
caller[0] # builds a large array from which only one element will be extracted
# good
caller(0..0).first # builds a single-element array from which one element will be extracted I hope the array size is actually something to be concerned about here, because this is a very odd edit for a style checker to suggest. |
# bad
caller[0] # extracts only one element after receiving an enormous array I think it's more than caller(0..0) BUILDS a tiny array, and caller() builds a huge one, most of which is thrown away. But I maintain that it should be that Ruby's optimiser should notice caller[0] and do the optimisation, not the programmer forced to jump through stupid hoops. |
You're right, I'm going to update that comment |
I have the following line of code
which RuboCop 0.49.1 flags with
Looking at the suggested solution I'd expect to change the code to
but that isn't feature equivalent because
caller(0..0)
not only returns anArray
instead of aString
, but even if we use the first item in the returnedArray
we get a different result. In short; the default message is confusing and potentially misleading (at least to me).Expected behavior
I'd expect RuboCop to guide me to a correct solution, or not at all. The pipe dream is
but that's a bit specific to my concrete case, I reckon. Perhaps we could settle for:
but that might hide the changed behavior too much. More precisely:
but that's hardly concise or easily understandable. How about some form of
¯\_(ツ)_/¯
There is some discussion ongoing on the now closed pull request as well: rubocop/rubocop#4078
Actual behavior
RuboCop suggest
Steps to reproduce the problem
caller[0]
RuboCop version
The text was updated successfully, but these errors were encountered: