Building a commercial system: Pure Erlang or Erlang/OTP?
I am about to build a system with Erlang (my problem can be solved better with multiple CPUs) and I have skimmed through:
- Learn You Some Erlang;
- Erlang/OTP in Action
- Programming Erlang (Armstrong);
- Erlang Programming (Cesarini).
The Erlang/OTP in Action book (2) says: "...writing non-OTP Erlang code is really an advanced topic, and something that should be done only when you really really have开发者_如何学Go to. So perhaps not ever having done it the non-OTP way is a blessing because you will pick up the right habits straight away with regard to things OTP..."
(2) insists that commercial systems should be built with OTP only, whilst (4) gently shows that OTP is not the only way to do this.
Additionally, by reading (4) I have found out that building the knowledge from the very basics of Erlang helps to understand how OTP works (but not in the opposite way).
So, the question is: Should I choose Erlang/OTP to build a commercial system or can it be done with pure Erlang?
Learn and play with pure Erlang.
Build systems in Erlang/OTP.
can it be done with pure Erlang?
Yes, it can, subject to the analogue of Greenspun's Tenth Rule: your system will contain an ad hoc, informally-specified, bug-ridden, slow implementation of half of OTP.
OTP is written in Erlang so it definitely can be done in pure Erlang. That being said OTP provides you with a lot of useful functionality which you would otherwise need to write yourself. @Alexey is right than you will end up implementing a portion of OTP along the way. The problem is that the framework you need for building fault-tolerant systems, which OTP provides, has to itself be very fault-free.
I will also echo @Mazen in that experimenting with doing it in pure Erlang gives you a good feel for what is going on internally in OTP and how you can build fault-tolerant systems in Erlang. You will make better use of OTP afterwards. You will come to a better understanding when not to use OTP, and why.
If you read through the "Learn You Some Erlang" (like you said you have) you'll notice the author spends the Designing a Concurrent Application chapter building something half-useful in "plain Erlang". Then in the next 2 chapters, he basically throws it all away, and uses OTP to achieve the same thing with far less code (add to that the fact that because it's OTP code, it's standard - so other developers with familiarity with OTP will have a much better idea of where to look to understand it!)
The OTP has been developed and refined over a lot of years (initial release 1998 according to Wikipedia) with a large number of developers, and the backing of a large international company (Ericsson), and peer reviewed as it's all open source. I think it'd be a little audacious to assume you could single-handledly build something equally robust and scalable!
So use the OTP. Even for "play" projects, still use the OTP as it can only help you learn to make your "commercial" code better :)
精彩评论