My brother-in-law is a freshman engineering major in college. He has no prior programming experience. He is learning programming in his classes, but he seems to be struggling with the basic concepts. It doesn't help that he seems to be the only person in all his classes without some background in programming.
He did OK in Matlab (which I don't know), and then I helped him along when he was learning the basics of Python. Pretty soon his courses will start on C and C++. I'm worried that he will be left behind when Object-Oriented Programming comes up.
I tried explaining it to him with the analogy of a car.
Pseudocode:
Class Car
{
public string make;
public string model;
private string milesPerGallon;
private float gasolineGallonsInTank = 0;
private float tankCapacity;
private float odometer = 0;
public Car(maxGas, mpg)
{
tankCapacity = maxGas;
milesPerGallon = mpg;
}
public void fillTank()
{
gasolineGallonsInTank = tankCapacity;
}
public void drive(float miles)
{
if (miles == 0)
{
print("You don't want to drive?");
return;
}
if(miles < 0)
{
print("Ok, we're driving in reverse!");
miles = Math.AbsoluteValue(miles);
}
float maxDistance = gasolineGallonsInTank / milesPerGallon;
if (maxDistance >= miles)
{
odometer += maxDistance;
gasolineGallonsInTank = 0;
print("You've run out of gas!");
return;
}
odometer += miles;
gasolineGallonsInTank -= miles / milesPerGallon;
}
public float readOdometer()
{
return odometer;
}
}
I said that the Car class was like a car factory, and var mySedan = new Car(12, 20)
was like producing a new car with a 12-gallon gas tank and 20 mpg. Then I showed him how the methods could be run, and it was like things were happening to the car.
Then I made a second car: var myMiniVan = new Car(21.5, 14)
and showed how running methods on one car didn't affect the other.
But he didn't get it. All of this went way over his head. Is there a better or simpler visual analogy I can use? Am I explaining it wrong?