This document offers a uniform style for creating Ada source code and documentation, and is intended as a guide for all programming assignments. Adherence to a consistent programming style is beneficial in:
Equivalent document: Java Style Guide , describes preferred coding style in terms of the language constructs of Java. The Java Style Guide essentially reuses the Ada Style Guide, translating Ada language references into Java.
PI : constant := 3.14159;
STAR : constant := '*';
procedure Header is
type STACK is array (1 .. MAX) of INTEGER;
Initial_Character: CHARACTER;
procedure Stack_Initialization (S : out STACK);
function StepOutside return ELEMENT;
function IsEmpty (S: in STACK) return BOOEAN;
TopLeftCornerrather than
xy0
if (CountInstalled < ALLPIECES) then
NextSquarePeg := SquarePeg;
while BoardArray (NextSquarePeg) > 0 loop
Increment (NextSquarePeg);
end loop;
SolvePuzzle(NextSquarePeg, RoundHole);
end if;
if OverTheSpeedLimit then
EaseOffGas;
elsif (Road = GardenStateParkway)
while Speed < MINIMUM_SPEED loop
StepOnGas;
end loop;
end if; if OverTheSpeedLimit then EaseOffGas;
elsif Road = GardenStateParkway
while (Speed < MINIMUM_SPEED) loop StepOnGas end loop;
Array_Index := 0;
Flag := FALSE;
rather than
Array_Index := 0; Flag := FALSE;
ALLPIECES : constant := 16; -- checkers constant
MyBoardCanvas : BOARD_CANVAS; -- board display class
SquareClicked : MOVE_RANGE; -- where to move next
OneStepOnly : BOOLEAN; -- no jump possible
NetPay := GrossPay - StateTax - FederalTax;
AmountOwed := -TotalDebits;
if OneStepOnly
OneStepOnly := FALSE;
elsif (ThisOneIsDown (Piece(P,0) = FALSE) then
ThisOneIsDown (Piece (P,0)):= TRUE;
Increment (CountInstalled);
else
StepButton.Enable;
GoButton.Enable;
PauseButton.Disable;
end if;
type STACK is recordOf the two Lilliputian factions -- one camp putting the record at the end of the header line before a new text block, the other camp putting the term indented in the line below -- the author of this Guide sides with the former. More to the point, one should make a choice and then use the chosen style consistently.
function Run (Color : in COLOR_TYPE;Board : in GRID) return RANGE_TYPE is Position: RANGE_TYPE; begin SetBackground(Color.blue); loop for Position in Board'Range (1) loop . . . . . . end loop; -- end of for-loop . . . end loop; -- end of infinite while return Position; end Run;
-- FILE:
-- spider.ads
-- specification for an Ada program using the GNAT compiler
-- AUTHOR:
-- Michael B. Feldman, The George Washington University (Ada 95)
-- MODIFIED BY:
-- Istvan Mohos to provide additional capabilities
-- DATE :
-- November 1, 1996
-- PURPOSE:
-- Provides an implementation of a spider walking on a board
-- INCLUDES:
-- screen.ads
-- INPUTS:
-- User inputs of moves for spider
-- OUTPUTS:
-- A board, with spider movements corresponding to user inputs
-- NOTE:
-- A movement off the edge of the board is treated as a wraparound
-- ERROR CONDITIONS
-- Incorrect user input is handled with an exception that prompts
-- users for correct input.