CodeWorld Import by Hash

  • Students have learned to do a lot of copy and paste, to reuse their drawings in new projects. This initially didn’t bother me much, since I’m not teaching software engineering practices. However, it encourages students to write complex expressions in a single top-level definition so that it’s easier to copy around. That’s not a good strategy.
  • Teachers have wanted to provide scaffolding and setup for assignments and classes, but struggled with their students copying boilerplate code. Fernando Alegre solved this by contributing modules of extra functionality to CodeWorld itself. But other projects, such as setting up virtual physics labs or biology simulations, have been abandoned.
  • Haskell community members have found creative uses for CodeWorld beyond the classroom, and have struggled with the limitation. Joachim Breitner even created a horrifying (but awesome) tool to help him write code in multiple files and then mush it all together in a single file to run inside CodeWorld, and used this to create the presentation for a talk at ICFP in 2017.

Introducing: Import by Hash

The solution to all of this was to piggyback on the existing sharing system in CodeWorld, and allow projects to be imported by hash.

Importing a program by its hash in CodeWorld
  • You can include a module header, if you choose, and it is useful for controlling exports. However, the module is imported by its hash rather than its module name, so the module name itself doesn’t matter.
  • Even if a project exists only to define things for reuse, it should compile and run on its own. So go ahead and use the main entry point (remember, that’s program in the educational dialect, or main in plain Haskell) to define a test or demo. These are not exported (or rather, they are exported but the name is mangled), because they would conflict with the entry point of the code that imports them.
  • Don’t go too crazy! While this does make organizing your code easier, it’s also easy to end up with long chains of dependencies, with the result that you might build a lot of code every time you compile a short file and your builds may time out.
  • If you give students your program hashes (beginning with “P”), they can also use those to get at the code you’ve written. Sometimes that’s not what you want. For instance, if your import is a unit test used for grading, you may want to hide exactly which test cases you’re checking. So you can also import deployed hashes, which have the same behavior, but cannot be used to access source code. To get a deployed hash, run your code, click Share, and then “Share Without Code”. You can copy the dhash parameter from that URL, and import it as a module.

What do I do with this?

Some of the use cases for import-by-hash in CodeWorld were mentioned above. As a student or self-motivated learner, you can easily import and reuse things you’ve defined in other projects. As a teacher or blogger, you can give your students/readers a link or import statement that they can use to get access to setup or scaffolding without too much boilerplate. But the use case I’m most interested in is to build and collect sets of useful educational environments.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Smith

Chris Smith

Software engineer, volunteer K-12 math and computer science teacher, author of the CodeWorld platform, amateur ring theorist, and Haskell enthusiast.