Given the prevalence of Python as a first language at many universities I think using Python as a language to teach new software developers is a good approach. But there's one thing that concerns me. Eventually these developers will be moving to a statically typed language and I want them to be aware of static typing and what it implies.

Do you think using Python for teaching will be a large hindrance to later instruction or am I just worrying for no good reason?

Would anyone care to recommend other teaching languages I might evaluate as well besides Python?

  • 1
    In my experience, the learning curve for from duck typing to (basic) static, declared types is pretty short. Partly because it is enforced by the compiler and partly since you probably introduced at least the int/float/str types in python. – Adam Sep 21 at 22:56
  • If your students understand basics about programming logic, tehre is nor problem; each language has similarities and differences and they have to understand as many as they can – user5980 Sep 26 at 15:05
up vote 7 down vote accepted

If you teach Python's typing system correctly, you should have no problem later. The rule in Python is that names don't have a type associated with them, but all values do. It isn't that "things" change type. They don't. Objects and other values have a well determined type when they are created and that type never changes. Names never have a type to be changed. But any name can be associated with any value.

When you move to a language that requires explicitly applying a type to names (Java, say), then you just need to teach them that names are given types also, as a sort of redundancy so that errors can be caught earlier (compiler v run-time). A name associated with a type can only refer to a value that has that type.

Applying types to names (as well as values) isn't really that big a deal, and the students will be more sophisticated when you get to it.

However, they may not like having to explicitly apply types to names. But that is a different issue. The reason given above will be enough for many of them.

Finding errors early is a big win in programming. If you take that attitude when teaching Python you will stress things like early testing (preferably test-first programming) so that errors show up soonest.


For the distinction between a "thing" and a "name applied to a thing" it is often instructive and always fun to return to Haddock's Eyes. Lewis Carroll was more interested in mathematics, of course, but the ideas apply equally well to CS.


Don't confuse "typing" as hitting keys on a keyboard with "typing" as applying a type to a name or value. It may be that the first version of this was confusing in that regard. Here "typing" means only the latter.

  • I like the distinction of names and values. I had never thought of it like that (I am a Software Engineer / Teacher, and learning to think more like a computer scientist, every day. If you are a computer scientist, then learn to think more like a Software Engineer, both are valuable). However, did you make a small error, I think “having to explicitly type names”, should be “having to explicitly type types”. – ctrl-alt-delor Sep 22 at 10:24
  • 1
    @ctrl-alt-delor. Clearer now. It wasn't an error, but may have been poorly stated. – Buffy Sep 22 at 11:20

Maybe it is a bit overkill, but I'm teaching python and C in parallel to CS beginners.

The languages are syntactically similar enough to lower the burden of learning two languages, but the students understand the "problem" of typing and get a better idea of what is happening in behind in python.

Fun fact: In the beginning, all like Python, because it requires no typing. At week three, all love C because it is clearer. In week 6, we are having two fractions in the course, one loving C, the other loving python (or hating C / python ;-) ). The students preferences are changing quite often during this course and this gives me a lot good teaching opportunities.

  • 1
    That's a fascinating approach! Is this your first time using it? What are the ages of the students? – Ben I. Oct 29 at 15:37
  • 1
    @BenI. I'm doing this for seven years now with good success. This year one colleague of mine switched from java to the same concept because of the good results. The students are first semester students in Germany at a university of applied science, many without little to no background in cs and no programming experience (yes, this is Germany in 2018 :-( ). – OBu Oct 29 at 15:39
  • Wow--you are ambitious :) Teaching any new developer C seems like a recipe for, well, bad outcomes. :) Glad to see that my intuition seems to be quite wrong. – Onorio Catenacci Oct 31 at 15:11
  • 2
    @OnorioCatenacci The good thing about C is, that it uses nearly no magic behind the scenes and you can understand the behaviour once you understood how a computer works. But you have to give the students time to learn, you should not hurry. – OBu Oct 31 at 17:02

Perhaps in the example code that you show them, introduce them to Python 3 Type Hints (PEP 484 -- Type Hints https://www.python.org/dev/peps/pep-0484/ ). It's a bit of a kludge because the typing is still dynamic, but it at least shows that we care about the arguments and return values. It looks like this:

def greeting(name: str) -> str:
    return 'Hello ' + name
  • Thanks for the feedback but that's not really what I'm asking for. – Onorio Catenacci Oct 31 at 15:10

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.