Tier 2
Series 102
102B: The Null Check Protocol
"You don't fire a missile if the targeting computer says "NO LOCK." In code, null means "No Lock." If you try to access a variable that is null, your game crashes. A skilled Engineer audits for Defensive Coding."
The Concept: The Null Coalescing Operator
Checking for null is the most common safety check in C#.
* **Traditional:** if (obj != null)
* **The Elvis Operator (?):** obj?.DoSomething() - "If obj exists, do it. If not, skip it."
* **The Null Coalescing Operator (??):** result = value ?? defaultValue - "Use value. If it's missing, use default."
* **Traditional:** if (obj != null)
* **The Elvis Operator (?):** obj?.DoSomething() - "If obj exists, do it. If not, skip it."
* **The Null Coalescing Operator (??):** result = value ?? defaultValue - "Use value. If it's missing, use default."
Red Flag Detected
The AI Trap: "The Blind Fire"
You ask the AI: "Find the nearest enemy and attack it."
// AI-Generated Code: Dangerous
void AttackNearest() {
Enemy e = FindNearestEnemy();
// Audit Fail: What if there are NO enemies?
// Crash: NullReferenceException
e.TakeDamage(10);
}
This is "Optimistic Failure." The AI assumes success. Real-world systems fail often. If FindNearestEnemy returns null, your game dies.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Pilot's Correction
Corrective Protocol
// Corrected: Safe and concise
void AttackNearest() {
Enemy e = FindNearestEnemy();
// "If e is NOT null, take damage. Otherwise, do nothing."
e?.TakeDamage(10);
}
Your Pilot Command
> A professional Pilot uses USS (Unity Style Sheets) to separate visual style from UI structure.