3 ms·
From the first example: private final double price; private final LocalDateTime sentAt; Can't help but notice that they won't be able to trade at exac
by nitrogen 7y ago
From the first example:
private final double price;
private final LocalDateTime sentAt;
Can't help but notice that they won't be able to trade at exact decimal amounts whose fractions aren't sums of powers of 1/2.
Also wouldn't Instant be better for a timestamp?
- pintxo 7y agoProduction code likely should use neither double for currency nor LocalDateTime for a point in time. But for the purpose of the article, which is about Records being a new type of Java class, this is kind of irrelevant.
- nitrogen 7y agoI think it's kind of a problem if examples of how to write Java are full of bad practices.
- barnaclejive 7y agoExamples are usually bad production code. The sky is blue.
- pgwhalen 7y agoFor what it's worth, I work at a place that would write a similar domain object, and we would use both of those and not feel bad about it. The FUD on money as a double is way overblown in my opinion - it only becomes a bad idea once you have to do precise math with the it (which is admittedly a lot of the time when you're dealing with money, but surprisingly rarely in some domains).