In computer science, macroprogramming is a programming paradigm where programs for the individual components of a distributed system are compiled or interpreted from a macro-program expressed by a system-level perspective or in terms of the intended global goal. The aim of macroprogramming approaches is to support expressing the macroscopic interactive behaviour of a whole distributed system of computing devices or agents in a single program. It has not to be confused with macros, the mechanism often found in programming languages (like C or Scala) to express substitution rules for program pieces. Macroprogramming originated in the context of wireless sensor network programming and found renewed interest in the context of the Internet of Things and swarm robotics. Macroprogramming shares similar goals (related to programming a system by a global perspective) with multitier programming, choreographic programming, and aggregate computing. Context and motivation Programming distributed systems, multi-agent systems, and collectives of software agents (e.g., robotic swarms) is difficult, for many issues (like communication, concurrency, and failure) have to be properly considered. In particular, a general recurrent problem is how to induce the intended global behaviour by defining the behaviour of the individual components or agents involved. The problem can be addressed through learning approaches, such as multi-agent reinforcement learning, or by manually defining the control program driving each component. However, addressing the problem by a fully individual (or (single-node) perspective may be error-prone, because it is generally difficult to foresee the overall behaviour emerging from complex networks of activities and interactions (cf. complex systems and emergence. Therefore, researchers have started investigated ways to raise the abstraction level, promoting programming of distributed systems by a more global perspective or in terms of the overall goal to be collectively attained. Examples ScaFi The following program in the ScaFi aggregate programming language defines the loop control logic needed to compute a channel (a Boolean field where the devices yielding true are those connecting, through a hop-by-hop path, a source device to a target device) across a large set of situated devices interacting with neighbours. class SelfContainedChannel extends AggregateProgram with SensorDefinitions { def isObstacle = sense[Boolean]("obstacle") def isSource = sense[Boolean]("source") def isDestination = sense[Boolean]("target") override def main(): Boolean = branch(isObstacle){ false }{ channel(isSource, isDestination, 5) } def channel(src: Boolean, dest: Boolean, width: Double): Boolean = dilate(gradient(src) + gradient(dest) <= distBetween(src,dest), width) type OB[T] = Builtins.Bounded[T] def G[V:OB](src: Boolean, field: V, acc: V=>V, metric: =>Double): V = rep(