Avoiding Encodings and Hungarian Notation
What you'll learn: Why embedding type or scope information directly into variable names is outdated and makes code harder to read.
What Are Name Encodings?
Name encodings are systems where you add prefixes or suffixes to variable names to indicate their type, scope, or other metadata. The most famous example is Hungarian Notation, where you'd prefix variables like strName, iCount, or bIsActive to show their types (string, integer, boolean).
Other encodings include scope prefixes like m_ for member variables (m_totalScore) or g_ for globals (g_appConfig).
Why Were They Used?
Decades ago, programming tools were primitive. IDEs didn't show you type information on hover, and compilers gave cryptic error messages. Developers embedded this metadata directly into names as a survival mechanism—like writing reminders on sticky notes because you had no calendar app.
Why They're Obsolete
Modern development environments render encodings unnecessary:
- IDEs show types instantly when you hover over a variable
- Compilers catch type errors before you run code
- Refactoring tools automatically update types across your codebase
How They Harm Readability
Prefixes add visual noise that your brain must filter out. Compare:
- With encoding:
strUserName,iUserCount,bUserActive - Without encoding:
userName,userCount,isActive
The second set is cleaner and focuses on what the variable represents, not how it's stored. When you refactor userName from a string to a custom UserName class, you don't want to rename it everywhere because the prefix lies.
The Modern Alternative
Let your tools do the work. Write intention-revealing names that describe the variable's purpose. Trust your IDE and compiler to track types.
Key Takeaway: Avoid embedding type or scope information in names—modern tools make these encodings redundant, and they clutter code with outdated metadata that can become misleading.