Sorry, replying to myself here, to complete the story here.

Or put another way, None is a pretty core Python topic, so there's no sense in dancing around it too much. Really "is" is the problem. I'd rather get into the details of "is" later in the course.

So I think two approaches are plausible here without going against this-thread too badly:

1. You could use "is", and say "It's most proper to use "is" when comparing to certain values, including None which we will explain later. For now,you just need to know that "is" plays a role similar to == here - testing if the thing is None." That would be fine. "I'm going to explain that later" is not that rare a thing to say in this course.

2. You could just use == like you do with strings and ints, and mention "it's more proper to use "is" with None here, and we'll start doing that when we get to "is" organically." This is the easier path for students - they are already using == for everything else and so it is zero extra thought for them to just use it with None. To be clear, their code will work perfectly with ==. They are just using strings and ints and whatever.  When it's time for students to switch to using "is None" - the occasionally maligned IDE PEP8 coloring will be there to nudge them along! I've seen that nudge in action a bunch of times.

Both of these strategies have some problems, so maybe we should just say that a particular teacher could follow their preference. Both strategies can get to the right place.

BTW,, I think "is" works best about what you get to lists - so then you have copies and identity and equality are meaningful, but there's a lot of more basic stuff to get through before you get to lists. Like you don't want to do lists before you have loops and logic.

Best,

Nick



On Wed, Sep 1, 2021 at 11:25 AM Nick Parlante <nick@cs.stanford.edu> wrote:
Hi Ricky,

A couple people have said this but I'll ask again because I am curious: would it be possible to delay introduction of None entirely until it's time to introduce is?

This maybe comes down to course tactics. I happen to like doing algorithms with data arranged in 2d from the start - you can show the kind of before/after data state in a way that is easy for the students to see, to understand what their code needs to do,  and the 2d is a rich enough domain that there's a zillion algorithms you can cook up. However, in the 2d, it comes up that you need a representation for when a square is empty, and I think None is the right value for that. Students have no problems understanding the role of None.

You could use a string constant 'empty' or something as a workaround. But I think just showing the None is the right way. It's a Python course, here's a situation where None is the appropriate Python approach, so probably this is the week to show them None.

A teacher could just use strings and ints and this would not come up, but I love the 2d early for the richness of the examples and homeworks you can do with it.

Best,

Nick

On Wed, Sep 1, 2021 at 11:06 AM Ricky Teachey <ricky@teachey.org> wrote:
On Wed, Sep 1, 2021 at 1:32 PM Nick Parlante <nick@cs.stanford.edu> wrote:
In fairness to Nick, he is not talking about the real world. Nick is
talking about the hot-house environment of *education*, where fragile
newbies are generally protected from real world issues.

Let me unpack this just a teeny bit. We don't need to think of the students as fragile. Think of it as where the minutes go.

Like why is Java worse? You are trying to explain about comparisons, and you need like 30 minutes for Java where the number of different required comparison facilities is big, and it just looks needlessly complicated. What is the problem with that? Think of it this way: I wanted to talk about *algorithms* and solving real problems .. like those are the best uses of lecture time and examples. If the language injects something that you feel is not such a great use of time, you notice that those minutes are taken away from the actual course goals.

Now for Python, == vs. is nothing like that bad. Both == and is are sensible, necessary parts of the language, I would just prefer to talk about == earlier and is later. Of the two, == is the no-brainer one when the students just have ints and strings, and no-brainer is what you want in week 2.

For teaching, you are not just identifying the 500 important things they need to know. To teach artfully, you are trying to think of an ordering, layering on 50 new things each week, where the subest achieved each week is internally coherent and you can do a project just using that subset, and at the end of the course you've gotten through everything.

Best,

Nick

A couple people have said this but I'll ask again because I am curious: would it be possible to delay introduction of None entirely until it's time to introduce is?

The biggest thing None seems to be needed for beginners is to learn the idiom for function signature default arguments for mutable parameters (the classic "Least Astonishment" and the Mutable Default Argument problem).

If the goal of the course is to get as quickly as possible to  *algorithms* and solving real problems, then I don't see why you even need to teach default arguments at all.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler