Turn repeated reasoning into small components · 3 Lessons
English

Ada Engineering

Module 3 – Turn repeated reasoning into small components

Page 2 of 3 · About 15 minutes per lesson, including practice.

Separate an interface from its implementation

A package groups related declarations. Its specification tells callers which operations are available; a package body can hold the implementation. For a larger local project, a Study_Plans package could declare Remaining in study_plans.ads, define it in study_plans.adb, and let a main procedure call Study_Plans.Remaining. The single-file starter keeps the first exercise manageable.

A procedure can perform actions without returning a function result. Parameter modes describe how a subprogram may use its parameters: in for reading, out for producing a value, and in out for reading and updating. Choose the smallest interface that expresses the job. Do not hide unrelated changes inside a function named only to calculate a count.

Reference: AdaCore: modular programming.

Example code on Agila Forge ↗

Complete this lesson

Answer every check correctly to earn your lesson certificate. Feedback helps you review and try again.

Sign in · Save your progress and earn a certificate for this lesson.