Celestial Software Programmers

Disclaimer: All characters and events in this blog are fictional, irrational, and superstitious. Any resemblance to real characters or organization, superstitiously or irrationally, is surely due to psychiatric problems.


Day 1
Location: Conference room
Time: 9 AM, 1st Jan 4000 BC.
CEO: The contract has been signed, we have to complete the coding and testing fast, the Go Live is in 7 days. System should perform well, we are expecting a load of around 10 billion users.
Team lead: But! We do not have enough resources, we have just 5 developers and 3 testers!
CEO: How many do we need?
Team lead: To go live in 7 days we need 10 developers and 7 testers!
15 developers (creature with hunch backs and 4 arms) and 10 testers (creatures with 4 eyes and 1 arm) get spawned.
CEO: Fine, get on with the work, mail me a status update at EOD.

Location: Team lead’s desk
Time: 5 PM, 1st Jan 4000 BC
Team lead typing on his Mac –

Dear CEO,

We have completed the code for instantiating the Heaven and the Earth objects.
As per the design specifications provided by you, the constructor for Earth class is kept public and for Heaven it’s private. We will be programming further tomorrow and fix if any issues are raised by the testers.

Regards,
The Team Lead.

Location: A tester’s desk
Time: 5.15 PM, 1st Jan 4000 BC
Tester logging a defect on the defect management portal.
Defect Type: Show stopper
Defect Description: The connection between Earth and Heaven fails with Socket Exception
Steps to simulate:
  1. Instantiate Heaven and Earth Objects.
  2. On the Earth’s portal, click on “Go to Heaven” Button
  3. The screen redirected to “Sorry, no connection found”
Expected Result:
Welcome to Heaven” Page should be displayed.

Day 2
Location: CEO’s Cabin
Time: 10 AM, 2nd Jan 4000 BC
Team Lead: My Apologies but we are little confused with the tasks you have assigned us for today… regarding the firmament stuff… we need to separate water with firmament in-between, but the design specifications are not clear about the ratio at which the division needs to be done, will it be 50-50 or 10-90 or 90-10 or something else.
CEO: hmm, what?
Team Lead: aah… water…. how much for heaven and how much for earth?
CEO: ah right, put it on earth, we drink other stuff anyway.
Team Lead: all of it?
CEO: did you ask something?
Team Lead: Never mind.

Location: A developer’s desk
Time: 3 PM, 2nd Jan 4000 BC
Developer adding comment on defect management system.
Comment –
Invalid defect, not able to simulate using the steps provided.
The heaven object fails to get instantiated, there’s no Socket Exception.
Please close the defect.

Day 3
Location: A Developer’s desk
Time: 11 AM, 3rd Jan 4000 BC
Team Lead yelling
Team Lead: Why is this object spawning a tree?!! Did you read the emails I sent?!! I told the seed object should instantiate a new tree and not leaves!!
Developer: I will fix it right away sir, (developer drags some stuff on his S-shaped curved 6DLED Screen), here it is.
Team Lead: No!!! Not that way!! The seeds should validate on the ‘type’ private variable. The mango seed won’t instantiate a banana plant! Fix that!!!
Developer: Ah sorry, ya fixing it!
Team Lead: hmm ok, get it tested today!

Location: A tester’s desk
Time: 4 PM, 3rd Jan 4000 BC
Tester logging a defect on the defect management portal.
Defect Type: Major
Defect Description: Unexpected plant growth
Steps to simulate:
      1. Instantiate a plant object of type grass
      2. Cut the grass into half.
      3. Take the bottom half, called root as per design document
      4. Invoke the plantInSoil function
      5. Grass grows.
Expected Result:
Plant should only grow from seeds as per design document

Day 4
Location: CEO’s Cabin
Time: 10 AM, 4th Jan 4000 BC
Team Lead: This is so weird requirement! Why you need us to provide the client with two different lighting systems? And… we need to schedule it at 12 hours? We will need multi-threading for it, we already run two threads, one for heaven and one for earth, now you want us to run two more threads for sun and moon? Why can’t we just keep a fixed sun, why rotate them periodically and that too at different frequency? It’s an overhead.
CEO: That’s a good idea, separate threads for the stars would be good too.
Team Lead: What! No!!! Stars are redundant, why even have them?! And what’s this no moon night that’s in the contract? Why have the client agreed on having a no moon night and having just some dim stars? They will just use up the CPU resources without giving much throughput!
CEO: So, do you have any more questions?
Team Lead: More Questions? I haven’t got any answers for the things I asked!
CEO: Fine then, mail me a status update before EOD.

Location: Team lead’s desk
Time: 5 PM, 4th Jan 4000 BC
Team lead typing on his Mac –

Dear CEO,

We have completed the code for instantiating the Sun, the Moon and the Stars.
As per design the Moon is kept little dimmer than the Sun, which enables the user to also view the stars at night. For the day time, we are applying a CSS style on the firmament to hide the heavens which might be visible from earth due to sun’s brightness. Please review the following code –
.firmament {
background-color: skyblue; //suggest any other color if you like
}

Regards,
The Team Lead.

Location: A tester’s desk
Time: 5.15 PM, 4th Jan 4000 BC
Tester logging a defect on the defect management portal.
Defect Type: UI
Defect Description:
Some parts of moon are missing on some days and a rabbit shaped shadow is visible on the moon which might be causing the low light conditions on earth.
Expected Result:
Moon should be round and uniformly lit.


Day 5
Location: Office Canteen
Time: 1 PM, Lunch time, 5th Jan 4000 BC
Developer 1: Can you believe, if our code works tomorrow, we can have flying creatures.
Developer 2: You mean birds?
Developer 1: Ya! And swimming creatures too!
Developer 3: And running creatures too!
Developer 1: I am so excited!
Developer 2: But did you see, we have some crawling creatures in design too, it doesn’t make sense! Why some creatures will crawl when others can fly?
Developer 1: Common! It’s more fun to have a variety!
Developer 2: But it’s so unfair to the crawlers!


Day 6
Location: A tester’s desk
Time: 5 PM, 6th Jan 4000 BC
Tester logging a defect on the defect management portal.
Defect Type: Minor
Defect Description:
Some of the building components of some creatures are unreliable.
Steps to simulate:
      1. Instantiate a tortoise object
      2. Invoke the Run function
      3. Increase speed till 100 miles per hour
      4. The instance variable ‘leg’ throws CantRunFasterException
Expected Result:
Creatures with legs should be able to run at any desired speed.


Day 7
Location: Conference Room
Time: 9 AM, 7th Jan 4000 BC
CEO: Is the scanner ready?
Team Lead: Yes Sir, let’s take your image.
CEO climb on the specially designed 3D scanner and the Team lead presses some button and gets the output as serialized objects on his Mac.
Team Lead (to a developer): I need you to make two deep copies of this scan into type human, set one as gender type female with the left scan and gender type male with the right scan. Also get the compatibility test done. And ya, set the immortality parameter to false.
Developer: Roger that!
CEO: Wait! Skip the testing part. It’s already the 7th day, no more time for testing and other stupid stuff. Make it live as soon as you are done with coding!
Team Lead: But sir, we have some defects pending, we haven’t done a load test, we are expecting around 10 billion users hitting the Earth thread in just 10,000 years, what if the system can’t support?
CEO: Don’t worry we have other plans, we can use distributed computing and use our other server Mars if needed. We can also keep some backup at Moon, I know it’s a lighting system but we can manage.
Team Lead: Fine.

Location: Conference Room
Time: 11 AM, 7th Jan 4000 BC
System Goes Live!
Celebrations all around in office. 

Does optimized imports improves performance?

Many of us have an idea that we optimize imports to improve performance.

We are told that we should import only the specific classes we need instead of whole packages.

import java.util.*;
import java.util.ArrayList;
import java.util.Map;

But does this really improve performance?


Let’s compare the bytecode generated after compilation to understand the difference.
We prepare two classes as below and generate their bytecode by compiling using the javac command –

A sample code with whole package imported A sample code with just the required classes imported
import java.util.*;

public class WholePackage {
ArrayList arrayList;
}

import java.util.ArrayList;

public class JustTheClass {
ArrayList arrayList;
}

Let’s use the Java’s code disassembler to see how it would be interpreting the bytecode.
we run the following commands on the class files to disassemble them –

javap -c WholePackage > WholePackage.out javap -c JustTheClass > JustTheClass.out
Compiled from “WholePackage.java”
public class WholePackage {
java.util.ArrayList arrayList;
 

public WholePackage();

Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object.””:()V
4: return
}

Compiled from “JustTheClass.java”
public class JustTheClass {
java.util.ArrayList arrayList;

public JustTheClass();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object.””:()V
4: return
}

Surprisingly or may be to my ignorance, the disassembled code is same for both. We can safely conclude that there’s no performance gain from exclusively importing classes instead of importing the whole package.


Then why is it a bad practice to import the whole package?

There are bigger risks than just performance.

Say I have a class named ArrayList in my package (of course i am not advising to make your classes named same to the java library ones) and I am also using java.util.HashMap in my Class. If I import java.util.* there can be incorrect imports at compile time that can go undetected.

Or the other way round if I have some classes like say GreatlyNamedAwesomeClass and I am also using a third party libraries (say import weirdjava.customlang.*; )  and the third party developers somehow also added a class named GreatlyNamedAwesomeClass in their next release… I would have some trouble making things compatible if I need to.

Have a look how my code broke as my package’s ArrayList is not having an add method (luckily, at least the compiler could catch it).

Cannot resolve method 'add(java.lang.String)'

So the primary reason for not using the wildcard imports and to exclusively import the classes is to avoid ambiguity and not performance optimization.