Profile picture
Michael D. Hill @GeePawHill
, 12 tweets, 2 min read Read on Twitter
TDD pro-tip: any "time" u refer to a clock, be on the lookout.
it's a time -- i just can't help myself -- to seriously microtest your way through.
if you have to talk about "now", consider whether you want to be able to pass a clock rather than call the system. for the price of an additional argument, you get perfect testability.
the price of resistance? your now-based object will have to be thought about every time you place it inside another object as a component.
some middle grounds that might be appropriate: 1) use a default argument for that clock. 2) use a global with settability -- what most people naively call a singleton.
when you do clock or date math, always always always test *on* the boundary point in addition to clearly-before and clearly-after. if you don't, you're sure to blow inclusive/exclusive endpoints for durations.
never assume that two calls to the system now have a certain gap between them. two calls to now might be the same time, they might be split by a tiny amount, they might be split by a lot. it is not a countable-on kinda thing.
finally, if you're manipulating times a lot, please do use a serious library rather than rolling your own. it's not cuz i'm against re-inventing wheels, i do that all the time.
it *is* about efficiency, but not in the way you think. you are so extraordinarily likely to handle the complexities of time and date correctly against all cases that you will waste way too much time -- lord, help me -- later debugging corner cases.
oh wait, i got another, cuz joe was responding in real time -- help! i'm trapped in a pun factory -- think of time as a set of timestamps, and think of them as potentially going backwards. yes. backwards.
that's all. have fun.
oops, on re-read. that should be "you are so extraordinarily *un* likely to handle..." in other words, you're gonna screw up a million different ways and spend the rest of your life sitting cold and lonely on a parkbench with a bottle and NO FRIENDS.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Michael D. Hill
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!