typelevel/squants

DefaultFormatter is removed, no replacement?

Opened this issue · 8 comments

netvl commented

Documentation still says that there is an API for formatting in the best unit, via DefaultFormater. Yet, it appears that it was removed in the latest version. I couldn't find any public discussions or tickets about it and reasoning for its removal, and there is no indication that there is a replacement. Does this mean that I cannot upgrade to the latest version if I want this functionality?

netvl commented

I found that this PR just dropped the entirety of experimental, with no replacement as it seems. I understand that experimental API is just that, experimental and subject for removal at any time, but I would've expected at least some explanation somewhere why it is done, and hopefully a pointer to a replacement (and updated docs too, because currently both readme and official site squants.com still have the old information).

I dropped theexperimental api when upgrading to scala 3 simply due to lack of time to update it at the same time.
I don't think there are any users of the experimental api so should have been safe

netvl commented

I don't think there are any users of the experimental api so should have been safe

Sorry but how did you figure this out? Experimental API was explicitly documented on the primary documentation page and readme, and it did provide very useful features. Right now, missing functionality of DefaultFormatter is something which prevents me from upgrading, for example. I doubt I’m the only such user.

Again, since this API is experimental, it is all right to drop it for whatever reason, burden of maintenance included, but it is quite jarring that it was done without any explanations or notes, and documentation is misleading now :(

You can see how the decision was reached in the PR
#454

In that PR support for scala 3 was added and some sacrifices were made (also no scala-native) or most likely there wouldn't be scala 3 support at all.

As for documentation, I don't have access to the orginal website nor rights to update it. We may want to update the README to be in sync with the current code. PRs are certainly welcome in documentation and/or to restore the removed functionality

NOTE - the website at squants.com is a GitHub page that displays the current README.

axb21 commented

The current README still discusses the non-existent experimental package. I just spent a good hour trying to find it, thinking I'd done something wrong or missed a dependency.

Can you please at least update the README and spare other people the trouble and headscratching I just went through?

axb21 commented

For what it's worth, if you're using scala 3 you can more or less copy-paste the DefaultFormatter code from an earlier version (e.g. 1.7.0 has it) and it works fine. You're going to need UnitGroup too and to either make your own or to use the ones implemented there. You can use an extension method to add inBestUnit to whichever Dimension you want, once you've created a formatter; e.g.,

val powerFormatter = new DefaultFormatter(PowerUnitGroup)
extension(power: Power) def inBestUnit = powerFormatter.inBestUnit(power)

where PowerUnitGroup is

object PowerUnitGroup extends UnitGroup[Power]:
   val units: Set[UnitOfMeasure[Power]] = Set(Watts, Kilowatts, Megawatts, Gigawatts)

(for instance).

With the above in place you can do stuff like

scala> Kilowatts(1000).inBestUnit
val res2: squants.energy.Power = 1.0 MW
                                                                                                                                                                                    
scala> Kilowatts(1000000).inBestUnit
val res3: squants.energy.Power = 1.0 GW

I don't think there are any users of the experimental api so should have been safe

Huh?!