Tier 1 Series 2

2D: Method Signatures

Pilot Record
Student Profile
"Imagine a pilot asking the co-pilot for the current altitude. The co-pilot answers, but while doing so, they also decide to dump the fuel without being asked. The question was simple, but the "side effect" was catastrophic.

In C#, Methods are your commands. If a method claims to calculate a value but also changes a global variable behind the scenes, you have a Side Effect."

The Concept: Pure vs. Impure

Inputs and outputs define the "contract" of a function.

Pure Functions: Given the same input, they always return the same output and change nothing else.
Side Effects: When a method modifies data outside of its local scope.
Parameters: The "Ask."
Return Types: The "Answer."
Red Flag Detected

The Audit: Spot the "Side Effect" Error

You ask the AI: "Write a function to check if the aircraft has enough fuel to reach the destination."

// AI-Generated Code (Impure)
public bool CanReachDestination(float distance) {
    float fuelNeeded = distance * 0.5f;
    if (currentFuel >= fuelNeeded) {
        return true;
    } else {
        isEmergencyDeclared = true; // SIDE EFFECT: Changing state!
        return false;
    }
}

This method is named as a "Check" (returning a bool), but it secretly modifies isEmergencyDeclared. If you call this check multiple times for telemetry, you might trigger an emergency state without meaning to.

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 Code (Pure Calculation)
public bool HasSufficientFuel(float distance, float currentFuel) {
    return currentFuel >= (distance * 0.5f);
}

// Action logic is handled separately by the caller
if (!HasSufficientFuel(dist, fuel)) {
    DeclareEmergency();
}
Your Pilot Command
> Implement MaterialPropertyBlock to enable efficient GPU Instancing.
Next Mission
Value vs. Reference