Re:Please put units in names
by lrem on Monday March 21, 2022 @04:12AM
(#30751542)
You can construct a linter that will prevent you from trying to add seconds to dollars.
[ Parent
| on HN ]
A better example would be seconds to minutes. I think i recall a jwt related cve related to timestamps being misinterpreted between sec/ms for example.
Adding seconds to minutes can actually make sense. A minute plus 30 seconds is 90 seconds, or 1.5 minutes. Whether your type system allows this, though, is up to the project.
You can't add seconds to kilometers, or to temperature, or to how blue something is.
Ideally you have a compiler that simply refuses to compile ambiguous code
Re:Please put units in names
by eurasiantiger on Monday March 21, 2022 @05:16AM
(#30751915)
Ideally, there is no compiler.
Ideally, you would detect all errors before runtime. Usually the compiler is the last gate to make that happen.
Re:Please put units in names
by eurasiantiger on Monday March 21, 2022 @12:11PM
(#30755776)
Ideally, hardware execution would happen on a language that can be proven correct and does not allow the programmer to make syntactic or semantic errors.
The world is far, far from ideal.
Re:Please put units in names
by CamperBob2 on Monday March 21, 2022 @05:37AM
(#30752059)
Isn't there an implicit conversion?