Quote:
Originally Posted by Spirited
I also tried other functional programming languages such as Haskell and F#. I found that they were too radically different from what I was working with, and that they had different purposes than what I wanted to accomplish. I like C because most of what I was doing already related to C (in my C++ project, at least), and it has decades of support behind it.
Just in general, programming in a functional language has shown me just how unnecessary my implementations were. Like, I had five classes for constructing MySQL statements which inherit from an abstract command class with the interface for implementing a SQL statement class. I replaced those with a string table that I can insert into sscanf functions. That way I can very quickly just define a new type of statement or define my own.
So yeah, I'm getting some benefit from the change of thinking. It definitely requires a completely different thought process, which I've really enjoyed so far. It takes practice before driving straight in though, or that's what I found. I started by creating my own compiler for a very simple programming language called C1. That helped me put together my style for programming in C. I'd like to know more about Elixir, since you mentioned it runs on a VM. Is that similar to JVM in Java, or does it run bear metal?
Everyone knows that XML is the future of programming. I mean, who wouldn't want the possibility of an infinitely complex configuration file with the worst syntax and amount unnecessary padding imaginable? Get with the times, grandpa. (Edit: Just realized that I shit on XML as well. I wonder how many markup junkies that'll upset, lol).
|
So Elixir is running on the Erlang VM. Erlang is a programming language & VM built way back in the 1980's. The purpose of the platform was to run on massively parallel telecom systems. The whole platform is designed to be extremely fault tolerant, concurrent, and high availability.
Code is compiled down to beam byte code (similar to the JVM). When running code, you spin off processes. These processes are very tiny and communicate with each other by passing messages (Actor Model). On a standard laptop you could potentially spin up millions of processes that take advantage of all cores on your machine. WhatsApp uses Erlang to handle millions of connections per server.
For example, if you run the below function it will spin off 100,000 Erlang processes to map all 100K elements by applying a function. If you had a 100,000 core computer (I wish :)), this would run all in parallel.
Code:
Parallel.pmap 1..100_000, &(&1 * &1)”
Code:
defmodule Parallel do
* def pmap(collection, func) do
* collection
* |> Enum.map(&(Task.async(fn -> func.(&1) end)))
* |> Enum.map(&Task.await/1)
* end
* end”
Erlang also follows the pattern of "let it fail". Essentially you create supervisor processes that monitor child processes. If a child process dies, the supervisor can restart it. Erlang encourages you not to code defensively.
One use of this for a conquer server could be a mob supervisor. The mob supervisor will spin off mob processes and when a player kills the mob, the process dies and then the supervisor spawn up a new one to takes it place.
The platform also allows you to create distributed environment very easily. Basically you ping two nodes together and then you can spawn processes, send messages, etc between severs!.
Now as for Elixir... Elixir is a fairly new language (version 1.2) that is built on top of the same VM, gives you all the features of Erlang/OTP, has more features, and gives you a much more modern syntax (Some people describe it similiar to Ruby).
Anyways, whenever I learn a new language I usually try to implement a conquer server in it as it forces me to use almost every aspect of a language. Last year, when I was learning Scala I built a CO 1.0 server in it for testing. Source code is available below if anyone is interested. I will be attempting a server in Elixir once I'm fairly comfortable with the language :).
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]