Diffusion-based molecular nanonetworks exploit the diffusion of molecules, e.g., in free space or in blood vessels, for the purpose of communication. This article comprehensively surveys coding approaches for communication in diffusion-based molecular nanonetworks. In particular, all three main purposes of coding for communication, namely source coding, channel coding, and network coding, are covered. We organize the survey of the channel coding approaches according to the different categories of channel codes, including linear block codes, convolutional codes, and inter-symbol interference (ISI) mitigation codes. The network coding studies are categorized into duplex network coding, physical-layer network coding, multi-hop nanonetwork coding, performance improvements of network-coded nanosystems, and network coding in mobile nanonetworks. We also present a comprehensive set of future research directions for the still nascent area of coding for diffusion-based molecular nanonetworks; specifically, we outline research imperatives for each of the three main coding purposes, i.e., for source, channel, and network coding, as well as for overarching research goals.