Code Smell 310 – Why Generic Date Names Break Your Code

Written by mcsee | Published 2025/09/29
Tech Story Tags: clean-code | refactor-legacy-code | code-refactoring | descriptive-variable-names | code-smells | semantic-naming | code-quality | naming-conventions

TLDRGeneric names like date make code confusing, harder to maintain, and prone to bugs. Instead, use descriptive names (e.g., publishDate, expiryDate) that reveal intent and business purpose. This clarity improves readability, reduces debugging headaches, and aligns code with real-world concepts. AI tools often default to vague naming, so it’s critical for developers to guide them with context. Naming is not cosmetic—it’s a design decision that shapes the quality of your code.via the TL;DR App

When 'date' doesn't tell you what you need to know


TL;DR: Use descriptive date names that reveal their role and business purpose instead of generic "date" labels.


Problems to Consider

  • Unclear purpose
  • Maintenance nightmares
  • Poor readability
  • Debugging confusion
  • Names suggesting types
  • Vague and short names
  • Hidden intent
  • Wrong context
  • Extra guessing
  • Hard search
  • Misleading reuse
  • Ambiguous purpose
  • Reduced readability
  • Misinterpretation risk

Proposed Solutions 😃

  1. Use descriptive names
  2. Reveal business intent
  3. Keep names consistent
  4. Follow the domain language
  5. Add semantic meaning
  6. Improve code clarity
  7. Add context words
  8. Avoid generic terms
  9. Replace comment with better names

Refactorings

https://refactoring.guru/rename-method?embedable=true

https://hackernoon.com/refactoring-005-replace-comment-with-function-name?embedable=true

Context

When you work with dates in your applications, you often encounter variables, methods, or attributes simply named 'date'.

This generic naming forces other developers (including your future self) to dig through the code context to understand what the date represents.

Does it track creation time? Publication date? Expiration date? Last modification date?

The ambiguity creates maintenance overhead and increases the likelihood of defects when you mix up different date purposes.

Sample Code 📖

Wrong

class Article {
  final DateTime date;
  final String title;
  final String content;

  Article({
    required this.date,
    required this.title,
    required this.content,
  });
}

Right 👉

class Article {
  final DateTime publishDate;
  final String title;
  final String content;

  Article({
    required this.publishDate,
    required this.title,
    required this.content,
  });
}

Detection

  • [x]Semi-Automatic

You can detect this smell when you see variables, methods, or properties named generically as "date," "time," "timestamp," or similar non-descriptive temporal names.

Look for methods that manipulate dates without clearly indicating which date they affect.

Code review tools and static analysis can flag generic naming patterns; however, manual inspection often reveals the business context more effectively.

Comments explaining what a date represents are also worth searching for.

Multiple date fields with numeric suffixes (date1, date2) are another hint.

Exceptions 🛑

Sometimes you work with truly generic date utilities or abstract interfaces where the specific date purpose varies by implementation.

In these rare cases, generic naming might be appropriate, but you should document the expected semantics clearly.

Tag(s)

  • Naming

Level

  • [x]Beginner

Why Bijection Is Important

Your code should maintain a clear one-to-one correspondence between real-world concepts and their programmatic representations.

When you name a date generically, you break this bijection by forcing readers to infer the real-world meaning from context.

In the real world, dates have specific purposes: publication dates, creation dates, expiration dates, and birthdates.

Your code should reflect these distinct concepts directly through naming, creating an unambiguous mapping between domain concepts and code elements

A publishDate corresponds to an actual publishing date in life.

If you use date, you break this mapping.

Notes on AI Generation 🤖

AI code generators frequently create this smell because they default to generic naming patterns when they lack specific business context. They often suggest "date" as a safe, universal name without considering the domain-specific purpose of the temporal data.

Some AI generators create this smell because they favor brevity, naming it date instead of clarifying its role.

AI Detection 🧲

AI tools can easily identify and fix this smell when you provide clear instructions about the business domain and the specific purpose of each date attribute and method.

Modern AI assistants excel at suggesting contextually appropriate names when provided with adequate domain-specific information.

Try Them!

Remember: AI Assistants make lots of mistakes

Suggested Prompt: replace any generic date/time variable names with descriptive names that clearly indicate their business purpose. For each date field, consider what specific moment or event it represents in the domain (creation, publication, expiration, last access, etc.) and name it accordingly

Without Proper Instructions

With Specific Instructions

ChatGPT

ChatGPT

Claude

Claude

Perplexity

Perplexity

Copilot

Copilot

You

You

Gemini

Gemini

DeepSeek

DeepSeek

Meta AI

Meta AI

Grok

Grok

Qwen

Qwen

Conclusion

When you use generic names, you shift the burden to the reader. Choose names that tell the story of the business. Naming dates specifically isn't just pedantry. It's about making your code communicate its intent clearly. The few extra characters you type save countless minutes of confusion for future readers, including your future self.

Related Reading

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xiii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-vii-8dk31x0

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxiii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxv

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-viii-8mn3352

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxix

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-viii-8mn3352

Additional Info

https://hackernoon.com/what-exactly-is-a-name-the-quest-part-i-fmw3udc

https://hackernoon.com/what-exactly-is-a-name-rehab-part-ii-4st3uph


Disclaimer: Code Smells are my opinion.


Credit: Lead image by Towfiqu barbhuiya on Unsplash


Precise naming is a design decision, not a cosmetic one.

Eric Evans

https://hackernoon.com/400-thought-provoking-software-engineering-quotes?embedable=true


This article is part of the CodeSmell Series.

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-i-xqz3evd?embedable=true


Written by mcsee | I’m a sr software engineer specialized in Clean Code, Design and TDD Book "Clean Code Cookbook" 500+ articles written
Published by HackerNoon on 2025/09/29