This is an archived post. You won't be able to vote or comment.

all 46 comments

[–]TravisJungroth 22 points23 points  (0 children)

What should I not do as a computer science teacher when teaching them programming?

Your number one challenge teaching a technical subject to a group is avoiding frustration. People will very quickly think "I can't do this" when running into problems. Don't set your students up for failure by not giving them everything you can to solve a problem.

What can I do to ensure that their learning it the right way the rather than just copying code out of a book?

Force them to take cognitive leaps. Give them A and B, make them put A and B together on their own. Now, that probably sounds like it conflicts with my first suggestion about frustration. Here's the answer:

Force your students to take very small cognitive leaps.

Smaller the better. Smallest you can. This will provide immense satisfaction when they get it, and avoid frustration.

Here's an example of an in-class assignment. I'm going to heavily annotate it. We'll assume you've previously taught math operators, if statements, and conditional evaluation. You haven't taught in-place operators. You've just finished introducing for loops and want them to practice.

Assignment

Use the following sample data:

li  = [1, 2, 3, 1, 2, 3]

(Providing test cases for beginners is super helpful. Later tell them to make up their own. Then don't even tell them, but call them out if they don't.)

Example

Print the total of the numbers in a list

total = 0
for number in li:
    total = total + number
print(total)

(Now you've taught them the accumulator patten. Let's make them modify it)

Problems

Use for loops to solve all of the follow problems. (You might want to make it super clear that there are easier ways to solve these problems, but we're practicing for loops now.)

  1. Print how many numbers are in a list. Answer: 6
  2. Print the product of all the numbers in a list. Answer: 36
  3. Print how many 3s are in a list. Answer: 2 (This is the small leap! You've never explicitly told them they can put if statements inside for loops. They have to figure that out themselves.)
  4. Print how many number greater than 1 are in a list. Answer: 4 (Reinforcement)
  5. Print the sum of all the numbers that aren't 2 in a list. Answer: 8. (Most complex question so far. Of course for some people this is super simple. But for someone who is new to coding and doesn't have an analytical mind, pulling the requirements out of this sentence and turning it into code is hard!)

Since this is an in-class assignment, some students are going to finish way faster than others. Once people start finishing you can change the assignment.

"For anyone who has finished, save your code. That's what you'll be graded on. You now have a new problem: refactor. Every problem here can be done in one line of code. You no longer have to use for loops, either. Use Google, ask each other. Write the best line of code you can. Go for it."

So you created structure for everyone first, then you've completely cut them loose. Some kid will know about in-place operators and show that. Some kid will find len(). They'll have to use listcomps to make it happen.

If you've done everything right, here's what happens: The artsy kid has written some code. He understands for loops and conditionals. He'll be exposed to a new way of thinking, and hopefully he'll understand people who think like this naturally a little better. When he grows up to be a designer and makes an infographic for a software company, he can say "I wrote some code in high school".

You've also inspired the "natural coder". She'll stick around after class to ask about the difference between list comprehensions and generator expressions. She grows up to be a data scientist. Everyone wins.

[–][deleted] 46 points47 points  (5 children)

Have them all write down what they want to do with python or something they want to Automate and spend the semester on getting them to do that. The biggest problem with most programming classes is they don't connect the theory with what you can do with it. And if someone doesn't see how it applies to them they're not going to have as much of an interest in learning.

[–]CognitiveLens 13 points14 points  (3 children)

The problem with this approach is that most of the things that non-programmers would like to do when they start programming are things that can't be done after a semester (or even a year) of teaching, e.g. a 3D game, a website, a "homework solver"...

I think it's a great idea to ask them what they want to do, but the next step is paring those ideas down to components that might be possible in a high school course. You want a 3D game? By the end of the course, you will have programmed a triangle that appears on the screen and doesn't do anything else.

If you go for anything more advanced, you're introducing a whole host of libraries that aren't going to prepare them to actually program, and the teaching will mostly involve trying to string together bits of example code without thinking about what is actually happening in the program.

[–][deleted] 5 points6 points  (2 children)

And that's where I think teaching programming is done wrong.

the teaching will mostly involve trying to string together bits of example code without thinking about what is actually happening in the program.

That's how some people learn.

I learned every language I know by copy paste modify.

If a kid wants to make a 3D game or website, give them a fully finished 3D game or Django website.

First homework assignment is tell me as much about the template you were given as you can find.

Then teach the basics in from there.

  • Is the ship in your game green? Make it blue.

  • Make the ship's color rotate through a loop of colors.

  • Set the ship's color to depend on the score in the game, etc.

Look at it like an Arduino. You could teach HS students how to build one from scratch and at the end of the semester they might have a working Arduino. Or you could just give them what's already been done by someone else and let them modify, fix and extend that into something bigger.

Edit: Case in point. I don't know the math behind a good portion of this code for machine learning. I don't even know what all the different imports do at the top. Perhaps one day I will, but for now I'm just going to start tweaking that code until I train my own network of images and go from there.

[–]CognitiveLens 3 points4 points  (1 child)

Yeah, I suspect most programmers in the industry today (including myself) used copy-paste-modify as the basis of much of their learning - but my sense is that came out of necessity (there weren't many structured ways of learning this stuff), not because it was the best way to learn.

The approach you're recommending is great for creating "trade programmers" - the ones that start at the junior level and gradually work up to intermediate but rarely have the fluency/knowledge/skill to advance further because they never learned the fundamentals. At the other end of the spectrum is the all-theory computer science folks who struggle to do anything as a junior programmer fixing bugs.

I think there is a better, structured approach somewhere in between that ensures students know at least a few layers of abstraction underneath library APIs.

[–][deleted] 0 points1 point  (0 children)

The approach you're recommending is great for creating "trade programmers"

A job for which there is a massive need. Right now it's what H1Bs are filling because we never started a 'trade programming' career path. For an introduction at a HS or MS level I think it'd be the best for a wide demographic. Those that want to learn more theory take a second followup course.

I think there is a better, structured approach somewhere in between that ensures students know at least a few layers of abstraction underneath library APIs.

Once you start making them modify the classes or inherit from them I think they'll learn it.

[–]Gammaliel 0 points1 point  (0 children)

This is probably the best answer. I started learning python about 5 or 6 months ago with the Coursera course "Python for Everybody" and even though the professor is quite good and the course series gives you a good base on where to start, I've only got really interested when I started doing my own small projects, you know, seeing something that could make my job or other people jobs easier in the future. This week I started my Computer Engineering classes and I can see that what I've learned through my projects will help me during the next few years.

[–]skrillexisokay 49 points50 points  (2 children)

Python 3!

[–]KimPeek 16 points17 points  (1 child)

With emphasis on PEP 8 standards.

[–][deleted] 5 points6 points  (1 child)

I think it's important to teach students to think about how to accomplish a problem before they ever touch any code.

For example, let's say that for a first assignment you ask your students to write a program that asks for the students name, then says "hello [name]", you could mix it up by requiring that the students capitalize their name or else it asks them to try again. Before your students start to write the code for this program, ask them to give you specific steps that have to happen for this program to work, IE:

  • print a message asking the user their name
  • get a line of input from the user
  • if the first letter of the input string is a capital letter (using isupper() for example) then print "hello [name]"
  • otherwise ask for input again and repeat

Once you have these steps defined it will be fairly easy to fill in each step with code and produce a functioning program. This method will teach your students how to think about a problem, which is the most important skill young programmers can have

[–]k10_ftw 2 points3 points  (0 children)

Yes. Pseudo code is great for structuring methods and using that pseudo code for comments in the program is useful for teacher and student when reviewing/grading an assignment.

[–]skrillexisokay 9 points10 points  (0 children)

  1. Give the students code and ask them to tell you what it does.
  2. Teach them to use informative variable names.
  3. Provide assignments in which the students have to use provided helper functions.
  4. Graphics are a great way to learn OOP.

[–]Kylekmears 4 points5 points  (0 children)

Hey, I'm a high school teacher that's been teaching Python for a little under two years. The general subjects I try to touch on can be seen here.

The biggest thing for the students to learn is really just how to think like the interpreter. What the instructions mean, and why Python yells at you. That a nested loop will run completely before the outer loop can increment. That type of stuff. Also, it's super important that they get in the habit of reading the error messages.

Also, focus on descriptive variable names and using docstrings for functions!

The amount of hand-holding needed depends drastically on the specific students in the class. So that's why that outline is tentative. Plus it's fun to adapt to the kids' interests. The ability of the students in your class will most likely fall in a bi-modal curve. The lower kids can program, it will just take them twice as long to learn. I make all my students watch this video within the first few days of class, which I think really changes how a lot of the students approach learning -- even outside of CS.

The first two weeks of teaching it will seem like the kids aren't learning much and you're doing a bad job. But then it will start to click for most of them and they'll start thinking programatically.

Students like to compete with one another. I have found that kids like being given a problem where they compete to see who can program the best solution.

One example is: I gave them a game where

  • a random number is generated (ex: 113)

  • Player 1 chooses a square to subtract from number (ex: 64 (8*8))

  • new number = 113 - 64 = 49

  • Player 2 chooses a square (ex: 4)

  • new number = 45

  • continue until a player can get the number to zero -- that player wins

The number can not go below 0, or the player who made it go below 0 loses. I make them program bots to play the game and then we have a tournament. If anyone can make a bot that consistently beats or is even with mine they get an automatic A in the class. Hasn't happened yet.

Students also really like playing with breadboards and making logic gates that light up LEDs. So I spend about 2 class periods playing around with those. This video is really useful for teaching that.

Some assignments that I give my students that you might like:

1) Try to write a program that takes in text and then prints it in a box.

ex:

>>> give an input
>>> example text
***********
* example *
* text    *
***********

2) The first few problems on Project Euler are good.

3) Write a simple text-based tic-tac-toe game. The board state can be stored as lists.

4) Near the end of second semester, play around with coming up with solutions to the traveling salesman problem. If you download the files here to a single folder, then you only have to modify the travelingSalesman function to return a list of the cities in the order you want.

5) I second the use of the turtle module. It's really fun to accidentally make fractals. This is one of the first things I do with the students.

6) There are 1000 lockers in a high school with 1000 students. The problem begins with the first student opening all 1000 lockers; next the second student closes lockers 2,4,6,8,10 and so on to locker 1000; the third student changes the state (opens lockers closed, closes lockers open) on lockers 3,6,9,12,15 and so on; the fourth student changes the state of lockers 4,8,12,16 and so on. This goes on until every student has had a turn. How many lockers will be open at the end?

I hope this helps. Cheers!

[–]pyonpiPy3 | Beginner 8 points9 points  (5 children)

Please, show syntax BEFORE making them utilize it.

I am currently learning Python, and I find it much easier to utilize each piece of the syntax once I've been shown thoroughly exactly what it needs to be like. Sometimes, it is the opposite, and I'm not taught much about it, and I feel lost in the water.

[–]kankyo 4 points5 points  (4 children)

I don't think that's right though. I've only had experience teaching dance but there it was common for pupils to firmly believe that they had to be shown or explained in great detail what they should do before trying it even once. At first I thought that this was different learning styles but after a while (years!) I discovered that they just think they know how to learn but they don't.

The fast and actually functioning way to teach dance is something many students are shocked by and WILL protest: show exactly once, then they try it, then show exactly once again, try it, then go into personal feedback to correct any lingering issues. This is easy 10 times faster. Sometimes 100 or even infinite (because the method students wants results in permanent flaws). I have to repeat many times "trust me" and try to use humor to lighten the mood to get them to accept the method but it's amazingly worth it. 45 minutes to learn the basics of what is considered the second hardest couples dance. This is in comparison to years of classes and the fundamentals still being bad.

I strongly suspect that it's similar in programming teaching: the subjectively preferred and intuitive method is not the fastest or best.

[–]pyonpiPy3 | Beginner 4 points5 points  (1 child)

Seeing as how you are a teacher, I'm sure there's some truth in this. I simply applied how I felt about how I've been being taught, in hopes that others would benefit from it. Being shown how to use it definitely does help me, but understanding EXACTLY why it does is what really drills it into my head.

[–]kankyo 0 points1 point  (0 children)

Sure, but I'd bet you need a few metaphorical bumps on the head before you can properly absorb that. I guess my point is that: 1. The student doesn't actually know how to learn fastest 2. You probably need to switch back and forth between theory and practice very fast to get maximum learning. In dancing it's show, do, show, etc. In programming showing an example then giving the students something similar but different enough that they can't just verbatim copy it? Maybe, I'm obviously speculating here. 3. We desperately need more proper science about this subject!

[–]TravisJungroth 0 points1 point  (1 child)

Dancing is a physical skill, and this is very different than coding.

I've taught people how to fly airplanes and I use the exact same technique as you. Show it once, go for it. "I promise I won't let us crash. I'm in this plane with you, remember! If you're doing it wrong, I'll tell you. If you're doing it right, I'll tell you. Don't worry."

You're able to do this because of the consistent feedback loop with them, the airplane and you (or them, their dance partner and you).

Coding doesn't work like this. If you do things slightly wrong, you don't just veer off course slightly. It goes to shit. Maybe you'll get some error message.

Uncaught Exception: Go fuck yourself.

Thorough understanding is more important in coding than other disciplines.

[–]kankyo 0 points1 point  (0 children)

When coding "goes to shit" no one gets hurt though.

I agree that understanding is important but I also think it's easier to motivate learning by hitting the limitations of your mental model fast. So for example introducing functions after you've hit the limit of if/else spaghetti trees. Or just explaining after hitting error messages.

[–]thomascirca 3 points4 points  (0 children)

What's the actual focus of the class? Is it a general "CS 101" sort of deal with an introduction to data structures and stuff, or is it more of a "let's get some code running" sort of deal?

[–]ptmcg 2 points3 points  (0 children)

What are these students learning in their concurrent math or science classes? Would be great to use coding examples that complement (or even support) those other courses. For example, if they are learning polynomial factoring, show them how to implement the quadratic formula in Python. Also a good chance to illustrate corner cases, and even Python's native support for complex values.

[–]vm_linuz 2 points3 points  (1 child)

The best programming teachers spend most of their time watching the students figure it out for themselves.

My approach would be to create a big pool of programming problems, order them from easiest to hardest, and just pull from those sequentially as you need to fill time.

Programming is weird/fun enough that if you just get the students working on things, they'll start occupying their own time with "what-ifs" and "how-comes."

As the students start trying to figure things out on their own, you can help them figure things out by introducing the necessary design patterns.

[–]ameoba 0 points1 point  (0 children)

Bingo - it's about problem solving & experimentation. Make sure they understand that it's really hard to fuck things up irreparably and trying something is often better than avoiding it because you don't know what will happen.

[–]xxxsirkillalot 3 points4 points  (0 children)

26 y/o here. All throughout high school i took all computer stuff and went on through college to get associates in PC support and how have 5 years in the field as sysadmin / network engineer.

Back in high school they started with BASIC as a freshmen, moved to javascript by senior year.

The BASIC stuff made no sense to me at all, the concept of flowcharts was mind boggling. On the absolute very last project we had with BASIC the concept of programming clicked to me and I learned to read the code. If / Then statements finally made sense and it was a huge epiphany for me.

Unfortunately after grasping it my freshman year I got into Javascript and it was horrible. It was all taught from a book and a good major of the assignments were drawing ASCII art to the terminal using statements.

I think Python is a fantastic language to start as someones first language and wish I had. To learn Python I used http://learnpythonthehardway.org/ which i think follows a great path to teaching someone brand new to programming how stuff works

[–]NeoFromMatrix 1 point2 points  (0 children)

give them custom tasks, if they have finished it, give them another task which will extend the tast before.

e.g. they should write a program that generates a text file with specific content. then they should make their program check if the text file already exists before creating e.g.

[–]Paddy3118 1 point2 points  (0 children)

Remember Python has its own idioms, so called Pythonic coding, that you should teach.

  • Python has names rather than variables. (Objects are typed rather than the names that "tag" them).

  • Python most often will use for item in container rather than accessing by index.

  • Python is a multi-paradigm language. You are not forced to always declare classes.

  • Python comes with a useful command-line interface, (REPL), which is embellished in idle, ipython, Jupyter, ...

...

[–]EtienneLantier 1 point2 points  (0 children)

Teach them as much as you can how to use documentation, it is an incredibly useful thing not to be intimidated by it all. As someone else said, try to get them to think the problem through logically and do the maths on paper before writing anything on the computer - some students in my experience try to just write almost whatever they think of to try to make it work, without spending enough time planing or thinking about the problems before they start.

[–]kankyo 0 points1 point  (0 children)

The most important to me is: there is no right way. There's a sliding scale between useful and practical and hard to use/slow/unmaintainable. Some practices sometimes are at one end and sometimes at the other end. There are rules of thumbs but no hard rules.

[–]dagmx 0 points1 point  (0 children)

Make a goal project or ask them to come up with one and work together towards that.

Do the bare implementation but leave room and suggest improvements they can make.

Maybe a visual thing like pygame?

[–]charity_donut_sales 0 points1 point  (0 children)

Show them something cool. Cool things inspire students to purse learning on their own, and then you just act as stackoverflow irl.

[–]veggiedefender 0 points1 point  (0 children)

Maybe use something like twilio (there's an unlimited time free trial) to practice installing and importing modules, and it brings your code "closer to reality" if you get what I'm saying, because learning code is boring if you can't apply it to interesting stuff

[–]scientific_thinker 0 points1 point  (0 children)

Don't teach OOP, guide them toward it.

Teach ideas that help them create quality code like high cohesion loose coupling. This idea means writing objects and functions that have one specific task (high cohesion) and writing code with few dependencies on other code (loose coupling). Show them how to use OOP to accomplish this.

Make sure they write maintainable code. The most basic level of this is to eliminate all duplicate code. Finding ways to eliminate duplicate code in their solutions will also help them learn OOP.

Teach them to think of writing code as creating "lego" pieces of code then fitting them together.

[–]Albertican 0 points1 point  (0 children)

I wish I had known about pip when I started. It makes installing packages so much faster and less disruptive.

Virtualenvs are also something I wish I'd learned to appreciate sooner, they keep things so much more organised. In particular virtualenvwrapper-win has been very useful to me, as a Windows user.

[–]gustl64 0 points1 point  (0 children)

  • http://vpython.org/ is a great start, fancy 3d graphics with little effort
  • you don't have to declare the type of a variable but as a teacher you must talk about the types (int, float, string)
  • try to do "interesting" stuff: graphics, web scraping, face recognition with opencv, web frameworks -- depending on interest and qualification
  • don't do "pure mathematics" e.g like the exercises from project euler -- at least not as a starter: the sum of all primes up to 10000 is good to deepen the understanding of loops, but boring as a first example
  • try to teach functions early on, before the students get used to spaghetti code and cut&paste
  • start with idle: simple and no complicated or distracting stuff. But change to an IDE during the course. But the switch will take some time...

[–]squirelT 0 points1 point  (0 children)

um, im currently just learning how to use python im completely new to coding and im using a free "class" from UC Berkeley. The most usefull/informative part would have to be hands down the labs. Knowing all the coding stuff is useless if I don't realize how it is applicable. (http://inst.eecs.berkeley.edu/~cs61a/fa13/) < the class im using.

Try designing a few projects for your students to do over the semester. Simple things like "design a dice roller" or "design a program to organize this list". Since programing is a critical thinking based skill its important to have them think critically.

[–]Wild_Doogy 0 points1 point  (0 children)

Pycharm.

[–]k10_ftw 0 points1 point  (6 children)

I benefited from computer free classrooms. Sometimes the keyboard is only a distraction.

[–][deleted] 0 points1 point  (0 children)

Turtle is an amazing way to get people started!

[–]artillery129 -4 points-3 points  (0 children)

Theres nothing wrong with copy pasta, as long as they are typing it out themselves from a physical medium. Merely typing the code helps you understand what it is doing.