How to Teach Code

Ali Spittel - Oct 27 '20 - - Dev Community

Teaching code has been a large part of my life -- I was an education minor in college before I left to become a software engineer, and I've since taught code fulltime as a bootcamp instructor and as a developer advocate. I've feel so lucky to have been able to have been a part of many developers' coding journeys in one format or another: from teaching thousands of students through workshops and the bootcamp I used to work at to millions through writing blog posts like this online. In this post I want to address the ways you can teach code, discuss how to coach students on a learning mindset, go over the mechanics of teaching a lesson, and give oodles of tips for teaching.

Note: It may be helpful to also read my post on how we learn

You probably already teach

You may have read the first paragraph and wondered, "is this post relevant to me, I don't teach code in a classroom." My answer is yes: you probably already teach code in some format, whether that be answering questions online, mentoring a junior developer, creating content, managing people, speaking at conferences, etc. If you participate in any of these activities, you are a teacher! And, some of the pieces of advice listed here will benefit you.

Why should you teach?

There are also so many reasons why you should teach. You can reinforce your knowledge on topics -- you have to learn something really in-depth in order to communicate it simply to someone else. In addition, it can be an opportunity to learn new things: I had to teach myself many topics in order to effectively teach them to students. You can become regarded as an "expert" in your field through teaching. At work, it can help you delegate tasks if you teach others to do tasks. And, it's also beneficial for the student to be given information in an understandable way.

The Mindset Behind Teaching

Learning anything is hard, especially code. I know this personally, I dropped out of computer science during my junior year of college because I thought coding wasn't for me. Put yourself into your students' shoes -- what are the stumbling points for learning what they are trying to learn. And how can you enable them to embrace the challenge of learning that subject. Having a growth mindset towards learning new things makes learning much more achievable. I think celebrating students' wins helps with this -- celebrate the little things and the bigger ones in the classroom. Celebrate the function that works successfully for the student that is struggling, a student asking a great question, and the mindblowingly great project.

In addition, think of your students' lives outside of the classroom. Now, especially with health concerns, political unrest, white supremacist escalations, and rapidly changing life circumstances, students' basic needs aren't being met, which means that learning becomes especially hard. Maslow's heirarchy of needs states that safety needs to be fulfilled in order for someone to achieve their full potential. As educators, we need to recognize that and create accommodations to help as much as we can. During the peak of the Black Lives Matter protests, I pushed back deadlines, lessened requirements for students, and made it clear students could work on projects on their own schedule as one example.

Creating a classroom culture needs to be an intentional activity as well. Set norms for students, establish a code of conduct, and make sure that no one student dominates conversation. Encourage students to take space and give space -- and that will look different for everyone. I'm naturally a very quiet student myself. It takes me time to process on my own before coming back with questions and answering on the spot gives me anxiety. That's pretty normal, as are students who have more immediate questions. Have strategies to make everyone comfortable contributing to the class, but also allow students to process before putting them on the spot. I prefer warm calling to cold calling -- "Can someone in this row answer this question" or "can someone who was in breakout room 3 explain x again to the class".

It's also important to know your audience. If you're doing a one off workshop, doing a quick poll at the beginning can be helpful to tailor your lesson. If you're teaching a full course, I like having student profiles before the class starts to know of accommodations, backgrounds, and previous experience with the subject matter.

Another important mindset to have is that the best thing you can teach students is to teach themselves. Yes, initially teaching a curriculum is important to guide students and to address any misconceptions. But also show them how to debug errors, how to research for answers, and challenge themselves to extend what they've learned to topics outside of the course subject matter.

The Mechanics of a Lesson

Now that we've discussed some of the key behaviors you should have as an educator and encourage in your students, let's discuss what a lesson actually looks like.

First, have Learning Objectives these are tangible takeaways for what students should learn in your lesson. For example, students should be able to define what React components, JSX, and the virtual dom are; students should be able to explain why React is helpful in developing applications; and students should be able to create a React component. When you're creating a lesson, these are helpful for staying on topic and scaffolding your lesson. For students, especially adult learners, knowing what they are going to learn helps relieve anxiety and pushes off pre-emptive questions. They also know what they need to especially focus on during the lesson.

Then comes Framing , which is when you explain the background for a topic and why it's important. You're hooking the learners into the lesson and telling them why they need to pay attention. You're setting the scene for the rest of the lesson here. In a React lesson, the framing could include the history of React, statistics on how widely it is used, and how it makes development easier. You could also include personal stories about creating applications with React.

Then comes the "body" of the lesson. I rotate through three steps repeatedly in this phase: "I do, we do, you do". I do is when I explain a topic to students - "A React component is X" for example. We do is when I write code and expect students to do the same on their computers if possible. So we may build a simple React component together. Finally, a you do is an activity for students to complete. I prefer to do these activities in groups if possible, then students can use each other as resources in addition to asking the instructor questions. Each of these sections shouldn't be too long. Rotating through keeps attention and students never have to wait too long before practicing with something themselves. When you have them do exercises emphasize that this is about the process more than the results, they won't necessarily always be able to get what they are aiming to each time, but hopefully they learn something for the next time they use that subject.

Traditional lectures are a flawed teaching model. People's attention spans are usually 11-13 minutes long, so if you are talking for much longer than that, people will be tuning out. Vary your teaching model. I really like flipped classrooms where students do a reading or watch a topic and then we come together to discuss. As well as repeated practice. Writing code is the best way to learn how to code.

Another reality is that students will be at different levels -- topics will click quickly for some and slower for others. Also, everyone is coming into a classroom from a different background. I'd recommend focusing your lessons on the middle of the class's ability level. You may lose some students and not challenge others enough, and that's where 1-1 attention comes in for those students. You can recommend additional resources, have 1:1 office hours, and tier activities so that everyone has something to work on. Your lessons should be reaching the vast majority of the class, but make sure to also reach those who may struggle or excel with a topic.

When you're teaching something you know really well it can be tempting to teach everything about that subject. But often times that overwhelms newbies. Teach what’s necessary, not for your ego.

I also incorporate Checks for Understanding every few minutes to make sure the class is following along with what I'm teaching. These can take multiple formats, from Slack polls and questions to writing on whiteboards, to answering questions verbally.

Finally, review at the end. Recap what you went over, linking back to the learning objectives.

Teaching Tips

Now, I want to transition into giving a bunch of teaching advice.

Set clear expectations. Students will do best if you have a clear agenda and success criteria. I always give a syllabus or outline beforehand, have a code of conduct for the classroom, and make my lessons available ahead of lesson time so students can review them before class if they want. Don't make your lesson be the first time they see the material. Assign readings ahead of class, and make slides or lesson materials available ahead of time if possible. Repetition of material is key.

Create a safe place to fail. Have safeguards in place so if a student doesn't finish something or doesn't get the correct answer it isn't devastating. I normally have a resubmission process outlined, allow for some missed assignments, and grade for effort not correctness.

Along similar lines, if your students have an extrinsic motivator for learning, i.e. they want to get a programming job, adding number or letter grades is often ineffective or harmful. Certain students, cough me in college, care more about that success measurement instead of actually learning. I would focus on giving good feedback rather than trying to put a contrived grading rubric together. I normally have criteria for graduation, but most assignments are given passing/not passing for assignments that are way off the mark (sections that haven't been attempted, very clear lack of effort, large chunks of code copied from the internet, etc).

Mirror the career world in the classroom , again mostly for adult learners. For example, having standups to discuss progress, use pull requests for submitting homework, or using issues for class questions. Get students used to using the platforms they will be using throughout their careers.

Use best practices. Please don't use foo/baz/bar examples. They aren't helpful. But do format your code properly, use good variable names, etc. Model what you want your students to do.

Link new information to what they already know. Learning in isolation is really difficult. Instead, put it in context of what they've already learned. Making those links explicit can be really helpful even if those links may seem very clear to someone with more experience. For example: a variable in code is very similar to the variables you may have learned about in algebra class.

Appeal to multiple learning styles. The idea of different people learning with different learning styles has been discredited, but make sure to have visuals, audio, additional readings students can do, and more exercises so that students can extend their knowledge on their terms. Diagrams are just good for learning anyways! Bonus tip for content creators: you can reuse content by creating it in multiple formats. I usually use my blog posts as scripts for my YouTube videos.

Break down jargon. I often see and hear that you shouldn't use jargon when teaching. I actually disagree with this -- students are going to need to use the terminology of the field in their work. Being able to talk like a programmer is crucial for interviews and communicating with others. That being said, make sure to explain yourself when you use jargon. Define new terms repeatedly verbally and in writing.

Emphasize the unimportance of memorization. In many subjects, rote memorization is critical. In programming, the difficult part is the problem solving, and students will be able to use resources on the job. Explaining this is super important so that students don't feel the need to memorize entire APIs. In addition, show gaps in your knowledge. If you forget the name of an array method, that's probably better for students to see than if you had it off the top of your head. Show them how you find the correct method name using the documentation.

It’s okay to not know something. When you're in front of a classroom it may feel like you need to know everything on a topic, but you don't. It's important to prepare extensively for lessons, but having a typo or a bug and debugging that live is so helpful for students. And sometimes their questions are really out of left field -- like when I was asked what would happen if you broke out of the window object in JavaScript. You can say you don't know, or show them how you would research the answer to their question.

Some of my favorite teaching resources

This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!

Conclusion

One of my favorite quotes is, "When one teaches, two learn" by Robert Heinlein. I have learned so much from teaching, and I feel so lucky to have been a part of people's learning journey. If you have any questions or follow up topics, please tweet them at me.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .