number_to_human_size and the modern era #292

Closed
wants to merge 1 commit into
from

Projects

None yet

7 participants

@trejkaz

Try to use standard SI prefixes for number_to_human_size, instead of the ancient 1024-based ones which were being used. Modern operating systems already do this, which results in a jarring mismatch between Rails' reported size and Mac OS'.

This particular version of the change may be controversial, but I believe in trying the simplest solution to the problem first, and this is the only solution which doesn't involve messing around with the options hash. :)

@trejkaz trejkaz Try to use standard SI prefixes for number_to_human_size, instead of …
…the ancient 1024-based ones which were being used.
d673a55
@mnaser

A kilobyte is 1024 bytes, the reason that some vendors refer to a kilobyte by 1000 bytes is beyond my understanding (simplicity?)

There's no need for us not to be precise and refer to it at 1024 bytes. What would be a far better alternative is to create an option to the hash which would allow it to use both bases of 1000 and 1024, with 1024 being the default, so this doesn't break someone's application with the change.

@trejkaz

"Some vendors" call a kilobyte 1000 bytes because that is the standard. A "kibibyte" is 1024 bytes. Please don't fall under the same misconception as others.

More information: http://en.wikipedia.org/wiki/Binary_prefixes

This change won't "break someone's application" - it will fix their application.

@eduardordm

"Some vendors": every known processor maker.

@trejkaz

Yep. Also every hard disk manufacturer. But also Mac OS. And also Ubuntu.

Without this change, I upload a 1 MB file to my Rails app and it tells me it received 977 KB. As a user, I now wonder if it uploaded correctly. (Plus, even if kilobytes were correct for 1024, the abbreviation for kilo- is 'k', not 'K'. My patch fixed that too.)

@morgoth

Hi guys.
I tried to do similar thing, some time ago:
https://rails.lighthouseapp.com/projects/8994/tickets/6287-correct-size-units-in-number_to_human_size-helper
Unfortunately there is no feedback from rails core team.

@samuelkadolph

Until computers no longer use binary, -1 a million times. In every OS, 1MB = 1024KB = 1048576B.
Everyone uses the base 2 values except for hard drive manufacturers and OS X's Finder (but not the kernel).

@nruth

If it says KB it is clear what it means, kB would be base 10 and kb would be a different unit of measure altogether.
I find it amusing that engineers will tell you the 2% error involved in mixing them up doesn't usually matter, while people building web apps think it does. :)

Also while Ubuntu and Mac OS may mysteriously count bits by si rather than binary powers, isn't Windows still the dominant consumer OS?

@trejkaz

Since when did being dominant automatically mean being right?

And since when is "K" ever a valid prefix for these units?

@henrikhodne

I see several programs use binary prefixes nowadays, so they use base 2, but they refer to them as kibibytes (KiB) or mebibytes (MiB), etc. in stead. So 1 kB is 1000 bytes, but 1 KiB is 1024 bytes. People started to adopt this as early as 1998 (as per the Wikipedia article), but adoption has been slow. I think we should do one by default with an option to choose which one to use, maybe :prefix => :binary and :prefix => :si?

@eduardordm

Anyways:

  • Users have no idea what KiB is;
  • Fitting the file is more important than showing number correctness.
  • 90% of users are running Microsoft's products.

If you are pragmatic having 1KB = 1000 does not makes sense at this moment when 90% of users still understand 1KB as 1024 bytes. Ext filesystem does use base 2 as an unit, it just converts before showing it to the user. Let's change the helper, after microsoft changes the way it displays file size numbers.

@trejkaz

Ext2 shouldn't be displaying anything to the user. It's a filesystem. If you mean ls, then there are multiple options to that tool:

$ ls -l 1MB 
-rw-r--r-- 1 trejkaz trejkaz 1000000 2011-04-26 12:33 1MB
$ ls -lh 1MB 
-rw-r--r-- 1 trejkaz trejkaz 977K 2011-04-26 12:33 1MB
$ ls -l --si 1MB 
-rw-r--r-- 1 trejkaz trejkaz 1.0M 2011-04-26 12:33 1MB

As for user understanding, if no applications were to show it the right way, users would never discover the right way. It's obviously up to applications to educate people on this, or everyone would keep doing it wrong (at least if we used eduardordm's logic. Proper units have been in place on both Mac OS and Ubuntu for some time, and I don't remember any major backlash about that.)

That aside, there are really three options here:

  1. Use KiB, MiB, GiB and base 1024 (:prefix => :binary)
  2. Use kB, MB, GB and base 1000 (:prefix => :si)
  3. Use KB, MB, GB and base 1024 (:prefix => :microsoft) (best name I can come up with, since most people seem to want to use them as the straw man for their argument about why anyone should be using this extremely outdated way of doing things.)
@trejkaz trejkaz closed this Apr 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment