Each fall I teach an Introduction to Programming class, and it’s always fascinating to see the connections students make as they experience their first real exposure to programming. Today I introduced the concept of classes, and we ended up in one of the most engaging conversations I’ve had with students in a while. Instead of drawing from my own experience to make up an example during the lesson, I asked students the following question:
If you had infinite programming skills, what would you build?
It’s a question I like to ask from time to time, and I’m really glad I asked it again today. I gave students a couple minutes to jot their answers on notecards, then asked a few students to share what they had come up with. After discussing a couple ideas I asked if anyone wanted us to use their idea as an example. One student raised her hand, and here’s what she had written:
I would write a cyber constitution for America that would have a solid set of laws, but wouldn’t limit freedom of speech.
I told her it was a great example because we can easily identify some kinds of information that should be stored in an electronic constitution, and we can also identify some actions you’d want to take when working with an electronic constitution. Here’s the class we developed during the lesson:
class CyberConstitution(): """A solid set of laws, that doesn't limit speech.""" def __init__(self): """Initialize the constitution.""" self.state = '' self.author = '' self.preamble = '' self.laws =  def add_law(self, new_law): """Add the new law to the list of existing laws.""" self.laws.append(new_law) def show_laws(self): """Show all the laws in the constitution.""" for law in self.laws: print(law) def show_constitution(self): """Show the entire constitution.""" print("This is the cyber constitution for the state of " + self.state.title() + ".\n\n") print("Authored by: " + self.author) print("\n\nOur constitution contains the following laws:\n") self.show_laws()
I had no idea how compelling this example would turn out to be. Right away, a number of questions came up:
- “How many constitutions are there?” (51 in the US alone, and ours was one of the most recently written. Many students had no idea each state has its own constitution.)
- “Are there laws in a constitution, or are they called something else?”
- “What’s a preamble? What would we say in a preamble?”
I asked what laws students would put in a constitution, and recorded their responses in code:
# Make a constitution. my_constitution = CyberConstitution() # Set the attributes (information) for the constitution. my_constitution.state = 'alaska' my_constitution.author = 'sr' my_constitution.add_law( 'All internet users must be licensed to access the internet') my_constitution.add_law( 'Marijuana possession, manufacture, etc. is legal in this state.') my_constitution.add_law( 'Gas prices will always be less than $2.00 per gallon.') my_constitution.add_law( 'Everyone will have access to a free, ' + 'high-quality, invidualized education.') # Show the constitution. my_constitution.show_constitution()
Here’s the output:
This is the cyber constitution for the state of Alaska. Authored by: sr Our constitution contains the following laws: All internet users must be licensed to access the internet. Marijuana possession, manufacture, etc. is legal in this state. Gas prices will always be less than $2.00 per gallon. Everyone will have access to a free, high-quality, invidualized education.
It helps to read these suggestions with an understanding of what high school students might be thinking about on a typical morning. The first suggestion comes from students who have watched their peers be bullied to the point of physical violence, and watched people’s lives be significantly affected by the negative impacts of social media. The second comes from students watching many non-violent people in their lives face all kinds of legal issues for marijuana violations, while many better-connected people around them get away with the same behaviors. The third suggestion comes from students who struggle to pay for gas with their high-school level jobs. The last one was my contribution.
These are great issues to discuss, and they place programming in a much-needed context. It’s not really about the code you write, it’s about what problems you might be able to address if you stay interested in programming. It’s about knowing what can be done with code, event if you don’t stay with programming.
After the lesson students went back to work on their own programming exercises. Most of them are not using classes yet, so no one expanded on the CyberConstitution class today. But they went away with a better understanding of how programmers can build tools that re-engage people in the fundamental question of how we might build the kind of society we want to live in. What more could we want for students in an Introduction to Programming class?
If you’re a programmer, you can play around with CyberConstitution on github.