Why use OTP with Erlang?
Asked Answered
G

2

9

As the question said: What benefits brings using the OTP design principles when developing with Erlang?

I am developing a server which will just receive commands and send responses.

Gonidium answered 4/5, 2011 at 8:16 Comment(0)
R
15

OTP is a battle-hardened set of design elements and idioms used in the creation of, as Jonas said, fault-tolerant systems among other things (like flexibility, live updates, etc.). In brief you want to use it for these environments, or environments that may grow into these, because a lot of the blood, sweat and tears of creating reliable, stable systems in Erlang is baked into the OTP behaviours and architecture. If you don't use them you'll either not have a fault-tolerant, flexible system or you'll recreate all of the decisions, one flub and error at a time, to create, in the end, what amounts to a clone of OTP.

So the question really is when don't you want to use OTP? You don't need OTP if you're not doing software that's intended to run for a long time with minimal interruption. You don't need OTP if you already have a framework that does its work that you're more familiar with. You don't need OTP if you want to learn (the hard way, perhaps) what decisions are behind OTP's designs. You don't need OTP if the cost of learning it (and there is a cost there!) exceeds the cost of system downtime for your software.

The best way to become familiar with the whys and wherefores of OTP is the OTP Design Principles User's Guide. Where the reasoning isn't directly stated, you can often read between the lines to discover the rationale for each component.

Retroflex answered 4/5, 2011 at 8:28 Comment(3)
Just to complete: "OTP provides library modules that implement the most common concurrent design patterns. Behind the scenes, without the programmer having to be aware of it, the library modules ensure that errors and special cases are handled in a consistent way. As a result, OTP behaviors provide a set of standardized building blocks used in designing and building industrial-grade systems."Gonidium
Not sure if it's allowed to plug a book here on Stack Overflow, but the free sample chapters 1 and 3 of manning.com/logan should give you an idea of what OTP is good for.Radar
I've seen lots of links to books in SO and PSE. Don't sweat it, RichardC. The worst that can happen is you get banned and hunted down like the dog you are! :DRetroflex
V
3

OTP contains some good design patterns for fault tolerant systems e.g. gen_server and supervising that may be interesting. It depends on what you want to do with Erlang.

E.g. If you want to run a website, you may be interesting to use Yaws and if you want a fault-tolerant website you may be using OTP with Yaws for supervision.

OTP also contains behavior patterns that can be useful.

Voltage answered 4/5, 2011 at 8:20 Comment(2)
@dkk: You may be interested in supervising your server, and restart it automatically if it crash. And maybe upgrade it at runtime with hot code swapping.Voltage
All that can be done without OTP. OTP is just a library that does it for you, and has been tested extensively (so it will be less prone to errors).Gonidium

© 2022 - 2024 — McMap. All rights reserved.