Master Defensive Programming: Unconventional Naming Tricks & OOP Hacks
This article revisits defensive programming, explores quirky variable‑naming techniques—including single‑character, Chinese, and multilingual identifiers—and humorously breaks down core OOP concepts while stressing the developer’s irreplaceable role in modern software projects.
Defensive programming has resurfaced as a buzzword, originally meaning meticulous and cautious coding to build reliable software, but now it also serves to protect programmers’ positions within companies.
Code Writing
Single‑character variable names
In Java, variable names can consist of Unicode letters, digits, underscores, or dollar signs, and the first character cannot be a digit.
There are 54 possible single‑character names (26 uppercase, 26 lowercase, underscore, dollar), which is usually sufficient for a single Java file.
Using Chinese names
Chinese characters are valid Unicode identifiers, providing about 20,902 additional single‑character options, making naming extremely flexible.
Using multilingual names
Variable names can be written in any language supported by Unicode, though readability may suffer for non‑native speakers.
CV Method
The article humorously presents the OOP fundamentals—abstraction, encapsulation, inheritance, and composition—as a "CV" technique, describing each concept’s benefits and providing a short dialogue illustrating the idea.
Product Development
It advocates hard‑coding configuration values, using magic numbers, and keeping code minimal and tightly coupled to the developer, arguing that this reinforces the developer’s indispensability.
Ultimately, defensive programming is portrayed as a way to safeguard the programmer’s role and ensure smooth project delivery.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.