Suggest appropriate goals for a super-basic Python class (HS level)



  • So I find myself once again teaching an introductory Python class in the fall. And when I say "introductory", I mean "the target audience will never have used a computer in any way other than browsing the web or word processing."

    I'm working on coming up with my learning objectives--things that I can measurably assess competence with. At this point, I want suggestions. What should a very basic student know/be able to do after a 1-semester, high-school level class in Python? Suggestions as to resources would also be wonderful, especially if they're free.

    Coding environment They'll be using Visual Studio Code with a Python plugin on old (2012) Macbook Pros. We'll be using Python 3.X. This is not flexible at this point.

    My current ideas for broad topics:

    • Computer familiarity
      • Use Finder to create, find, move, delete, rename, and archive files and directories
      • Use the trackpad and gestures
      • Manipulate open windows
      • Use VSC to create, rename, and execute Python files
      • Use VSC’s terminal window to access the Python interpreter
    • Debugging
    • Variables
      • Understand the basic types in Python: boolean, numeric, sequence, dict
      • Understand the difference between a variable name, its value, and its type.
      • Be able to assign a variable
    • Sequences
    • Conditionals
    • Loops
    • Functions & Parameters
    • Structured Programming
    • Input/Output
    • Advanced Topics

    The order of topics isn't fixed.



  • @Benjamin-Hall

    I'd have a session with an "Intro to Object Orientation" where you talk about (say, physical) objects like a brainteaser puzzle, and you talk about its properties and how you can name them, and where you talk about how you name actions you can do to the puzzle.

    Then you can characterize a solution to the puzzle as a sequence of actions that does ____.



  • @Captain I'm not entirely sure I'll even get to classes and objects-as-such at this level. Even functions are hard for a beginner. They'll use objects (because it's hard not to), but OOP might be a bit far of a reach.

    But thanks!



  • @Benjamin-Hall Then consider making it an "advanced topic". It shouldn't take too much time to cover the conceptual idea, and it will take the mystery out of what the . operator does.



  • @Captain Good idea.


  • BINNED

    Perhaps cover some standard libraries? Or even go over installing additional modules if you're feeling brave enough.


  • Discourse touched me in a no-no place

    @Captain said in Suggest appropriate goals for a super-basic Python class (HS level):

    I'd have a session with an "Intro to Object Orientation"

    That probably belongs in the Advanced Topics section, if at all.

    When I was taught OO long ago, it was a second year university course where the programming language it was in was one we were taught in the first year. (Modula3 isn't a language I've a lot of sympathy for; I'm happy it's basically unused.)



  • @dkf Seconded. Also, I think OOP is usually taught too early in general. I wouldn't teach it to anyone before they've written a program big enough that they start to wonder how to organize it properly.

    I believe it doesn't make sense to introduce OOP without also mentioning the SOLID principles and giving a basic introduction to object-oriented design (i.e. how to use it properly), and those concepts are way too abstract for people with little to no experience.

    Edit: If you have some leftover time, I'd rather teach the students how to properly organize their code into modules - that might be easier to grasp for beginners than OOP.



  • FWIW, I found the transcript for the 1-semester Java programming course I followed at university (for non-computer-science students). The contents were more or less like this, in order:

    • Introduction to classes, objects, variables, methods
    • Introduction to algorithms: the sequential execution of instructions
    • Language fundamentals: declaring variables, performing calculations, control structures, array types
    • Algorithmic concepts: recursion, stack, linked-list, divide-and-conquer (quicksort), brute force search
    • More about OOP: visibility, static classes, interfaces
    • Exception handling
    • Reading and writing files on disk

    Of course Java more or less forces one to talk about OOP a little bit even before starting with the smallest 'Hello World' program, but I don't think that's a deal-breaker.

    As for myself, I think I learned programming as a teenager with a book from the library, which mentioned OOP in the very last chapter. This means you won't practice much with it, and it makes it appear OOP as an unimportant fancy thingy. I'm not sure if that's desirable.



  • @Grunnen said in Suggest appropriate goals for a super-basic Python class (HS level):

    As for myself, I think I learned programming as a teenager with a book from the library, which mentioned OOP in the very last chapter. This means you won't practice much with it, and it makes it appear OOP as an unimportant fancy thingy. I'm not sure if that's desirable.

    I think it's better than the alternative, which is teaching misconceptions about OOP. Most introductory books I've read teach OOP and inheritance using some easy-to-understand real-world examples: Animal, Mammal, Dog. They also show you that base classes allow you to re-use code.

    All of that leads beginners to the conclusion that the purpose of inheritance is code re-use and that inheritance relationships should be modeled after real-world "is a kind of" relationships. Both is usually horribly wrong and violates a bunch of design principles like SOLID.

    You can write medium-sized programs perfectly fine without knowing about OOP at all, if the language allows it, like Python does. You don't need it to be able to re-use code (functions let you do that as well) or to hide implementation details (you can also do that inside a Python or C module).

    You only really need to learn about OOP once you write a program large enough that the dependencies between the various parts become to complicated or once you need some kind of plug-in architecture for flexibility. And once you understand those use cases, it can be taught to you properly: The real benefit of OOP is that it allows you to decouple unrelated code via dependency inversion and makes it easy to write different "plug-ins" with different implementations for a part of the functionality of your program which implement the same interface. Not modeling real-world relationships, not hiding implementation details and also not organizing code - you really don't need OOP for any of that.



  • @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    Computer familiarity

    • Use Finder to create, find, move, delete, rename, and archive files and directories
    • Use the trackpad and gestures
    • Manipulate open windows

    I'd hope this would be covered in a prerequisite class.

    It's been ages since I was in high school, but even back then we had a basic computer skills class. I can't imagine High Schools wouldn't have one in 2019.



  • @powerlord said in Suggest appropriate goals for a super-basic Python class (HS level):

    @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    Computer familiarity

    • Use Finder to create, find, move, delete, rename, and archive files and directories
    • Use the trackpad and gestures
    • Manipulate open windows

    I'd hope this would be covered in a prerequisite class.

    It's been ages since I was in high school, but even back then we had a basic computer skills class. I can't imagine High Schools wouldn't have one in 2019.

    They do everything on ipads (we're a 1:1 iPad school). So most of them...struggle...with full desktop OS capabilities. I discovered this the last semester when I finally transitioned to using desktops for my Web Design (HTML/CSS) class. It was...painful.

    People say that kids these days are so tech savvy. They're not. Not inherently, anyway. They can do apps, but that's about it.


  • 🚽 Regular

    @dfdub said in Suggest appropriate goals for a super-basic Python class (HS level):

    dependency inversion

    We no longer call it that. (inb4 "who's 'we'?")

    "Dependency injection" is a better name.


  • Discourse touched me in a no-no place

    @dfdub said in Suggest appropriate goals for a super-basic Python class (HS level):

    The real benefit of OOP is that it allows you to decouple unrelated code via dependency inversion and makes it easy to write different "plug-ins" with different implementations for a part of the functionality of your program which implement the same interface.

    The core benefit of objects is encapsulation, putting state together with operations upon that state and ensuring that the lifetime of that bit of state is consistent. Classes (and prototypes) follow from the observation that often you want to stamp out the same sort of object a lot of times. (Inheritance is a lesser benefit, and makes things much more complicated.) The greater level of encapsulation makes it easier to decouple pieces of state that don't need to be closely entangled, and make it so much easier to separate the interface to some code from the implementation of that code.

    All of which are concerns that only rear their heads in large programs, and are why you probably don't need to be taught OO early. It's simply not introductory level stuff. I guess it's more for when people stop thinking so much about the basics of coding and move more to looking at how to engineer a program to do something more complex; a software engineer absolutely should know OOP, OOD and OOA.



  • @Captain said in Suggest appropriate goals for a super-basic Python class (HS level):

    it will take the mystery out of what the . operator does.

    All you really need to know at this level, I think, is that it makes the thing after the . perform an operation on the thing before the .. Where the thing after the . comes from or why it works isn’t very relevant to just learning how programming works, IMHO.

    Do they still teach the basics of how engines work when taking driving lessons? This is unnecessary in much the same way, if you ask me.



  • @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    People say that kids these days are so tech savvy. They're not. Not inherently, anyway. They can do apps, but that's about it.

    That’s because the people making these claims are often even less technically skilled. Regardless of your own ability in something, a person who’s better at it than you are quickly appears to be far more skilled than they actually are, because you can’t accurately judge their abilities exactly because you’re less skilled yourself.



  • @Zecc said in Suggest appropriate goals for a super-basic Python class (HS level):

    We no longer call it that. (inb4 "who's 'we'?")
    "Dependency injection" is a better name.

    Dependency injection is am implementation pattern that helps you implement dependency inversion. They're related concepts, but not the same thing.

    For example, a high-level class written in Java that uses a ServiceLoader to find implementations of an interface does not use dependency injection, but follows the dependency inversion principle.

    @dkf said in Suggest appropriate goals for a super-basic Python class (HS level):

    The core benefit of objects is encapsulation

    I wasn't trying to say that OOP doesn't help with that. My point was that encapsulation is possible to achieve even without OOP (if the language doesn't force you to use OOP).

    As you said, the benefits of OOP in that area only become clear once you need to manage a lot of similarly shaped pieces of data and reason about their lifetimes.


  • Banned

    @dfdub said in Suggest appropriate goals for a super-basic Python class (HS level):

    @Zecc said in Suggest appropriate goals for a super-basic Python class (HS level):

    We no longer call it that. (inb4 "who's 'we'?")
    "Dependency injection" is a better name.

    Dependency injection is am implementation pattern that helps you implement dependency inversion. They're related concepts, but not the same thing.

    Though ""dependency inversion" is usually called "Inversion of Control" to avoid confusion.

    And DI can have many different implementations.



  • I think OOP may be unecessary. And considering a lot of professional programmers can't do OOP properly, inflicting it upon an introductory programming class for people with no computer skills might be a bit of waste of time. They will have enough problems wrapping their heads around flow controls and learning to thing procedurally for the most part. The stuff you take for granted after having been in the field for a while. I've found that most people that have not been inflicted with programming have problems with loops, functions and branching. I even meet programmers that don't know how to do recursion properly.


  • Discourse touched me in a no-no place

    @Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):

    I even meet programmers that don't know how to do recursion properly.

    It's more worrying when you encounter mathematicians who can't do recursion; they're supposed to trained in concepts like the fixed point of a function…



  • Here's a point no one has talked about: after teaching basic imperative programming (fuck that OOP noise), teach the basic ideas behind code design. Things like "each function should do one logical thing", "each piece of logic should only be exist in one place", and why we need those rules.

    I strongly recommend sticking to a small quantity of ideas and "drilling them in", rather than trying to fit more. After all, you can do more by being good at ifs and whiles, than by being terrible at list comprehensions and classes.

    You also should have them do some "realistic" project, because it's much better than learning things in an abstract environment...
    I'm trying to think of some simple application that a n00b could build. But to make a desktop app, the biggest obstacle is GUI libraries, they're too complex for a beginner and not suitable for imperative programming.

    Either make a simple text adventure. Or find a simple enough GUI library. Or just give them a template where they can "fill in the blanks" with their own code.


  • Banned

    @dkf said in Suggest appropriate goals for a super-basic Python class (HS level):

    @Carnage said in Suggest appropriate goals for a super-basic Python class (HS level):

    I even meet programmers that don't know how to do recursion properly.

    It's more worrying when you encounter mathematicians who can't do recursion; they're supposed to trained in concepts like the fixed point of a function…

    What do fixed points have to do with recursion?


  • Discourse touched me in a no-no place

    @Gąska They're how you go from the operational semantics of the function to the denotational semantics.



  • @anonymous234 I took an intensive 4 week C programming course right at the start of my career. I already new C and was competent in it but I took the course because it was free, it gave an NVQ level 3 (not terribly useful but better than useless) and most importantly it promised 12 weeks work experience. Experience was where I was lacking and I was confident I could turn that 12 weeks into a job. As it happened, I ended up doing work experience in COBOL, then going on and working in COBOL at the same place for the next 5 years. I didn't even know the language at the time.

    Anyway, for the first day or so I paid attention to the lecturer. He was very good and knew his stuff. It was done on UNIX terminals, with not much more than the necessary functions to program enabled. It was a high level course and expected you to know how to program in C already which I did, so I spent the next 4 weeks writing a text adventure set in the training center, with the quirks of the various staff turned into hazards and puzzles. As I did all the course work, and even found time to help out some of the less advanced students, the lecturer didn't mind.


  • 🚽 Regular

    @dfdub said in Suggest appropriate goals for a super-basic Python class (HS level):

    Dependency injection is am implementation pattern that helps you implement dependency inversion. They're related concepts, but not the same thing.

    Yeah, I posted that at 4 am, and one of my last thoughts before falling sleep was "oh crap, 'dependency inversion' as in 'inversion of control'". But then I was already lying down and my computer was off, so... mea culpa.


  • BINNED

    I just want to concur that OOP has no place in such a very beginner’s course (it’s not the 90s anymore).

    Also, I’m not particularly strong on didactics (you know those things much better), but it might be a good idea to motivate everything around example problems they find interesting and how to solve them. A book that I’ve not even read and which is for a far more advanced audience but which seems to do this (problems engineers want to solve), so might give some ideas:

    Also, I think handing out one of these little Python “Cheat Sheets” could be neat once they do their own programming.

    EDIT: tried to prevent embedding the whole damn thing but failed.



    1. Show them how to setup the dev environment
    2. Teach them how to output something ("Hi, world")
    3. Teach them about variables.
    4. Show them how to prompt for input.
    5. Show them loops.

    They should now be able to do simple programs like ask for your name and print "Hi, Name"



  • @anonymous234 said in Suggest appropriate goals for a super-basic Python class (HS level):

    Either make a simple text adventure. Or find a simple enough GUI library. Or just give them a template where they can "fill in the blanks" with their own code.

    I would look at some of the common interview assessments, many of them have a simple brute force method that can solve the problem and they should be within reach of an intro class. (Thinking of stuff like word searches, anagram finders, etc...). They usually also have a more efficient way to solve the problem, so you can hint at that for the more advanced students.



  • Coming back to this. Here is my complete list of "things I want to get to this semester". It'll likely get pared down in actual practice, and the order isn't fixed. It's probably over-ambitious, but it gives me a good place to start with more advanced students. I also have a (short) list of larger projects that incorporate multiple objectives (a "guess the number" game that requires terminal I/O, random numbers, looping, and conditionals, for example).

    Computer familiarity

    Use Finder to create, find, move, delete, rename, and archive files and directories
    Use the trackpad and gestures
    Manipulate open windows
    Use VSC to create, rename, and execute Python files
    Use VSC’s terminal window to access the Python interpreter

    Variables & Math operators

    Explain the basic types in Python: boolean, numeric, sequence, dict
    Explain the difference between a variable name, its value, and its type.
    Assign variables
    Explain and use the basic math operators for both integers and floating-point numbers.
    Use variables to solve simple math problems.
    Import and use simple functions in the standard library, including the random and math modules.

    Input/Output

    Write fixed string data to the terminal
    Read string data from the terminal
    Convert user-input data from str to numeric types and handle invalid data.
    Write values of variables to the terminal using string interpolation
    Properly escape character sequences when needed.

    Sequences

    Appropriately choose between lists and dicts
    Use the index operator to select and modify subsets of lists and elements of dicts
    Explain the proper way of copying sequences.
    (advanced) Use list & dict comprehensions

    Conditionals

    Use if...elif...else for branching, including proper syntax and nested conditionals.
    Explain the different comparison operators (==, and, or, not, is, in) and when they’re used.
    Construct complex conditionals by combining simple comparisons
    Use variables to control branching

    Loops

    Explain the differences and similarities between for and while loops, including when to use which kind of loop
    Write correct loops that terminate at the correct point.
    Use continue and break to control the details of looping, including skipping loop bodies or ending early.

    Functions & Parameters

    Explain the difference between a function, a variable, and the parameters to a function.
    Write functions that only take concrete, required variables
    Explain what a default/optional parameter is and how it should be used.
    Return properly-typed data from a function.

    Structured Programming

    Explain where each part of the script (functions, imports, free statements) should go within the file.
    Explain when to extract code into functions
    Properly comment code, including docstrings for functions.

    File I/O

    Read line-based data from text files and iterate over the lines
    Write structured data to text files, including using alternate modes (append vs overwrite) and interpolating text.

    Debugging & Error Handling

    Use try...except to handle exceptions gracefully
    Use the stack trace to find common programming errors such as improper formatting, type errors, and None-type errors


  • 🚽 Regular

    @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    Explain the difference between a variable name, its value, and its type.

    Don't forget to mention aliasing and the difference between reference and value types (thinking of function parameters in particular).



  • @Benjamin-Hall I like this sequence. I think the only thing I would do differently is to put greater emphasis on functions. The sooner students start thinking about breaking a problem into smaller pieces, creating those smaller pieces, and combining the smaller pieces into larger wholes, the better off they'll be, even in non-programming contexts.

    @Zecc said in Suggest appropriate goals for a super-basic Python class (HS level):

    @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    Explain the difference between a variable name, its value, and its type.

    Don't forget to mention aliasing and the difference between reference and value types (thinking of function parameters in particular).

    This is way too technical for students who are starting with lessons on "manipulating open windows." Although, the fact that there is a need for a lesson on

    the proper way of copying sequences

    makes me mad at Python for that crappy piece of subtlety.



  • @MZH said in Suggest appropriate goals for a super-basic Python class (HS level):

    Don't forget to mention aliasing and the difference between reference and value types (thinking of function parameters in particular).

    This is way too technical for students who are starting with lessons on "manipulating open windows."

    To me it seems quite essential to know whether f(x) can change the value of x or not.


  • Discourse touched me in a no-no place

    @Grunnen said in Suggest appropriate goals for a super-basic Python class (HS level):

    To me it seems quite essential to know whether f(x) can change the value of x or not.

    Yes… but that's not for beginners.



  • @dkf said in Suggest appropriate goals for a super-basic Python class (HS level):

    @Grunnen said in Suggest appropriate goals for a super-basic Python class (HS level):

    To me it seems quite essential to know whether f(x) can change the value of x or not.

    Yes… but that's not for beginners.

    Yes and no, I’d say. I certainly don’t think the whole semantics and reasons of it should be explained, but something like, “You can use a variable name within a function without changing the value of another variable with the same name outside the function” will certainly help, I think. Else you’re bound to get people to do things like come up with convoluted variable names because they think they’re all the same if they have the same name. And it should be easy enough to demonstrate to anyone who understands variables and functions already.


  • Discourse touched me in a no-no place

    @Gurth OK, I see what you mean. Local-ness of variable names is a good thing to teach early, but the subtleties of object identity semantics and modifiability are not. I guess they're more the stuff you teach when you start in on the intermediate level material.

    In fact, it's possibly a good idea to just teach unmodifiable objects (e.g., tuples rather than lists) to start out with since they're significantly harder to screw up in weird ways, at a cost of a lot more processing overhead. Which is absolutely fine for beginners. (The subtleties of modifiable collections and action-at-a-distance semantics are why I'm definitely in two minds as to whether Python is as good a language for beginners as it claims to be…)


  • Considered Harmful

    @Gurth I'd just say 'the name is yours, but the value isn't. So if you change something inside the value the caller will see that, but if you put a new value under the name then it won't affect anything else.'



  • I've never been very interested in it, but apparently Python has a different way of thinking about variables than e.g. C.

    C:

    int a = 1; // make a box  in memory and put a value into it
    a = 2; // put a different value into the box
    

    Python:

    a = 1 // Put the number 1 somewhere in memory and let 'a' point to it
    a = MyClass() // Put an object somewhere in memory and let 'a' point to it
    

  • Discourse touched me in a no-no place

    @Grunnen Python has a different shape of box that can hold any old value, unlike in C where boxes have very definite shapes (in terms of number of bits; other languages define the shape even more strongly). This is pretty convenient when you're not sure what sort of thing you want to put in it, but gets inefficient when you want to have a whole lot of them piled together and only want to put a small thing in each.



  • @Grunnen That's memory-managed languages in general. Just imagine there's an "object-space" somewhere where all the objects "float" freely on their own. Variables point to them, but don't contain them.



  • @anonymous234 It's probably important to tell this from the first moment that variables are introduced.

    If you introduce variables in the classic way as 'boxes that contain something', it will only lead to confusion with function parameters, with assigning lists to another variable, etc.



  • @Grunnen said in Suggest appropriate goals for a super-basic Python class (HS level):

    I've never been very interested in it, but apparently Python has a different way of thinking about variables than e.g. C.

    You could probably have guessed as much from that in C you have to declare that a is an int when you first assign it a value, whereas in Python you can just assign it a value without having to say which kind that will be.



  • So here's my "Computer Skills Assessment". The numbers in parentheses are the objectives each task covers. I plan on giving this by the second day as a pre-test, but they'll be able to remediate if they don't already know the material. That way, if everyone already can do it, I can just move along.

    This is a timed assessment. Since these are very basic skills, you will need to be able to do them accurately and fast.

    On the Computer Skills page of the PSL class, you will find three files labeled CS_Assessment_1.zip, CS_Assessment_2.zip, CS_Assessment_3.zip. If your last name starts with

    A-I: you will work with CS_Assessment_1.zip

    J-R: you will work with CS_Assessment_2.zip

    S-Z: you will work with CS_Assessment_3.zip

    Download the file, uncompress it, and complete the following tasks.

    1. Rename the file named “count.txt” to be your first name, followed by “.txt” (1.1, 1.2)

    2. Open the file you just renamed in Visual Studio Code (1.4)

    3. Fill in the blanks with the number of each of the following found in the archive you downloaded (1.6):

    Plain text files
    Images (of all types)
    python files

    1. Access the python interpreter from VSC’s terminal and add the version number it reports on startup to the text file. (1.5)

    2. Open the file named “helloworld.py” in VSC and execute it. Copy the text it outputs to the text file. (1.3, 1.4)

    3. Compress all the files from the archive (including the one you modified) (1.1)

    4. Upload it to the PSL dropbox for this assignment.

    Correct completion of this assessment within 10 minutes will earn you a 4 for each of those objectives. If you have to ask for help or it requires 10-20 minutes, you will earn a 3. Any errors will result in a 2 or less.

    As a note, the grading scale goes
    4: Full proficiency (100%)
    3: Meets basic proficiency but can improve (83.3%)
    2: Proficiency substantially lacking, remediation needed (67%)
    1: No proficiency displayed (50%)

    0% is only assigned if they did not take any of the related assessments and did not make them up.



  • Now that I have a basic structure of content, I'm thinking about skills. Cross-cutting skills that I can assess and teach.

    In my mind, the basic skills of a junior/intro programmer are:

    1. Read simple code fragments written by others and, given inputs, predict both the expected output and the real output (the difference being the bugs).
    2. Document the purpose, invariants, and required inputs of simple code (either their own or that of others) in their own words.
    3. Write code that satisfies simple requirements. This includes using code fragments (functions, etc) produced by others and assembling/calling them to achieve the desired goals.
    4. Debug common programming errors using a stack trace and documentation.

  • Discourse touched me in a no-no place

    @Benjamin-Hall All of that being in addition to “uses a computer” type skills, which programmers of pretty much all levels need to be adept at.



  • @dkf Yeah, those were presumed at that point. I consider those more "content" (ie stuff to be assessed) than cross-cutting skills (things I can use to assess content).

    I'm planning on having them show that they've mastered the content by doing skills 1-4 above. So a question might go

    I want to print the values of the first ten perfect squares. Do this with a for...in... loop.

    or

    Write the docstring for the following piece of code:

    def is_apple(fruit):
      if (fruit.lower() == "apple"):
        return True
      return False
    

    or

    <piece of code and stack trace> Circle the offending statement and write what it should have been.

    or

    What will <piece of code> return if the arguments are "apple" and "spam"? What about if they're 1 and [3,2,1]?



  • @Benjamin-Hall said in Suggest appropriate goals for a super-basic Python class (HS level):

    def is_apple(fruit):
    if (fruit.lower() == "apple"):
    return True
    return False

    Please tell me you'll teach then to return the result of the boolean expression directly. I hate it when people write code like this.



  • @dfdub Yeah, If I hadn't been writing that on the spur of the moment I'd have written it as

    def is_apple(fruit):
      return fruit.lower() == "apple"
    

    I'm normally better about that, but had a brain-fart. Good catch. I try to model good code for the kids, because they're experts at coming up with bad code themselves and don't need help with that.



  • This post is deleted!


  • So, now the semester has started.

    And what were supposed to be very basic students? They all have at least some experience, although not necessarily with Python. Guess I'll have to accelerate things quite a bit while still hitting the basics.

    Sigh...that's gonna take effort. And I don't like effort.



  • It's a bit horrifying to see so many supposedly competent programmers in here bashing on OOP.

    If you're going to teach a programming class, you'll be doing the kids a massive disservice if you don't teach them about OOP, because OOP is what the world of programming runs on. There's a good reason why the Simula-style object-oriented paradigm has taken over the world of programming like nothing else before or since: it is hands-down better at managing complexity than anything else we've tried. And complexity, and growth of complexity to greater and greater degrees, and fighting to keep it under control, has been the story of the entire history of software development.

    Here's the simple way to explain it to a new student: Start with basic imperative programming. You have a program. This program has data, and it has functions that operate on that data. But once that program grows beyond a trivial size, keeping track of all the data and functions gets complicated.

    So what do you do? You organize it. And as is common for organizational systems, the best way to do it is to take the same basic concept and repeat it at a smaller scale. You can think of the entire program as one big object with some data and some functions that operate on that data... so now we create smaller objects with their own data and their own functions methods that operate on that data.

    And just like the person running the program doesn't need to know how the data is organized inside the program in order to use it--and we don't actually let them get at the data directly because they could corrupt things and break it; instead they have to manipulate the program via the user interface--the people using an object don't need to know how its internal data works either. We hide the data behind a public interface, and call this encapsulation, and it protects the data inside your objects from corruption.

    When you're writing a bunch of objects, you're likely to come across cases where you're doing very similar things with slightly different types of data. For example, reading data from a file, downloading data from a Web page, and reading data from a compressed archive are all very similar. You take a [thing] that has data in it and read data from the [thing] in a linear fashion, from beginning to end. So you can simplify your code by creating a base class that defines reading data from a [thing], but leaves the exact nature of the [thing] undefined. This is called an abstract class, and you leave it up to the subclasses to define the [thing] and fill in the specific blanks, which has two major advantages:

    1. it's about 10 times simpler than building the entire "read data from" logic over and over every time
    2. you can now have code that operates on your base class (let's call it a Stream) and reads data from any Stream without having to care what kind of [thing] the Stream is reading from. Again, that's much simpler than having to have different logic to use the data from every kind of [thing].

    This is known as polymorphism, and more than anything else, it's the reason why OOP is so awesome and has come to dominate the world of programming. Once the students "get" polymorphism, they'll become much better programmers overnight.


Log in to reply