Factorial - Ada Typing CST Test
Loading…
Factorial — Ada Code
Calculates factorial recursively.
with Ada.Text_IO; use Ada.Text_IO;
procedure Factorial is
function Fact(N: Integer) return Integer is
begin
if N <= 1 then
return 1;
else
return N * Fact(N-1);
end if;
end Fact;
begin
Put_Line("Factorial 5: " & Integer'Image(Fact(5)));
end Factorial;Ada Language Guide
Ada is a statically typed, high-level programming language designed for safety-critical, real-time, and concurrent systems. Developed with reliability and maintainability in mind, Ada emphasizes strong typing, modularity, exception handling, and support for concurrent programming.
Primary Use Cases
- ▸Safety-critical avionics systems
- ▸Real-time embedded software
- ▸Railway signaling and control
- ▸Defense and military software
- ▸Medical device software
- ▸High-integrity systems requiring formal verification
Notable Features
- ▸Strong static typing and compile-time checks
- ▸Support for tasking (concurrency)
- ▸Exception handling and robust error management
- ▸Package-based modularity
- ▸Design-by-contract with pre/post conditions
Origin & Creator
Ada was commissioned by the U.S. Department of Defense in the late 1970s and early 1980s, designed by Jean Ichbiah and his team at CII Honeywell Bull under the name 'Ada' in honor of Ada Lovelace.
Industrial Note
Ada is essential in avionics, railway control systems, nuclear power plant software, medical devices, and mission-critical defense applications where software failure is unacceptable.
Quick Explain
- ▸Ada supports structured, object-oriented, and concurrent programming paradigms.
- ▸It is widely used in aerospace, defense, transportation, and other safety-critical systems.
- ▸Its compiler enforces strict type checking, which reduces runtime errors and improves reliability.
Core Features
- ▸Procedures, functions, and packages
- ▸Tasking and protected types for concurrency
- ▸Generics for reusable code
- ▸Exception handling
- ▸Strong typing and subtyping
Learning Path
- ▸Learn Ada syntax and strong typing
- ▸Understand procedures, functions, and packages
- ▸Explore tasking and concurrency
- ▸Practice exception handling
- ▸Apply Ada to real-time and embedded systems
Practical Examples
- ▸Hello World console program
- ▸Concurrent producer-consumer tasks
- ▸Embedded system sensor interface
- ▸Railway signal control logic
- ▸Flight software for avionics
Comparisons
- ▸More robust than C/C++ for safety-critical systems
- ▸Less flexible for rapid scripting than Python or Ruby
- ▸Concurrency model safer than traditional threads
- ▸Strong typing prevents many runtime errors
- ▸Better for certified systems than general-purpose languages
Strengths
- ▸High reliability and maintainability
- ▸Excellent support for concurrent and real-time systems
- ▸Compile-time type safety reduces runtime errors
- ▸Modular design encourages clean architecture
- ▸Widely used in certified, high-integrity systems
Limitations
- ▸Steep learning curve for beginners
- ▸Less community support compared to mainstream languages
- ▸Verbose syntax relative to modern scripting languages
- ▸Smaller ecosystem of libraries for general-purpose programming
- ▸Not ideal for rapid prototyping or casual applications
When NOT to Use
- ▸Rapid prototyping or scripting
- ▸Casual web development
- ▸GUI-heavy desktop apps
- ▸Games and graphics-intensive apps
- ▸Machine learning with extensive libraries
Cheat Sheet
- ▸with Ada.Text_IO; use Ada.Text_IO;
- ▸procedure Main is
- ▸ begin Put_Line('Hello World');
- ▸end Main;
- ▸task type Worker is ... end Worker;
FAQ
- ▸Is Ada still used today?
- ▸Yes - in aerospace, defense, railways, and other safety-critical industries.
- ▸Can Ada handle concurrency?
- ▸Yes - Ada provides tasking and protected types.
- ▸Is Ada suitable for beginners?
- ▸It has a steep learning curve but excellent for safety-critical programming.
- ▸Does Ada support object-oriented programming?
- ▸Yes - Ada supports OOP with tagged types and inheritance.
30-Day Skill Plan
- ▸Week 1: Basic syntax, variables, and procedures
- ▸Week 2: Packages, modularity, and type system
- ▸Week 3: Tasking, concurrency, and protected types
- ▸Week 4: Exception handling and real-time programming
Final Summary
- ▸Ada is a high-integrity, strongly typed language for safety-critical and real-time systems.
- ▸Ideal for avionics, defense, transportation, and embedded applications.
- ▸Its strict typing, modularity, and concurrency features make it reliable and maintainable.
- ▸Ada continues to be relevant in certified, mission-critical software development.
Project Structure
- ▸source.adb (body)
- ▸source.ads (specification)
- ▸packages/
- ▸tests/
- ▸Makefiles or GNAT project files (.gpr)
Monetization
- ▸Defense and aerospace contracts
- ▸Medical device software development
- ▸Railway and transportation control systems
- ▸Consulting in real-time and safety-critical systems
- ▸High-integrity software engineering services
Productivity Tips
- ▸Use packages for modularity
- ▸Follow strict naming conventions
- ▸Test tasks and concurrency carefully
- ▸Leverage SPARK for verification
- ▸Use Makefiles or GNAT project files to automate builds
Basic Concepts
- ▸Strong typing and variable declarations
- ▸Procedures and functions
- ▸Packages and modularity
- ▸Tasking and concurrency
- ▸Exception handling
Official Docs
- ▸Ada Reference Manual
- ▸AdaCore GNAT User Guide
- ▸SPARK Ada Verification Guide