← Back to context

Comment by throwaway4good

4 years ago

Honestly. The code is fine.

This is for presenting stuff in a user interface. Who cares if you can find some weird edge case using MAX_LONG and MAX_DOUBLE which never will occur in practice.

Until it does.

  • The original doesn't have types, but the modified version of humanReadableByteCount() uses a "long bytes" and as such will fail if the file size is (Long.MAX_VALUE+1) because it cannot even accept the correct size as its argument in the first place. Implementing these edge cases makes adds one more working case to 2^63 (2^64 if negative file sizes are valid) when the bigger problem is using the type "long" when files of that size are possible on the target system.

  • Readability and maintainability matters far more.

    And no - the edge cannot occur as it would require a file / whatever to have that size.