News for hackers. Stuff that matters.
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.
Re:Please put units in names by akdor1154 on Monday March 21, 2022 @04:18AM (#30751585)
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.
Re:Please put units in names by taneq on Monday March 21, 2022 @05:53AM (#30752154)
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.

Re:Please put units in names by OtomotO on Monday March 21, 2022 @04:21AM (#30751604)
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.
Re:Please put units in names by _flux on Monday March 21, 2022 @05:46AM (#30752107)
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?