Discord uses Python for it's API and ELixir for realtime chat capabilities. Functional programming languages are off-putting for everyday uses but Elixir is just beautiful. Here's some musings.
> rem(4, 3)
1
It's very neat to depart from modulo. You want the remainder? Use rem!
The comparison rule is also clearly spelt. Amazing!
number < atom < reference < function < port < pid < tuple < map < list < bitstring
String formatting without weird f letters are welcome!
"Hello #{world_var}"
But concatenation using <>
is weird though
["a"] ++ ["b"]
sure gives a Python feel ["a"] + ["b"]
Map is convoluted though dict = %{:x => "a", "y" => :z}
but access feels at home: dict["hello"]
The iterables could be clearer, the end statement just bugs me: Enum.any?(["a", "aa", "aaa"], fn(s) -> String.length(s) == 3 end)
The .
is annoying in fn calls sum.(2, 3)
The pipe operator is really coool!
fucntion() |> decorator()
Documenting feels a lot like docstrings
defmodule Hello do
...
@doc """
"""
For comprehensions, i prefer the in keyword anytime
for x <- list, do: x+2
Filtering is sort of neat
for x <- 1..100,
i guess in Python we can do
is_even(x),
rem(x, 3) == 0, do: x[x for x in range(1, 100) if combined_conditions(x)]
Using <<int>>
to represent bytes is very interesting to have natively
The raise use is also very pythonic raise ArgumentError, message: "the argument value is invalid"
Concurreny is also weirdly simple:
defmodule Example do
def listen do
receive do
{:ok, "hello"} -> IO.puts("World")
end
listen()
end
end
pid = spawn(Example, :listen, [])
#PID<0.108.0>
It's also far more friendly than Erlang and more readable than Haskell!
Top comments (0)