This question already has answers here:
Are there things Elixir can do that Erlang cannot, or vice versa?
(4 answers)
Closed 6 years ago.
I read on the Elixir site that sooner or later a developer will want to include Erlang libs into their Elixir projects. Why would this be? Are there things that can only be done in Erlang?
I'd be just as happy learning Erlang instead of Elixir. Are there core things available in Elixir but not in Erlang?
Both languages are Turing-complete, so there's nothing that can be done in one and not in the other. The difference between the two is in the syntax.
Elixir developers use Erlang libraries because there are some excellent Erlang libraries out there and one of the advantages of living on the BEAM (Erlang VM) is that interoperability. (Just like how JVM languages get access to the vast array of Java libraries.) The most prominent example is Phoenix (popular Elixir web framework) using Cowboy (popular Erlang web server).
As Elixir continues to grow, you'll see more of the reverse, too: Erlang developers grabbing a useful Elixir library to use.
You can see packages for both languages (and they're all useable by both languages) at https://hex.pm
Related
We are hoping to develop a static code analyser for Elixir in order to detect concurrency issues (mainly deadlock and race conditions). We have some basic idea about the structure for the analyser, but our problem is which AST would be better suited for this task. As we have understood the Elixir compilation process creates an Expanded Elixir AST, Abstract Erlang Format and Core Erlang.
My question is out of these whether the Expanded Elixir AST or Core Erlang would be better for creating the Call Graph and Control flow graph. And if we use Core Erlang is it possible to work our way backwards from Core Erlang to find the source within the Elixir code for the issues identified by the analyser?
If anyone has some idea about this, your help would be really appreciated. :)
If the purpose is educational I would probably go with erlang. The compiling of erlang to beam will probably be a little more straightforward (if not a lot more) and as you develop your tool, you will probably find more resources/documentation on erlang ASTs. It's lower level than what most people do and you'll find more answers in the erlang community (probably won't be true in a few years). Overall, your tool would be simpler in erlang, with less moving parts.
I also found that project : https://github.com/rrrene/credo
More specifically, I think it will be practically difficult to work you way back to elixir code. From your perspective, after having implemented your tool, it will make sense. But that probably would not be the case for your average elixir developer. The more elixir matures, the more it tends to depart from core erlang concepts. It builds a lot of features on top of erlang, to the point where you can build entire web applications without knowing a single bit of erlang. Probably not the best approach but the fact that it's possible tells you how large the gap between the two languages can become.
This question is in the context of the Beam VM and the capabilities that it provides, not in the general context of what a Turing complete language can do. I want to invest some time to learn either pure Erlang or Elixir. I get the basic differences between the two and I am leaning towards Elixir because of the macros, better syntax and faster development of the language this day.
My question is: if I choose Elixir, will I stumble on something that I cannot do in it, but can do in Erlang? Can I use all the OTP stuff, all the Erlang libraries, code reload, etc. with Elixir?
I am not asking for someone's preference between the two; just facts about the possibilities of the languages. Preferably from someone who used both in production.
You shouldn't stumble on anything you can do in one that you can't in the other, since you can freely call Elixir code from Erlang and vice-versa. You can even easily mix Erlang and Elixir files in one project.
In Elixir:
:erlang_module.erlang_function(args)
in Erlang:
'Elixir.ElixirModule':elixir_function(args)
TL;DR - Start with Elixir
Erlang has a steeper learning curve compared to Elixir. Once you start learning Elixir, you will automagically start learning Erlang. Hence, start out with Elixir. Elixir is written in Erlang and Elixir. See distribution on Github (since Elixir is full of macros aka meta-programming).
You can use Elixir with Erlang and vice-versa, hence the full Erlang eco-system of 20+ years of libraries.
More details from Erlang Solutions
Elixir’s ‘out of the box’ productivity is accomplished by a strong focus on tooling and convenience in expression of data manipulation. System design is the same in Elixir and Erlang, but Elixir removes a lot of boilerplate code and is easier to extend. The removal of boilerplate raises productivity and allows programmers to get feedback faster – crucial when you want to launch your product to market as fast as possible. Less boilerplate also makes for happy developers, and happy developers are unsuprisingly productive developers.
Joe Armstrong's (Erlang inventor's) blog post about Elixir
Start here to learn about Elixir - Getting Started
Once you feel its going well, work your way towards practicing on Exercism and other resources.
Just to preface - I have only used Elixir in production and not Erlang.
I would honestly recommend Elixir. This is my opinion and not necessarily the right one for you, but below I will list my reasons why.
Productivity: I come from a Ruby/Rails background so the Elixir syntax and style is something that was very familiar to me. One of the main factors that helps me determine whether or not to learn a language is how productive I can be in it - mainly why I chose Ruby. Elixir is the same. I can work just as fast in it as I can Ruby with all the added benefits of concurrency and pattern matching.
Erlang: Since Elixir is built on top of Erlang and compiles down to erlang and the beam vm, you have access to every erlang module and package. So if you are worried about using elixir and missing out on all of the features of Erlang, you shouldn't be. Elixir even has it's own implementations of most of the bigger Erlang/OTP features such as GenServer, GenEvent etc.
Community/Resources: The Elixir community is really a great one. The slack channel is really popular and great way to get some answers for beginner questions. There are already some really good books written on the language (Programming Elixir 1.2 - Dave Thomas, Author of the Ruby Pickaxe) also that make getting into the language really easy.
Really, if you have a mess around with the two you will probably come to the same decision that Elixir is a much nicer language with all the features of Erlang + More. It's on the rise as well, I can't remember the exact numbers but I remember reading something from the Hex website (package manager) about a considerable increase in package downloads.
There are a few things. I think you can't make a recursive anon function in Elixir. Now to be fair this is something that in 8+ years of Erlang I don't think I have ever needed to do, and if I did it could be done easily in some other way. There are probably a few other things like that that quite honestly you can ignore.
In general, for things that most people care about anything you can Do in Erlang, you can do in Elixir and vice versa. The community on the Elixir side seems to be more active so I would suggest starting there. I have recently moved from Erlang to Elixir and with the exception of a few fancy things in Proper I can say that it is a pretty easy transition
I cannot find a clear definition of what Erlang/OTP is and what purpose does it serve. Can anyone give a brief introduction to what it is and what it does?
On erlang/otp, it says
Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecom, banking, e-commerce, computer telephony and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.
OTP is set of Erlang libraries and design principles providing middle-ware to develop these systems. It includes its own distributed database, applications to interface towards other languages, debugging and release handling tools.
You actually have your answer in the question
First Erlang is a programming language, Examples of other programming languages
Go
Python
Ruby
A programming language is a special language programmers use to develop applications, scripts, or other set of instructions for computers to execute.
Second OTP is a set of tools and libraries the one can use when building applications written in erlang
In programming, a library is a collection of already compiled code that a programmer can use in his program. Libraries are particularly useful for storing frequently used code.
Python has the Python Standard Library
Ruby has the Ruby Standard Library
Now OTP stands for Open Telecom Platform, While this is strange name to call a set of libraries, this name most due to the fact that the Erlang programming language was designed at the Ericsson Computer Science Laboratory. So OTP is the name of the erlang standard library, so while the name contains the term telecom the library is not about telecom anymore
I'm starting to dive into Erlang for the first time, and OTP is held aloft by lovers and critics alike as being the gold standard for highly available, distributed processing.
Given that OTP has been around for decades and is openly documented, why is it that other languages supporting lightweight threads/processes haven't adopted versions of their own? Are there technical/political challenges? Or does everyone just shrug and learn Erlang?
Thanks!
The largest issue is that most language runtimes don't have built-in lightweight concurrency and error isolation with exit signal propagation. Without those things you would have a really hard time properly porting OTP.
For the languages that do have the right kind of runtime, I am seeing some effort or at least plans to build OTP inspired frameworks. Cloud Haskell is the first that comes to mind. I also expect that Go and Rust will eventually have something like OTP if they don't already.
There are technical challenges, as Erlang itself is designed for the same features OTP is known for. Case in point, Basho Riak is a distributed fault-tolerant key/value store written in Erlang. One might be able to port it to Haskell or some similar functional language, but it would probably be a lot of work. Just for fun, you might look into OTP stuff written in the Elixir language.
Actually, it has been (tried).
Akka is the library which takes some OTP features and implements them in Scala for JVM.
Given the principles underlying JVM and BEAM (the Erlang VM) are very different (mainly GC, scheduling and message passing are radically different), I can't say how successful that implementation is and how many benefits of the original OTP it preserves. There's a lot of (heated) debate on that in the internets.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the best way to learn Erlang?
I'm interested in learning Erlang; I'd appreciate suggestions on resources - books, websites, etc. - that can help me along. So far I've learned quite a bit from Learn you some Erlang. At this point I'm comfortable with the syntax and most of the (basic) concepts. As a practice project I was thinking of writting a server socket app that serves xml data when conected, unfortunately, I'm not sure where to start - i.e. what libraries to use and how to use them. Thanks.
gen_tcp is Erlang's interface to TCP/IP sockets. You can find many examples of how to use it in Erlang/OTP libraries or in open-source applications. For example, take a look at these http server and client libraries: https://github.com/mochi/MochiWeb, https://github.com/cmullaparthi/ibrowse
Handling XML in Erlang is more painful than it should be. JSON might be a little bit easier, if you have an option to use it instead of XML.
For XML, there's a standard Xmerl library which is a part of Erlang/OTP. I found that the least painful way to extract necessary pieces from XML is to use XPath (xmerl_xpath:string). For XML generation, xmerl:export_simple is the way to go.
I've also used Erlsom library. I has a (rather) simple XML parsing interface.
trapexit has an excellent article for building a tcp server with OTP.