cover-img

Code Smell 77 - Timestamps

Timestamps are widely used. They have a central issuing authority and do not go back, do they?

19 June, 2023

2

2

0

Timestamps are widely used. They have a central issuing authority and do not go back, do they?

TL;DR: Don't use timestamps for sequence. Centralize and lock your issuer.

Problems

  • Bijection Fault.
  • Timestamp Collisions.
  • Timestamp precision.
  • Packet Disorders.
  • Bad Accidental Implementation (Timestamp) for an Essential Problem (Sequencing).

Solutions

  1. Use a centralizing sequential stamper. (NO, not a Singleton).
  2. If you need to model a sequence, model a sequence.

Sample Code

Wrong

# using time module
import time

# ts stores the time in seconds
ts1 = time.time()
ts2 = time.time() # might be the same!!

Right

numbers = range(1, 100000)
# create a sequence of numbers and use them with a hotspot

# or
sequence = nextNumber()

Detection

Timestamps are very popular in many languages and are ubiquitous.

We need to use them just to model... timestamps.

Tags

  • Bijection

Conclusion

This smell was inspired by recent Ingenuity software fault.

If we don't follow our MAPPER rules and model sequences with time, we will face trouble.

Luckily, Ingenuity is a sophisticated Autonomous vehicle and has a robust fail-safe landing software.

This video describes the glitch

https://www.youtube.com/v/6IoMiwxL2wU

Relations

Code Smell 39 - new Date()

Code Smell 32 - Singletons

Code Smell 71 - Magic Floats Disguised as Decimals

More Info


The most beautiful code, the most beautiful functions, and the most beautiful programs are sometimes not there at all.

Jon Bentley

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code

2

2

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.