5

How to react to a coworker using equals() instead of equalsIgnoreCase() for checking case insensitive strings?

Comments
  • 11
    IDK, just react normally. Are you sure he didn't do .toLower() on both of them beforehand?

    If he didn't - just fix the thing and hint him to be more careful next time.
  • 11
    Teach him the first time and roast him the second
  • 6
    Point it out in the code review
  • 5
  • 1
    Refuse to approve the merge until he fixes his shit. Code reviews are exactly for that.
  • 1
    show off his mistake in the demo
  • 2
    Maybe he didn't know such function exists. Languages need to stop spoonfeeding by creating unnecessary functions.
  • 1
    @theabbie Because high level languages are inherently slower, it's a question of performance that the STL can do as many things as possible, so the users don't have to write these functions in the language itself.
  • 1
    @homo-lorens Functions like Array Flatten, Starts with, ends with etc. are fine in standard library as they are not hard to implement but just tedious. This however and also function Array Shuffle for example are neither hard nor tedious. Internally this would also be converting to lower case and comparing which will not take more than one line.
  • 2
    @theabbie In that case the error is that the stl function shouldn't convert and compare. Given how often it's reused, no amount of optimization is too much. It should compare bytes, preferably with SIMD.
  • 1
    @homo-lorens It's not some tremendous optimization, high-level should not mean having functions for everything, but having features that make most implementations simpler. These only increase the size of standard library and documentation.
  • 1
    @theabbie Yes it is. Copying a string (+allocation) and iterating over it twice vs iterating once comparing 4 characters at a time is a huge optimization.
  • 1
    @homo-lorens Maybe this would be a bad example, and we are assuming this is happening in the library. Still, having too many functions isn't the best idea.
  • 2
    @theabbie the only thing high level actually objectively means is highly abstract. This implies the inability to use platform and problem specific optimizations, which can be solved with providing platform-optimized STL functions for all problems imaginable.
  • 1
    @homo-lorens This optimization is useful when millions of operations are performed. And if millions are being performed, the programmer will have to consider these optimisations anyways.
  • 1
    @theabbie I'm fairly confident that considering Java's popularity, this function runs way more than a million times a second, altogether probably costing hours of runtime every year. This is what I mean by frequently reused.
  • 1
    Okay, my numbers are all over the place because it's impossible to guess at the worldwide calls to an stl utility, but you get the point.
  • 1
    @homo-lorens I meant in a single program. For eg. For sorting a list of 10000 strings using bubble sort. Then, these small optimizations on string comparison add up. If it only happens few times, it won't just destroy the program. But yes, it's always better to have the most efficient implementation.
  • 1
    @theabbie But I didn't mean a single program,because the investment of writing it well isn't made per program. It's made once, and the return on that investment is every call to it ever made from any Java program.
Add Comment