Hacker News new | past | comments | ask | show | jobs | submit login

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.


For example - what is the meaning of the parameter "si"?

I betcha that is going to give you more bugs than the edge cases discussed here.


The parameter "si" here stands for International System of Units, or SI for short [0].

0: https://en.wikipedia.org/wiki/International_System_of_Units#...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: