Sizes in yast-storage-ng after introducing alignment in libstorage-ng
Before ====== Before introducing alignment calculation in libstorage-ng the library provided methods like ::Storage::Partition#size_k #=> Fixnum ::Storage::Disk#size_k #= Fixnum On top of that, there was a DiskSize class with offered several convenient methods including DiskSize#size_k #=> Fixnum And, on top of that we had many methods always called #size that returned a DiskSize object, like FreeDiskSpace#size #=> DiskSize ::Storage::Partition#size #=> DiskSize (using a refinement) The API was pretty clear, you could always expect any method called #size to return a DiskSize object and you always had #size_k to get a Fixnum. After ===== All that beauty was broken with the change introduced in libstorage-ng. Now its API looks like ::Storage::Partition#size #=> Fixnum (bytes) ::Storage::Disk#size #= Fixnum (bytes) Now you cannot longer infer the type based in the name and everything becomes more confusing with methods like DiskSize#size #=> Fixnum (bytes) DiskSize#size_b #=> Fixnum (alias for the former) FreeDiskSpace#size #=> DiskSize Solution 1 ========== We could rename all the methods from libstorage from #size to #size_b and thus recover the initial consistency. Solution 2 ========== We could rename all the methods in the ruby layer that return a DiskSize object to something like #disk_size. So #size is always a Fixnum (bytes) and #disk_size is always a DiskSize object. For example FreeDiskSpace#disk_size #=> DiskSize In addition, I would add DiskSize#bytes as a more readable alias for DiskSize#size, resulting in things like this: a_free_space.disk_size.bytes What do you think? -- Ancor González Sosa YaST Team at SUSE Linux GmbH -- To unsubscribe, e-mail: opensuse-storage+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-storage+owner@opensuse.org
On 15.06.2016 10:59, Ancor Gonzalez Sosa wrote:
Solution 1 ==========
We could rename all the methods from libstorage from #size to #size_b and thus recover the initial consistency. ... What do you think?
IMHO 'size' without anything implies that it's bytes. size_k was just a reminder that it was nonstandard, calculating in kilobytes. So I'd suggest to use DiskSize whereever it makes sense (i.e. mostly everywhere in the Ruby code) and otherwise leave plain size() where it doesn't - and where there is no danger of integer overflow (!). Kind regards -- Stefan Hundhammer <shundhammer@suse.de> YaST Developer SUSE Linux GmbH GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg) Maxfeldstr. 5, 90409 Nürnberg, Germany -- To unsubscribe, e-mail: opensuse-storage+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-storage+owner@opensuse.org
Franky, I didn't find it that intuitive before. :-/ I tend more to solution 2. On Wednesday 2016-06-15 10:59, Ancor Gonzalez Sosa wrote:
Solution 2 ==========
We could rename all the methods in the ruby layer that return a DiskSize object to something like #disk_size. So #size is always a Fixnum (bytes) and #disk_size is always a DiskSize object. For example
FreeDiskSpace#disk_size #=> DiskSize
In addition, I would add DiskSize#bytes as a more readable alias for DiskSize#size, resulting in things like this:
Or DiskSize#to_i? BTW, we have also the ::Storage::Region class where sizes are returned in *sectors*. Also, I would change the DiskSize implementation so that -1 is no longer a special value. Steffen -- To unsubscribe, e-mail: opensuse-storage+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-storage+owner@opensuse.org
participants (3)
-
Ancor Gonzalez Sosa
-
Stefan Hundhammer
-
Steffen Winterfeldt