Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un-specialcase Temperature #1

Open
martinlindhe opened this issue Mar 5, 2016 · 1 comment
Open

Un-specialcase Temperature #1

martinlindhe opened this issue Mar 5, 2016 · 1 comment

Comments

@martinlindhe
Copy link
Owner

martinlindhe commented Mar 5, 2016

All converted units with the exception of temperatures can be easily converted using multiply, like this:

in := (Meter * 5).Inches()

It would be nice if temperature could too be used in this fashion, removing the need for special casing in the lib.

Some failed attempt exists in branch "temp" in
8478d54

@jfkonecn
Copy link

I like the way you've done your temperature logic better. I think you should move the rest of the code in that direction. I think it gives consumers of your code better readability. If I have a method that calculates the area of a box I could make the method signature look something like this
(This assumes all of your underlying units are SI units)

func AreaOfBox(l Length, w Length, h Length) Volume {
	return Volume(l * w * h)
}
func FromMeter(l float64) Length {
	return Length(l)
}
assertFloatEqual(t, 2*6*5, AreaOfBox(FromMeter(2), FromMeter(6), FromMeter(5)).CubicMeters())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants