1.24 Skill builder: Qualities of a Programmer

Objects and Properties

Let's say I have pet chicken.

It's name is Prince Rupert the Second, it is dark brown, it has long feathers and is 2 years old.

I can store this information in the following (slightly awkward) ways:

1. Using a different variable for each property (time consuming)


	var chickenName = "Prince Rupert the Second";
	var chickenColour = "dark brown";
	var chickenFeathers = "long";
	var chickenAge = 2;
	
	console.log(	// output the chicken information
		"My chicken's name is " 
		+ chickenName 
		+ ". It is " 
		+ chickenColour 
		+ " with " 
		+ chickenFeathers 
		+ " feathers. It is " 
		+ chickenAge 
		+ " years old."
		);
			

2. Stuffing each property into an array (time consuming, and an ugly hack)


	var nameIndex = 0;
	var colourIndex = 1;
	var feathersIndex = 2;
	var ageIndex = 3
	
	var chicken = []; // define as an empty array
	
	chicken[nameIndex] = "Prince Rupert the Second";
	chicken[colourIndex] = "dark brown";
	chicken[feathersIndex] = "long";
	chicken[ageIndex] = 2;
	
	console.log(	// output the chicken information
		"My chicken's name is " 
		+ chicken[nameIndex]
		+ ". It is " 
		+ chicken[colourIndex]
		+ " with " 
		+ chicken[feathersIndex]
		+ " feathers. It is " 
		+ chicken[ageIndex] 
		+ " years old."
		);
			

3. Create an object with a series of properties (elegant & fast)


	var chicken = {}; // define as an empty object
	chicken.name = "Prince Rupert the Second";
	chicken.colour = "dark brown";
	chicken.feathers = "long";
	chicken.age = 2;
	
	console.log(
		"My chicken's name is " 
		+ chicken.name
		+ ". It is " 
		+ chicken.colour
		+ " with " 
		+ chicken.feathers
		+ " feathers. It is " 
		+ chicken.age
		+ " years old."
		);
	
			

Assigning properties to an object

There are several ways to assign properties to an object. First, define your variable:

var chickenObject = {}; // define as an empty object

Then you can assign values to each property. Each of the following methods is exactly the same:

Reading properties of an object

Once the property values are stored, then you can get the information out again. Each of the following methods is exactly the same:

Objects and function pipelines

One of the reasons why programmers love objects is because they organize a lot of information under one variable. This means that you can pass them easily between functions in a function pipeline.


	function  mainProcedure() {
		var inputObject 	=getInfoObject();		// note that this function returns an object
		var outputString	=processTheObject(inputObject);	// note that this function accepts an object as an argument
		outputInfo(outputString);
	}
			

Take a look at the following code:

Notice that mainProcedure(), makes the following function pipeline:

initCharacterObject()
returns: charObject
createCharacterInfo(charObject)
returns: thisInfoString
outputCharacterInfo(thisInfoString)

Saving your work

Download the template and rename it to your last name, such as "1.24S-QualitiesOfAProgrammer-LastName.html".

The assignment

Modify the code above to create a program that outputs information about ONE of the following heroes of programming using objects and function pipelines.

For example

Ada Lovelace was born in 1815 and is famous for inventing the first programming language.

A few programming heroes...

Some famous programmers for you to consider using...
programmer.name Ada Lovelace Alan Turing Steve Wozniak Tim Berners-Lee Limor Fried Your own choice
programmer.imgSrc AdaLovelace100px.png

AlanTuring100px.png

SteveWozniak100px.png

TimBerners-Lee100px.png

LimorFried100px.png

?
programmer.born 1815 1912 1950 1955 c. 1977 ?
programmer.famousFor Inventing the first programming language Cracking the German enigma code Doing most of the code and hardware for Steve Jobs in the early days of Apple Inventing the internet Open-source hardware entrepreneurship at Adafruit ?

You will need to consider the following