Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can one make concurrent scalable reliable programs in C as in erlang?

a theoretical question. After reading Armstrongs 'programming erlang' book I was wondering the following: It will take some time to learn Erlang. Let alone master it. It really is fundamentally different in a lot of respects.

So my question: Is it possible to write 'like erlang' or with some 'erlang like framework', which given that you take care not to create functions with sideffects, you can create scaleable reliable apps as well as in Erlang? Maybe with the same msgs sending, loads of 'mini processes' paradigm.

The advantage would be to not throw all your accumulated C/C++ knowledge over the fence.

Any thoughts about this would be welcome

like image 945
Toad Avatar asked Mar 19 '09 18:03

Toad


People also ask

Is Erlang concurrent?

One of the main reasons for using Erlang instead of other functional languages is Erlang's ability to handle concurrency and distributed programming. By concurrency is meant programs that can handle several threads of execution at the same time.

Why is Erlang so scalable?

Scaling in Erlang is provided in two differ- ent ways. It is possible to scale within a single node by means of the multicore virtual machine exploiting the concurrency provided by the multiple cores or NUMA nodes. It is also pos- sible to scale across multiple hosts using multiple distributed Erlang nodes.

Is C language scalable?

Scalable C is standard portable C plus a mix of other technologies: The CLASS RFC defines the Scalable C language style. ZeroMQ provides message passing between threads and processes. CZMQ provides a core C library for Scalable C.

Why Erlang?

Erlang provides a simple and powerful model for error containment and fault tolerance (supervised processes). Concurrency and message passing are a fundamental to the language. Applications written in Erlang are often composed of hundreds or thousands of lightweight processes.


1 Answers

Yes, it is possible, but...

Probably the best answer for this question is given by Robert Virding’s First Rule:

“Any sufficiently complicated concurrent program in another language contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Erlang.”

Very good rule is use the right tool for the task. Erlang excels in concurrency and reliability. C/C++ was not designed with these properties in mind.

If you don't want to throw away your C/C++ knowledge and experience and your project allows this kind of division, good approach is to create a mixed solution. Write concurrent, communication and error handling code in Erlang, then add C/C++ parts, which will do CPU and IO bound stuff.

like image 128
gleber Avatar answered Sep 21 '22 22:09

gleber