Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Modula3

Learn Modula3 - 10 Code Examples & CST Typing Practice Test

Modula-3 is a high-level, statically typed programming language designed for safe systems programming, modularity, and object-oriented programming. It emphasizes simplicity, safety, and readability while providing features suitable for building large, robust software systems.

View all 10 Modula3 code examples →
Modula-3 Counter and Theme ToggleModula-3 Random Number GeneratorModula-3 Todo ListModula-3 Dice RollerModula-3 Countdown TimerModula-3 Prime CheckerModula-3 Temperature ConverterModula-3 Shopping CartModula-3 Name GreetingModula-3 Stopwatch

Learn MODULA3 with Real Code Examples

Updated Nov 21, 2025

Explain

Modula-3 allows developers to write modular, maintainable code with strong type safety.

It supports object-oriented programming, generics, and concurrent programming.

Commonly used for systems software, compilers, networked applications, and research projects.

Core Features

Modules for encapsulation

Objects and interfaces for abstraction

Automatic memory management (garbage collection)

Strong type system preventing unsafe operations

Concurrent programming with threads and monitors

Basic Concepts Overview

Modules, interfaces, and implementations

Strong typing and type inference

Objects and inheritance

Exceptions and concurrency primitives

Memory management with garbage collection

Project Structure

src/ - Modula-3 source code

lib/ - library modules

bin/ - compiled executables

tests/ - unit tests and validation scripts

docs/ - documentation and design notes

Building Workflow

Write Modula-3 source code (.m3 files)

Define interfaces and implementation modules

Compile using Modula-3 compiler

Link modules into executable program

Test and debug using standard compiler tools

Difficulty Use Cases

Beginner: small modular programs

Intermediate: object-oriented applications

Advanced: concurrent systems programming

Expert: compiler or runtime development

Enterprise: safe and maintainable modular systems

Comparisons

Safer than C or C++ due to garbage collection and strong typing

More modular than Pascal or early Modula-2

Concurrency primitives built-in unlike many older languages

Less popular than mainstream languages like Java or C#

Designed for systems and research rather than general scripting

Versioning Timeline

Late 1980s - Initial design at DEC SRC and Olivetti Research Center

Early 1990s - Compiler and runtime developed

1994 - First standard release and academic adoption

1995-2000 - Used in systems programming and compiler research

2025 - Legacy language with niche academic use

Glossary

Module: encapsulated code unit

Interface: exported API for modules

Object: supports inheritance and encapsulation

Exception: runtime error handling construct

Monitor: concurrency primitive for thread safety

Installation Setup

Download a Modula-3 compiler (e.g., m3, DEC SRC compiler)

Install and configure compiler on system

Set environment variables for Modula-3 workspace

Verify installation with a simple test program

Ensure standard libraries and runtime are accessible

Environment Setup

Install Modula-3 compiler (e.g., DEC SRC m3)

Set M3_PATH environment variable to library locations

Verify installation with test programs

Ensure runtime libraries are accessible

Test concurrency and exception features

Config Files

source.m3 - main source file

lib/ - libraries and modules

bin/ - compiled executables

tests/ - validation scripts

docs/ - design and API documentation

Cli Commands

m3c source.m3 - compile Modula-3 code

m3run executable - run compiled program

m3build project - build linked modules

m3test tests/ - run test suite

m3version - check compiler version

Internationalization

Supports Unicode via strings

Modules can handle localized resources

No standard i18n libraries

Text formatting handled in application modules

Locale awareness implemented per project

Accessibility

Limited; relies on external libraries

Modules can abstract accessibility features

Keyboard/mouse events handled manually

Text-based UIs easier to implement

Primarily academic or research accessibility focus

Ui Styling

Modula-3 itself has no GUI standard

Custom GUI via X11 bindings or external libraries

Modular event-driven design recommended

GUI elements encapsulated in modules

Portable design via modular abstraction

State Management

Module-level variables encapsulated within modules

Object fields and methods manage state

Concurrent state managed via monitors

Garbage collection handles object lifecycle

Explicit state management for critical performance paths

Data Management

Primitive types: INTEGER, REAL, BOOLEAN

Composite types: RECORDS, ARRAYS

Objects and classes for structured data

Exception and error data

Thread-safe shared resources via monitors

Architecture

Modules encapsulate code and data

Objects implement interfaces

Memory managed by garbage collector

Concurrency primitives for threads and monitors

Applications linked via module interfaces

Rendering Model

Modules compiled into native binaries

Objects and interfaces provide encapsulation

Garbage collector manages memory automatically

Concurrency primitives control thread execution

Exception handling ensures safe runtime behavior

Architectural Patterns

Modular programming

Object-oriented programming

Exception-driven error handling

Monitor-based concurrency

Layered module dependencies

Real World Architectures

Modular server applications

Compiler and language toolchains

Concurrent network simulations

Educational modular programming systems

Legacy research projects and experiments

Design Principles

Safety via strong typing and garbage collection

Modular programming via interface and implementation separation

Readable and maintainable syntax

Concurrent programming support

Object-oriented constructs for abstraction

Scalability Guide

Use modules and interfaces for large projects

Leverage object-oriented abstractions

Design concurrency to avoid bottlenecks

Reuse library modules to minimize duplication

Profile and optimize memory-intensive modules

Migration Guide

Port modular Pascal or Modula-2 code to Modula-3

Use interfaces to separate API and implementation

Refactor unsafe memory usage to leverage GC

Update concurrency logic to use monitors

Modularize large codebases into multiple modules

Performance Notes

Garbage collection may impact runtime performance

Minimize deep recursion in critical modules

Optimize concurrency design to reduce contention

Reuse modules efficiently to limit overhead

Profiling can help identify bottlenecks in large systems

Security Notes

Strong typing prevents many memory errors

Modules encapsulate sensitive data

Exception handling can prevent crashes

Concurrency primitives help avoid race conditions

Safe programming practices recommended for system code

Monitoring Analytics

Use compiler warnings and runtime checks

Monitor garbage collection performance

Profile concurrent thread execution

Log module interactions for debugging

Track memory and exception behavior

Code Quality

Strict type checking for safety

Use interfaces to enforce contracts

Document modules and APIs

Unit test objects and modules

Avoid global mutable state

Practical Examples

Building a modular text editor

Implementing a concurrent server

Designing a compiler front-end

Developing network protocol simulations

Prototyping educational systems programming exercises

Troubleshooting

Check module import paths

Ensure interface and implementation match

Resolve type mismatches using compiler feedback

Debug concurrency issues with threads and monitors

Use compiler warnings to catch potential runtime errors

Testing Guide

Write test modules for each interface

Use exception handling to test error cases

Validate object behavior and method contracts

Check concurrent thread execution

Verify module linking and compilation

Deployment Options

Compiled native binaries

Executable modules for research projects

Educational software for teaching modular programming

Cross-platform deployment with compatible runtime

Library modules for reuse in larger projects

Tools Ecosystem

DEC SRC Modula-3 compiler

m3 compiler from various distributions

Standard Modula-3 libraries

Debugger tools integrated with compiler

Community-contributed modules and examples

Integrations

System-level libraries

Networking and file I/O

GUI libraries via bindings (X11 or custom)

Compiler toolchains for low-level operations

Educational frameworks for modular programming

Productivity Tips

Plan module interfaces before implementation

Leverage garbage collection for memory safety

Encapsulate state in modules and objects

Use concurrency primitives efficiently

Document modules to ease maintenance

Challenges

Create a small modular calculator

Develop a simple concurrent server

Implement an object-oriented library

Design a mini compiler front-end

Build a modular GUI prototype (optional)

Learning Path

Understand basic Modula-3 syntax and types

Learn module system and interface definitions

Practice object-oriented design in Modula-3

Implement concurrency with threads and monitors

Build and link modular applications

Skill Improvement Plan

Week 1: Syntax, variables, and basic modules

Week 2: Objects, interfaces, and classes

Week 3: Exceptions and type safety

Week 4: Concurrency primitives and threads

Week 5: Large modular program design and compilation

Interview Questions

What is Modula-3 and why was it created?

Explain modules and interfaces in Modula-3

How does garbage collection work in Modula-3?

Describe concurrency primitives and their use

When would you choose Modula-3 over C++ or Java?

Cheat Sheet

MODULE MyModule;

INTERFACE IMyInterface = ... ;

IMPLEMENTATION ... END MyModule;

VAR x: INTEGER;

EXCEPTION SomeError;

Books

Programming in Modula-3

Modula-3 Language and Applications

Safe Systems Programming with Modula-3

Concurrent Programming in Modula-3

Modula-3 Reference Manual

Tutorials

Getting Started with Modula-3

Modular Programming Concepts

Object-Oriented Design in Modula-3

Concurrency and Monitors

Building and Linking Modular Applications

Official Docs

Modula-3 Language Reference Manual

DEC SRC Modula-3 Compiler Documentation

Research papers and academic tutorials

Community Links

Modula-3 Mailing Lists

University Research Groups

GitHub Repositories with Modula-3

Archived DEC SRC resources

Academic course materials

Community Support

Modula-3 mailing lists

University research groups

GitHub repositories with Modula-3 code

Old DEC SRC documentation

Community-contributed examples and educational material

Monetization

Primarily academic and research usage

Educational tools and teaching software

Niche commercial systems requiring safety

Prototyping modular software

Compiler or systems toolchains

Future Roadmap

Mostly legacy support and educational use

Tooling and compiler improvements for niche projects

Modern language influence continues in teaching

Integration with research operating systems

Focus on modularity and safe concurrent programming

When Not To Use

Rapid web development

Mobile app development

Large enterprise applications needing modern libraries

High-performance low-level embedded systems

Projects requiring large third-party ecosystem

Final Summary

Modula-3 is a safe, modular, statically typed language for systems programming and research.

It provides garbage collection, strong typing, object-orientation, and concurrency primitives.

Ideal for building reliable, modular, and concurrent software with a focus on maintainability.

Mostly used in academic, educational, and legacy systems contexts.

Faq

Is Modula-3 still used?

Primarily in research, legacy systems, and education.

Does Modula-3 have garbage collection?

Yes, automatic memory management is built-in.

Can Modula-3 handle concurrency?

Yes, with built-in threads and monitors.

Is Modula-3 object-oriented?

Yes, supports objects, classes, and interfaces.

Is Modula-3 suitable for modern enterprise software?

Rarely; mainly used for research and teaching.

Code Sample Descriptions

1

Modula-3 Counter and Theme Toggle

MODULE CounterTheme;

IMPORT IO;

VAR
    count: INTEGER := 0;
    isDark: BOOLEAN := FALSE;

PROCEDURE updateUI():=BEGIN
    IO.Put("Counter: "); IO.PutInt(count, 0); IO.PutLn();
    IF isDark THEN
        IO.PutLn("Theme: Dark")
    ELSE
        IO.PutLn("Theme: Light")
    END;
END updateUI;

PROCEDURE increment():=BEGIN
    count := count + 1;
    updateUI();
END increment;

PROCEDURE decrement():=BEGIN
    count := count - 1;
    updateUI();
END decrement;

PROCEDURE reset():=BEGIN
    count := 0;
    updateUI();
END reset;

PROCEDURE toggleTheme():=BEGIN
    isDark := NOT isDark;
    updateUI();
END toggleTheme;

BEGIN
    updateUI();
    increment();
    increment();
    toggleTheme();
    decrement();
    reset();
END CounterTheme.

Demonstrates a simple counter with theme toggling using Modula-3 variables, procedures, and safe I/O.

Let’s Try →
2

Modula-3 Random Number Generator

MODULE RandomGen;
IMPORT IO, SYSTEM;
VAR i, num: INTEGER;
BEGIN
    FOR i := 1 TO 3 DO
        num := SYSTEM.Random() MOD 100 + 1;
        IO.Put("Random "); IO.PutInt(i,0); IO.Put(" : "); IO.PutInt(num,0); IO.PutLn();
    END;
END RandomGen.

Generates random numbers between 1 and 100 and prints them.

Let’s Try →
3

Modula-3 Todo List

MODULE TodoList;
IMPORT IO;
VAR todos: ARRAY [0..9] OF STRING;
VAR count: INTEGER := 0;

PROCEDURE addTask(task: STRING);
BEGIN
    todos[count] := task; count := count + 1;
    FOR i := 0 TO count-1 DO IO.PutLn(todos[i]) END;
END addTask;

PROCEDURE removeTask(index: INTEGER);
VAR i: INTEGER;
BEGIN
    FOR i := index TO count-2 DO todos[i] := todos[i+1] END;
    count := count - 1;
    FOR i := 0 TO count-1 DO IO.PutLn(todos[i]) END;
END removeTask;

BEGIN
    addTask("Buy milk");
    addTask("Write Modula-3 code");
    removeTask(0);
END TodoList.

Maintains a simple todo list with add and remove functionality.

Let’s Try →
4

Modula-3 Dice Roller

MODULE DiceRoll;
IMPORT IO, SYSTEM;
VAR i, roll: INTEGER;
BEGIN
    FOR i := 1 TO 3 DO
        roll := SYSTEM.Random() MOD 6 + 1;
        IO.Put("Roll "); IO.PutInt(i,0); IO.Put(" : "); IO.PutInt(roll,0); IO.PutLn();
    END;
END DiceRoll.

Rolls a six-sided dice three times.

Let’s Try →
5

Modula-3 Countdown Timer

MODULE Countdown;
IMPORT IO;
VAR count: INTEGER := 5;
BEGIN
    WHILE count >= 0 DO
        IO.Put("Countdown: "); IO.PutInt(count,0); IO.PutLn();
        count := count - 1;
    END;
    IO.PutLn("Done!");
END Countdown.

Counts down from 5 to 0.

Let’s Try →
6

Modula-3 Prime Checker

MODULE PrimeCheck;
IMPORT IO;
VAR nums: ARRAY [0..2] OF INTEGER := [7,10,13];
VAR n, i: INTEGER;
VAR isPrime: BOOLEAN;
BEGIN
    FOR n IN nums DO
        isPrime := TRUE;
        FOR i := 2 TO n-1 DO
        IF n MOD i = 0 THEN isPrime := FALSE END;
        END;
        IO.PutInt(n,0);
        IF isPrime THEN IO.PutLn(" is Prime") ELSE IO.PutLn(" is Not Prime") END;
    END;
END PrimeCheck.

Checks if numbers are prime.

Let’s Try →
7

Modula-3 Temperature Converter

MODULE TempConv;
IMPORT IO;

PROCEDURE cToF(c: REAL): REAL;
BEGIN RETURN c*9/5+32 END cToF;

PROCEDURE fToC(f: REAL): REAL;
BEGIN RETURN (f-32)*5/9 END fToC;

BEGIN
    IO.Put("25°C = "); IO.PutReal(cToF(25),2); IO.PutLn();
    IO.Put("77°F = "); IO.PutReal(fToC(77),2); IO.PutLn();
END TempConv.

Converts Celsius to Fahrenheit and Fahrenheit to Celsius.

Let’s Try →
8

Modula-3 Shopping Cart

MODULE ShoppingCart;
IMPORT IO;
VAR cart: ARRAY [0..9] OF STRING;
VAR prices: ARRAY [0..9] OF INTEGER;
VAR count: INTEGER := 0;

PROCEDURE addItem(item: STRING; price: INTEGER);
BEGIN
    cart[count] := item; prices[count] := price; count := count + 1;
    (* print cart and total sum here *)
END addItem;

PROCEDURE removeItem(index: INTEGER);
VAR i: INTEGER;
BEGIN
    FOR i := index TO count-2 DO cart[i] := cart[i+1]; prices[i] := prices[i+1] END;
    count := count -1;
    (* print cart and total sum here *)
END removeItem;

BEGIN
    addItem("Apple", 2);
    addItem("Banana", 3);
    removeItem(0);
END ShoppingCart.

Adds and removes items in a shopping cart with total cost.

Let’s Try →
9

Modula-3 Name Greeting

MODULE Greet;
IMPORT IO;
PROCEDURE greet(name: STRING);
BEGIN
    IO.Put("Hello, "); IO.Put(name); IO.PutLn("! Welcome!");
END greet;

BEGIN
    greet("Saurav");
    greet("Alice");
    greet("Bob");
END Greet.

Greets users by name.

Let’s Try →
10

Modula-3 Stopwatch

MODULE Stopwatch;
IMPORT IO;
VAR time: INTEGER := 0;
BEGIN
    WHILE time < 5 DO
        IO.Put("Stopwatch: "); IO.PutInt(time,0); IO.PutLn();
        time := time + 1;
    END;
    IO.PutLn("Done!");
END Stopwatch.

Simulates a stopwatch incrementing seconds.

Let’s Try →

Frequently Asked Questions about Modula3

What is Modula3?

Modula-3 is a high-level, statically typed programming language designed for safe systems programming, modularity, and object-oriented programming. It emphasizes simplicity, safety, and readability while providing features suitable for building large, robust software systems.

What are the primary use cases for Modula3?

Safe systems programming. Concurrent applications. Compiler development. Networked and distributed systems. Educational projects on modular programming

What are the strengths of Modula3?

High-level abstraction with system-level control. Safe and reliable code through static typing and garbage collection. Supports modular and object-oriented design. Concurrency built into the language. Readable and maintainable syntax

What are the limitations of Modula3?

Smaller community compared to mainstream languages. Limited library ecosystem and tooling. Primarily academic or research use. Not widely used in modern commercial software. Performance can be impacted by garbage collection

How can I practice Modula3 typing speed?

CodeSpeedTest offers 10+ real Modula3 code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.