JuliaPhysics / JuliaPhysics/Unitful.jl

`preferunits` without global state

Open
#601 1 comment 2 reactions 0 assignees View on GitHub
v2.0
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

Currently, `preferunits` works by changing the values in the global dictionary `Unitful.promotion`. This causes problems with precompilation (#545, #600).

My suggestion for Unitful v2.0 is to replace the global "unit preference dictionary" (`Unitful.promotion`) by an object that the user creates and explicitly uses to convert to their preferred units. Instead of
```julia
preferunits(cm)
upreferred(1m)
```
the user would do the following:
```julia
my_unit_preference = UnitPreference(cm) # this returns a UnitPreference object, does not alter global state
my_unit_preference(1m) # the UnitPreference object is callable
```

However, this means that automatic promotion would not promote to the user’s preferred units but always to the default units (unless they are using `ContextUnits`/`FixedUnits`).

Introducing this new `UnitPreference` object can be done in a minor release, but removing the possibility of setting a global unit preference would be breaking.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.