Well I’ve been a bit lazy with the updates, but in the last two weeks I have finished the entirety of HtC: SD on edx.
I’ll continue where I left off in my last post: Week 4 focused on self-reference and reference. Self-reference means when a data definition refers to itself, then the template for that function must include a “natural recursion.” The primary type of self-referential data we work with is Lists (remember car and cdr), where an list can either be empty or a pair of items, where the second item is another list. Therefore, naturally, to work on this type of data we need some recursive function. I have worked with recursion a bit (a very tiny bit) but I enjoyed this approach to teaching it. Solving problems with recursion can be a bit tricky, which is why “well formed” tests will help your development.
Reference (as opposed to self-reference) means when a data type contains another type of data that is non-primitive. For example, a List of Bears, each item can be a Bear (which would be some other structure). The point is, if we refer to a non-primitive data type, we need to include reference to that data type’s template into the new template. It’s a bit less confusing than it sounds. If you have a list of x,y pairs, and you want to adjust every point in the list, you’ll need a function that operates on a single point itself. This lends itself to the Helpers module.
A helper function, simply, does a small part of a function. You can use helpers for function composition (remember JS Allonge?) or when the “knowledge domain” changes. Many many helpers might be needed for large or complex problems. Helper functions make debugging and keeping track of the flow of information much easier.
The course also touched on Binary Search Trees, which is vaguely familiar form CS50 (though I believe that was just binary search, and search trees/tries were separate). To be honest I struggled a bit with these, a few problems in the problem set tricked me up (partially due to misunderstanding the problem statement)
The final project of the course Space Invaders was a fun opportunity to combine everything I’d learned. A lot LOT of helper functions, test-driven design, breaking down a problem into sub-problems. I am quite proud of my little result. The code is somewhere on github but I’m not going to post it as maybe you haven’t finished the course yet!
I super recommend this course, it is not the most challenging (like CS50 was for me) but it teaches a lot of broadly applicable lessons in CS. The followup, HtC: Complex Data, is supposed to be much tougher! Let’s go!