News for hackers. Stuff that matters.
Re:Simplify Your Code: Functional Core, Imperative Shell by time4tea on Tuesday October 28, 2025 @01:11AM (#45729374)
Not a single person in this thread commented on the use of Date.now() and similar - surely clock.now() - you never ever want to use global time in any code, how could you test it?

clock in this case is a thing that was supplied to the class or function. It could just be a function: () -> Instant.

(Setting a global mock clock is too evil, so don't suggest that!)

Re:Simplify Your Code: Functional Core, Imperative Shell by POiNTx on Tuesday October 28, 2025 @01:20AM (#45729426)
I was just referring to how pipes make these kinds of chained function calls more readable. But on your point, I think using Date.now() is perfectly ok.
Re:Simplify Your Code: Functional Core, Imperative Shell by vlovich123 on Tuesday October 28, 2025 @05:00AM (#45730591)
What happens during a daylight savings adjustment?
Re:Simplify Your Code: Functional Core, Imperative Shell by POiNTx on Tuesday October 28, 2025 @06:27AM (#45731105)
You use UTC which doesn't adjust daylight savings.
Re:Simplify Your Code: Functional Core, Imperative Shell by ruszki on Tuesday October 28, 2025 @09:38AM (#45732741)
> I think using Date.now() is perfectly ok.

This is why we have tests which we need to update every 3 months, because somebody said this. This is of course, after a ton of research went into finding out why the heck our tests broke suddenly.

Re:Simplify Your Code: Functional Core, Imperative Shell by Izkata on Tuesday October 28, 2025 @01:14PM (#45735705)
I would call those badly-written tests. The current date/time exists outside the system and ought to be acceptable for mocks, and in python we have things like freezegun that make it easy to control without the usual pitfalls of mocks.
Re:Simplify Your Code: Functional Core, Imperative Shell by ruszki on Tuesday October 28, 2025 @01:51PM (#45736273)
What are those mock pitfalls, which are avoided by freezegun which is a mock according even to them? IoC and Clocks solve the same problem. So what are the pitfalls of using those instead of this other mock?
Re:Simplify Your Code: Functional Core, Imperative Shell by Izkata on Tuesday October 28, 2025 @02:09PM (#45736572)
Applying it to the wrong module, a very common mistake in python due to how imports work.
Re:Simplify Your Code: Functional Core, Imperative Shell by MarkMarine on Tuesday October 28, 2025 @10:55AM (#45733685)
nit picking on the example code while missing the example the code was trying to demonstrate. I see why TAOCP used pseudocode
Re:Simplify Your Code: Functional Core, Imperative Shell by time4tea on Tuesday October 28, 2025 @02:47PM (#45737081)
Agreed! But i didnt miss the example.... i also thought it was interesting that all the various examples of declarative or applicative did Date.now(), which i see as a big thing to avoid.