AJChapman / formatting

Format strings type-safely with combinators
BSD 3-Clause "New" or "Revised" License
164 stars 39 forks source link

Add bytes formatter #17

Closed markus1189 closed 9 years ago

markus1189 commented 9 years ago

Extracted from commercialhaskell/stack#571

I wasn't sure under which category I should place it, in the end I went with Bases, though maybe Units would be better, I felt like opening a whole section was overboard, but I leave that to you ;)

chrisdone commented 9 years ago

I'm trying to think of a specific name for it, as the mebibyte format isn't really used anywhere. In the stack case, it doesn't matter much because you're telling people how many mebibytes there are, so they don't have to be familiar with it.

markus1189 commented 9 years ago

An alternative could be to add two versions, bytesDecimal and bytesBinary, inspired by https://en.m.wikipedia.org/wiki/Binary_prefix On Jul 13, 2015 10:56 AM, "Chris Done" notifications@github.com wrote:

I'm trying to think of a specific name for it, as the mebibyte format isn't really used anywhere. In the stack case, it doesn't matter much because you're telling people how many mebibytes there are, so they don't have to be familiar with it.

— Reply to this email directly or view it on GitHub https://github.com/chrisdone/formatting/pull/17#issuecomment-120856399.

chrisdone commented 9 years ago

Yeah, bytesDecimal works for me.

chrisdone commented 9 years ago

Applied as bytesDecimal and bumped as 6.2.1. Thanks!

markus1189 commented 9 years ago

Uhm, hang on there, bytesDecimal would be the version that uses 1000 as the base not 1024 as did the version I used, KB = 1000 bytes, KiB = 1024 bytes, so the version you currently named bytesDecimal is wrong. What about #18 instead?

chrisdone commented 9 years ago

Okay, this is confusing. ls and nautilus and whatnot report a file with 1024 bytes in it as "1K" and "1.0 kB (1,024 bytes)" respectively. This is the typical notion of a kilobyte that I'm used to since forever. I've never seen anywhere use 1K or 1KB to mean 1000 bytes. Your use of KiB — a notation I've never seen in the wild, lead me to believe it was somehow different, referring to 1000 bytes. After looking again I see it just means what we're used to (KB=1024, MB=1,048,576 bytes, etc.), but with an additional i in there. I'm not sure how I feel about this.

chrisdone commented 9 years ago

I'm just going to put this in as bytes without the i inside like everybody else and call it good.

chrisdone commented 9 years ago

Works for me: https://github.com/chrisdone/formatting/commit/c850e90b649f3f88144f618013f83cc2d06e3391

markus1189 commented 9 years ago

Yeah it is a confusing. AFAIK most consider KB = 1024 but the kilo prefix in other units is supposed to mean 1000. So per standard kilobytes = 1000 bytes not 1024, KiB (kibibytes) explicitly specifies that it uses 1024, while with KB everybody kind of does what he wants. Now that you're primed you will be surprised how often you can actually see KiB etc. instead of KB, just keep looking.

However whatever works for you works for me too :), so I closed the other pr

BrunoChevalier commented 7 years ago

@markus1189 @chrisdone I'm kind of disappointed that the most illogical decision was made here. We have a standard of prefixes, and I would have expected that this standard was followed. A lot of Linux tools have standard output of KiB instead of KB. 1 KiB = 1024 Bytes 1 KB = 1000 Bytes

chrisdone commented 7 years ago

@BrunoChevalier

We have a standard of prefixes, and I would have expected that this standard was followed.

I think "standard" is a matter of use, not prescription.

A lot of Linux tools have standard output of KiB instead of KB.

At the time of writing my previous message, Nautilus displayed as "1KB". OS X displays a 4*1024*1024 file as 4 KB:

Chriss-MacBook-Pro:~ chris$ stack exec ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/chris/.ghci
Prelude> writeFile "x.txt" (replicate (4*1024) 'a')
screenshot 2017-05-19 21 05 11

If you want to present to users a familiar size then I think the normal (aka standard) notation is more legible than something unfamiliar with an unfamiliar meaning.

I'm kind of disappointed that the most illogical decision was made here.

Calling things you don't agree with illogical is not a good way to get what you want.