Re:Google’s Go Style Guide
by randomswede on Monday November 21, 2022 @04:03AM
(#33690430)
Werrrrlllllll... It all depends on what yo umean by "type". In physics problems, I find taht quantities may be measured in "floats", but have the types "mass", "amperage", "distance per second per second" and the like.
In Go, I would probably model this as:
type mass float64
type speed float64
type acceleration float64
That way, they'd all have float64 as the "storage type", but it would be harder to accidentally pass an acceleration when I wanted a mass.
Re:Google’s Go Style Guide
by robertlagrant on Monday November 21, 2022 @09:11AM
(#33692631)
> Going back to my physics example, all the variables in a physics problem are actually of the same type, float
This is why some people recommend a practice I've forgotten the name of, where they defined a new type that maps to language type. So type Mass could just be a float, but you know better how to treat it.
If you were just coding physics problems you could have types restricted to the physics domain, that is, physical units. Which it looks like MATLAB does now support: https://www.mathworks.com/help/symbolic/units-of-measurement...