Building a new Concept Exercise Type for Code Organization

Hey there,

code is often organized in different files. For C++ there are header files that can be seen like an API and source files with the implementation. To avoid name collisions, code is often organized in namespaces. These can be accessed side-by-side with other namespaces in the same file after being imported (“included” in C++).

I want to teach about includes, header and source files and why they are helpful or even needed. That would include circle references or double-includes.

Apart from the explanation in the concept files, I want the students to have a separate concept exercise just for that purpose. Nothing complicated. Just several files, which have to be combined to get the solution.

For this, I opened an issue on the C++ track. I would love to have your feedback, while I refine the exercise. Maybe other languages could make use of the concept as well?


I added a PR for the concept docs as well.

I haven’t looked at the issue nor the PR yet (it’s been on my TODO list), but I too have been thinking about a concept exercise about imports and/or dependencies. One thing I have come up with is essentially

Here’s a bunch of code, the precise details of which don’t matter. Currently it doesn’t compile/work. Your task is to (only) add imports and/or dependencies until it does.

Solving this exercise requires reading compiler/runtime errors. Also, a variety of import styles (e.g. Python’s import … vs. from … import …) can be enforced.

Currently, this is planned to be the second concept after basics. This opens up the track to use header files, which are used in every single practice exercise (even hello-world).

The students will have no experience with the compiler at all at this point. If I throw a bug-seeking exercise in front of them and only give them compiler messages as a tool to solve it, they might jump the C++ track and never come back.

Even when you introduce the relevant kinds of compiler errors before, and leave to the student only to figure out which specific functions still need to be imported?

Added: I don’t think you can effectively shield students from compiler errors anyway. Better help them deal with them early on.

Another problem with this idea for C and C++ specifically is that solving such problems aren’t easily solved through imports, as there are no imports: only includes. (I think?)