1. Home
  2. /
  3. Eiffel
  4. /
  5. Prime Checker

Prime Checker - Eiffel Typing CST Test

Loading…

Prime Checker — Eiffel Code

Checks if a number is prime.

class
	PRIME_CHECKER
feature
	is_prime (n: INTEGER): BOOLEAN
		local i: INTEGER
		do
		from i := 2 until i >= n loop
		if n \ i = 0 then
		Result := False
		return
		end
		i := i + 1
		end
		Result := True
		end
end

! Run
local
	p: PRIME_CHECKER
	num: INTEGER
do
	num := 13
	create p
	if p.is_prime(num) then
		io.put_string ("Prime"); io.put_new_line
	else
		io.put_string ("Not Prime"); io.put_new_line
	end
end

Eiffel Language Guide

Eiffel is a high-level, object-oriented programming language designed for software engineering with a strong emphasis on correctness, reusability, and maintainability. It supports the Design by Contract methodology, promoting robust and reliable applications.

Primary Use Cases

  • ▸High-reliability enterprise software
  • ▸Safety-critical systems
  • ▸Reusable component libraries
  • ▸Formal software engineering projects
  • ▸Educational use for software engineering principles

Notable Features

  • ▸Design by Contract
  • ▸Strong static typing
  • ▸Generic classes and collections
  • ▸Multiple inheritance with controlled resolution
  • ▸Automatic memory management (garbage collection)

Origin & Creator

Eiffel was created by Bertrand Meyer in the late 1980s at ETH Zurich and later developed further at Interactive Software Engineering.

Industrial Note

Eiffel is used in safety-critical systems, mission-critical enterprise applications, embedded systems requiring high reliability, and software frameworks emphasizing correctness.

Quick Explain

  • ▸Eiffel enforces object-oriented principles such as classes, inheritance, polymorphism, and genericity.
  • ▸Design by Contract allows developers to specify preconditions, postconditions, and invariants for software correctness.
  • ▸Used for building complex systems, safety-critical applications, and reusable libraries.

Core Features

  • ▸Classes, objects, and inheritance
  • ▸Preconditions, postconditions, invariants
  • ▸Genericity for reusable components
  • ▸Deferred (abstract) and effective (concrete) classes
  • ▸Exception handling and assertions

Learning Path

  • ▸Learn basic OO principles
  • ▸Understand Eiffel syntax and class structure
  • ▸Master Design by Contract methodology
  • ▸Practice with EiffelStudio IDE
  • ▸Build reusable components and libraries

Practical Examples

  • ▸Bank account management system with contracts
  • ▸Inventory management with inheritance
  • ▸Reusable generic container library
  • ▸GUI applications using EiffelVision
  • ▸Safety-critical simulation modules

Comparisons

  • ▸Higher emphasis on correctness than Java or C++
  • ▸Integrated contract system vs external testing
  • ▸Object-oriented like C++ or Java, but with design-by-contract
  • ▸Less widespread than mainstream languages
  • ▸Focus on software engineering rigor

Strengths

  • ▸Encourages correct and maintainable code
  • ▸Supports formal software engineering methodologies
  • ▸Highly reusable libraries via genericity
  • ▸Robust exception handling and error detection
  • ▸Object-oriented features fully integrated with contract-based programming

Limitations

  • ▸Smaller developer community compared to mainstream languages
  • ▸Limited third-party libraries and ecosystem
  • ▸Less industry adoption for modern web/mobile applications
  • ▸Verbose syntax for simple tasks
  • ▸Learning curve for Design by Contract concepts

When NOT to Use

  • ▸Small scripting tasks
  • ▸Modern mobile app development
  • ▸Rapid prototyping for web
  • ▸Highly dynamic or loosely typed systems
  • ▸Projects with tight integration with mainstream ecosystems without Eiffel libraries

Cheat Sheet

  • ▸class ACCOUNT
  • ▸feature
  • ▸deposit(amount: REAL)
  • ▸require amount > 0
  • ▸ensure balance = old balance + amount

FAQ

  • ▸Is Eiffel still relevant?
  • ▸Yes - for software engineering and high-reliability systems.
  • ▸Can Eiffel integrate with other languages?
  • ▸Yes - C/C++, COM, .NET, and web services.
  • ▸Does Eiffel support OO fully?
  • ▸Yes - classes, inheritance, polymorphism, and generics are all supported.
  • ▸What is Design by Contract?
  • ▸A methodology to enforce correctness via preconditions, postconditions, and invariants.

30-Day Skill Plan

  • ▸Week 1: Basic classes and objects
  • ▸Week 2: Contracts and assertions
  • ▸Week 3: Inheritance and polymorphism
  • ▸Week 4: Generic classes and reusable libraries

Final Summary

  • ▸Eiffel is a rigorously designed OO language for correctness, maintainability, and reusability.
  • ▸Its Design by Contract methodology enforces reliability in software systems.
  • ▸Used in high-reliability, enterprise, and safety-critical applications.
  • ▸Less mainstream but highly valued for software engineering best practices.

Project Structure

  • ▸Class files (.e)
  • ▸Library or module folders
  • ▸Project configuration files
  • ▸Generated binaries or executable
  • ▸Documentation and contract specifications

Monetization

  • ▸Enterprise software development
  • ▸Safety-critical application contracts
  • ▸Consulting for reliable system design
  • ▸Reusable library distribution
  • ▸Educational and academic usage

Productivity Tips

  • ▸Leverage EiffelStudio templates
  • ▸Reuse generic classes
  • ▸Write contracts for all critical features
  • ▸Use unit tests extensively
  • ▸Document invariants and assumptions

Basic Concepts

  • ▸Classes, objects, and references
  • ▸Features (methods) and attributes
  • ▸Preconditions, postconditions, invariants
  • ▸Generic classes
  • ▸Inheritance and polymorphism

Official Docs

  • ▸EiffelStudio Documentation
  • ▸Design by Contract Reference
  • ▸Eiffel Language Standard

More Eiffel Typing Exercises

Eiffel Counter and Theme ToggleEiffel Fibonacci SequenceEiffel Factorial CalculatorEiffel Sum of ArrayEiffel Reverse StringEiffel Multiplication TableEiffel Temperature ConverterEiffel Simple Alarm SimulationEiffel Random Walk Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher