Do You Have a Sister?

Infinity had looked under the weather for a few days. She was quite bad at hiding emotions, but I wasn't sure what the cause of her sadness was. Once when we both were making a coffee in the kitchen, I decided to ask her what was wrong.
First, she replied wearing her leader hat, saying that everything was fine and that she didn't know what I was asking. She must have seen the look of concern on my face, because a few seconds later, she suddenly burst into tears.

"It's okay Infinity, you can talk to me," I said.
"They g-g-got her. They got my s-s-sister," she sobbed.
"Who are 'they'? What do you mean by 'got'?" I didn't understand what had happened - was Infinity saying that the machines had infiltrated?.
"My sister, Olivia, was the second best programmer in Wonderland. She had a mission to reveal new robot versions, and I told her it was dangerous, but she... she never listens to me."

Goddamnit - they got our second best programmer! I had been doing well in my studies and was slowly rising in the ranks. How long would it be before they started working their way down the line and put a target on my back? What should I do? Think, Teo, think!

"When, and where?" I asked.
"In Sector C15, about a week ago. We did our best to track her location after the incident, and we managed to figure out that she's in B29 now. They keep her in a transfer bunker, ready for transportation at any moment. It's right next to Ritchie's resistance base. This means we have a few beginners nearby, not much more than that," Infinity answered, her voice was sad.

"That's where I was at before I came to Wonderland. Is there any way to get in that bunker?" I asked.
"We've looked for all possibilities. Droids constantly patrol the perimeter. Unfortunately, their model is very outdated; we don't have anyone who know how to reprogram them," Infinity replied.

"You have one. Gather a security group - we'll save your sister," I put tremendous effort to make my voice sound confident and secure, like in a Hollywood movie. Inside, of course, I was quite frightened.



By 11:00 am the next day, we were near the transfer bunker. I counted six police drones. They looked the same as those that I reprogrammed on my first day in the future. In the present future. In the present... You understand what I mean.

"We got you here, Teo. Now it's up to you. You need to reprogram them one by one to force to leave the area," Infinity commanded.
I left my cover and snuck within range of a drone that was a bit away from the others. Using my tablet, I established a wireless connection.
The code that I saw was different from what I had worked on previously:

class AdvancedDroid
  private int xPosition;
  private int yPosition;

  public AdvancedDroid(int xPosition, int yPosition)
      this.xPosition = xPosition;
      this.yPosition = yPosition;

  public void MoveTo(int x, int y)
      this.xPosition = x;
      this.yPosition = y;

"Infinity," I whispered into my headset, "what does this mean? We haven't covered that before..." I asked.
"Are you sure, you are the right person to reprogram those droids?" Infinity questioned. She continued:
" This is a keyword in C# that represents the current object of a class. That object is where the code is running. "

Maybe I was in a bit over my head. "Where is it used? Why is it useful? Why does this code refer to private variables with this when they could just omit it?" I shot back in rapid-fire.
" This depends on a naming convention. If the programmer chooses not to use underscores for private fields, their names may collide with local variables and function or constructor arguments. To distinguish fields from others, you can use the this keyword to point out that you want to work with a field now."

Infinity added, "One more interesting use of this it to pass current object somewhere; for example, to a method."

class Person
    public string Name;

    public void PrintNameUsingPrinter()
        Printer.PrintNameNicely(this); // Passes current object to the printer

class Printer
    public static void PrintNameNicely(Person person)
        Console.WriteLine($"Welcome, {person.Name}");

Strange joke


It didn't work. Well, to be more precise, it did; but the outcome was not enough to deactivate droids. We had one hour to fix everything, and it took 20 minutes to finish with one droid, which left five remaining. We clearly had to change tactics if we were going to save Infinity's sister.

Abruptly, Infinity said, "We can force droids to infect each other, similar to the goal of the Rust project!"
"Brilliant!" I said, "Let's hack their communication system!"
Hope and enthusiasm spread inside of me.
The Droid's communication module code looked like this:

class Droid
    private Droid[] _neighbours;

    public Droid(Droid[] neighbours)
        _neighbours = neighbours;

    public void BroadcastMessage(string message)
        for (int i = 0; i < _neighbours.Length; i++)

    public void ReceiveMessage(string message)
        if (message.Length < 255)
            Console.WriteLine("Message is too long to display");

I can change this code for one droid, but it would remain the same for all others. The code looks clean and safe. How could I break all other droids having only this one under control ?

"Noname, I need help. Are you there?" I asked in my head.
"Yes, my lord. I am here and waiting for your orders, sir!"
"Have you updated your speech module?" I asked.
"Yes, milord, I have."
"Never mind, we'll talk about it later. I need your help now. We have 10 minutes left to deactivate five droids, and I have only one under control. The only thing I know is that the others have the same functioning code. When my droid broadcasts a message, all others receive it. What can I do?" I asked him, practically begging.
"One moment, Sir. Scanning code... Right, one of the most available and reliable solutions taking into account current circumstances..."

"Noname! Just the specifics," I shouted in my mind.
"Broadcast null ."
"What is null ?"
" Null represents an empty reference, i.e., one that does not refer to any object. null is the default value of reference-type fields. "
"And the default value is the one that is assigned to an object before we use the new operator?" I asked.
"Let's get there step by step, sir. Fist important fact to remember: local variables should always have some value assigned before you work with them. Otherwise, your program won't compile. This holds for reference and value types ," Noname said.

string s; // s is unassigned
if (s == null) // COMPILE ERROR: Can't use unassigned variable
    Console.WriteLine("s is null");

int n; // n is unassigned
n++;   // COMPILE ERROR: Can't use unassigned variable

"Got it, Noname. What about class fields? What default value do they take?" "Class fields take, we can call it, a zeroed value, which means that it is null for reference types, and all memory is filled with zeros for value types. "

class ClassWithNotInitializedFields
  string _someReferenceType; // This one gets default value - null
  int _someValueType;        // This one gets default value - 0

  public void DoWork()
      if (_someReferenceType == null)
          Console.WriteLine("_someReferenceType is null");

      if (_someValueType == 0)
          Console.WriteLine("_someValueType is 0");
// If DoWork is called, output is:
// _someReferenceType is null
// _someValueType is 0

" You can also assign null to any reference type, but not to a value type ," Noname further explained.

string s = null;     // Fine, assigning null to a reference type
int i = null;        // ERROR: Can't assign null to a value type
int[] iArray = null; // Fine, array is a reference type

double d = 0.0;      // Fine, assigning zero to a value type
string str = 0.0;    // ERROR: Can't assign zero to a reference type

"Teo, I would like to add one crucial fact," Noname said.
"Just do it, don't preface it!" I was nervous. Time, time, time!
" You can't call a method or access a field on a null object. Such behavior causes a NullReferenceException. An exception is a runtime error: the program will compile, but it will fail dramatically during execution. I've prepared a demonstrating code snippet for you:"

string s = null;

int i = s.Length; // ERROR: field access on a null object

int[] array = null;

array[0] = 12;  // ERROR: trying to access an array cell on a null object
array.Clone();  // ERROR: calling a method on a null object

Infinity's voice brought me back to reality. "Teo, where are you? Are you still there? We have to do something!"
I looked at the timer - 5 minutes to deactivate the rest of the droids and have a chance to save Infinity's sister.

As soon as I sent the message, the remaining droids immediately stopped. I was hoping this would prove to be the hardest part of the rescue.
We entered the building and found Infinity's sister in some kind of Faraday cage.

Double agent

Well done

At Codeasy we believe that learning should be fun and engaging. Please reach out to us to share your feedback and collaboration ideas.