Sunday, August 19, 2007

Erlang: The Introduction (Part 1)

Is Erlang really going to be the next Java according to Ralph's Blog? Erlang is really a powerful programming language, but thinking of it as a replacement for Java is not realistic. Developers are using Java over a decade now, they already have their applications, frameworks, libraries, ... etc. all written in Java. I don't see a clear reason to leave all this and start again from a scratch using another programming language. I am not completely against Erlang, although I am not completely with Java but I will try to predict the answer for the question I asked at the beginning. I will talk a bit about Erlang before I start comparing it to Java.

Introduction

Erlang is a general-purpose concurrent programming language and runtime system. It was designed by Ericsson to support distributed, real time, fault tolerant and non-stop application.

It was developed in the late 1980's by Ericsson to program the next generation of telecom applications. First it was used to program ATM Switches. It was released as open source in 1998 with the Open Telecom Platform (Erlang language, libraries and a real-time distributed database (Mnesia)) which I am going talk about it in details later.

Erlang is named after A. K. Erlang (Agner Krarup Erlang was a Danish mathematician, statistician and engineer, who invented the fields of traffic engineering and queuing theory). It is sometimes thought that its name is an abbreviation of Ericsson Language.

Erlang as a framework has a lot features:

Concurrent: has a process-based model of concurrency with asynchronous message passing

Real-time: intended for programming real-time systems where response times in the order of milliseconds are required

Continuous operation: has primitives which allow code to be replaced in a running system and allow old and new versions of code to execute at the same time

Robust: Safety is a crucial requirement in systems such as the above. There are three constructs in the language for detecting run-time errors.

Memory management: a symbolic programming language with a real-time garbage collector

Distribution: has no shared memory. All interaction between processes is by asynchronous message passing

Erlang is a functional programming language. It is different from C++, C#, and Java, which are Procedural Programming Languages.

Procedural languages: stress on the organization of data, and sequences of instructions which operate on some global state

Functional languages: treat programs as evaluations of functions without a global state

To have a good idea about the language I added simple examples to check:
  • Example 1: Hello World

This is the usual hello world program that displays "Hello World!" to the screen.

-module(hello).

-export([hello/0]).

hello() ->io:fwrite("Hello, World!~n", []).

  • Example 2: Factorial

This a simple factorial example.

-module(fact).

-export([fac/1]).

fac(0) -> 1;

fac(N) when N > 0 -> N * fac(N-1).


To be continued ...

No comments: