Today's generation of wireless sensor networks are now moving out of the lab and into the real world. While early applications were single-purpose and primarily of a prototypical nature, contemporary sensor networks are increasingly evolving towards dynamic, multi-stakeholder, multi-purpose scenarios such as smart cities and intelligent logistics. Developing applications for these scenarios requires: (i) expertise along the entire value chain, (ii) appropriate software development paradigms, and (iii) middleware support to mitigate the complexities of distribution and dynamism.Current approaches to programming wireless sensor network applications place a significant burden on the developer, who is forced to take on multiple roles at once: embedded software developer, domain expert, and network technician. These practices are unsustainable in the long-term and stand in clear conflict with the variety of skills needed to design, develop, assemble, deploy, and manage contemporary sensor network applications. In addition, existing solutions for software reconfiguration and management are either coarse-grained and inefficient, or do not provide adequate support for inspection and management of complex distributed software dependencies at run time. The work presented in this dissertation tackles this problem with a two-fold approach: (i) improving software development efficiency for heterogeneous stakeholders through dedicated software abstractions, and (ii) supporting the long-term adaptation, evolution and management requirements of sensing applications. Solutions presented in this dissertation try to maximise flexibility, while respecting the resource constraints of embedded sensing platforms.The key contributions presented in this dissertation are two-fold: (i) stakeholder-appropriate programming paradigms and (ii) efficient runtime support for management and reconfiguration. These contributions are realised in the Component and Policy Infrastructure (CaPI) middleware. The CaPI middleware consists of a programming model and a supporting runtime environment. The CaPI programming model offers abstractions tailored to accommodate the specific software development objectives of embedded developers, application experts, and infrastructure managers. Embedded developers are supported in the creation and encapsulation of generic units of software by LooCI, a lightweight component model specifically designed for dynamic sensor networks. Application experts use LooCI's flexible binding model to safely assemble components into distributed application compositions. Finally, infrastructure managers are supported by expressing management objectives via PMA, a programming environment that supports lightweight policies. The CaPI runtime environment operationally integrates LooCI and PMA and addresses the long-term adaptation, evolution and management requirements of the dynamic software life cycle. Integration is supported by a unified distribution infrastructure, the 'event bus' that masks network heterogeneity and providesfulldistribution transparency. Evolution and management requirements are supported by means of a flexible runtime environment that offers support for dynamic reconfiguration and inspection of distributed application structure and state.The contributions in this dissertation have been validated on representative sensor network platforms and through a number of real-world scenarios performed in close collaboration with academic and industrial partners. Evaluation results demonstrated that CaPI enables flexible and efficient software development andreconfiguration support at significantly lower costs than existing state-of-the-art solutions.