Rubocop: Issues with Performance/Casecmp

Created on 10 Jan 2016  路  3Comments  路  Source: rubocop-hq/rubocop

Hi! Two issues with this cop:

  • It autocorrects wrong. 'HOLA'.downcase == 'hola' gets autocorrected to 'HOLA'.casecmp('hola'), but the first version returns a boolean and the second an integer.
  • I don't think it should be enabled by default. The correct autocorrected version would be 'HOLA'.casecmp('hola') == 0 which is arguably less readable. I think performance cops should only be enabled by defaulf if they don't harm readability.

Most helpful comment

I still find it less readable, but it's not up to me... :)

All 3 comments

What if it autocorrected to 'HOLA'.casecmp('hola').zero? ?

I still find it less readable, but it's not up to me... :)

@segiddins, since this cop is for "performance", could you benchmark the zero? fix and see if it still buys any performance?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikegee picture mikegee  路  3Comments

bbugh picture bbugh  路  3Comments

bbatsov picture bbatsov  路  3Comments

bquorning picture bquorning  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments