3 ms·
> and perhaps there could be a more concise enhancement of Erlang which would get the job done Erlang already is a more concise language than Elixir but also n
by astrowilson 6y ago
> and perhaps there could be a more concise enhancement of Erlang which would get the job done
Erlang already is a more concise language than Elixir but also noisier as there are more punctuation characters. I would love if Erlang would drop some of its punctuation, as some of it is frankly unnecessary.
Elixir syntax is definitely simpler than Ruby’s. Probably in the same ballpark as Python complexity wise: Elixir has less keywords and less rules thanks to the macro system but on the other hand more affordances, such as optional parenthesis.
- dmitriid 6y ago> Erlang already is a more concise language than Elixir but also noisier as there are more punctuation characters. What? Here's more-or-less the entirety of Erlang's "noisier syntax with more punctuation characters" -spec f(A :: any(), B :: some_type(), C :: list()) -> any(). f(A, {B}, [C | _]) -> A1 = fun() -> io:format(a, []) end, A1(), case C of <<1, _/binary>> -> 1; _ -> #person{ok = ok, field = C} end. Edit: %% plus map syntax #{"tuple" => {1,2}} M#{"key" := "new_value"} %% plus list comprehensions [X || X <- List, X /= 10]. Elixir has all that plus more. The equivalent in Elixir is something along the lines of @spec f(a :: any(), b :: some_type(), c :: list()) :: any() def f(a, {b}, [c | _]) -> a1 = fun() -> IO.inspect(a) end, a1.(), case C do <<1, _ :: binary>> -> 1 _ -> %Person{ok: :ok, field: c} end end ## and don't forget the capture and pipe syntax x |> (&f(y, {&1}, list)).() ## and default function parameters def f(a, b, c \\ []), do: something() ## and sigils String.replace(str, ~r".*", "") ## and Ecto adds its own characters id = 1 (from p in Person, where: p.id == ^id, select: p) |> Repo.all() ## and dropping down to Erlang is a function call on an atom :io.format(x, y) And I'm definitely forgetting more... Edit: ## and string interpolation a = 1 s = "The value is: #{a}" ## and two different map syntaxes %{a: :map, with: "various", keys: "as", atoms: 0} %{"another" => "map", "but" => "keys", "are" => "strings"} ## and different map access map[key] map.key ## and map update %{ map | key: "new_value" } ## and list comprehensions for x <- list, x != 10 do end
- dnautics 6y agoyou are conviently forgetting one thing: The equivalent of "hello world" in erlang is <<"hello world">> Not the best. Keyword lists in erlang are unpretty m:f(value, [{foo, <<"bar">>}, {baz, 47}]) Where in elixir you would do: :m.f(value, foo: "bar", baz: 47)
- dmitriid 6y ago> The equivalent of "hello world" in erlang is is "hello world". Edit: I know that "" in Elixir is binaries which are <<>> in Erlang. In Erlang "hello world" is really a list of ["h", "e", "l", "l", ...]. What was surprising to me is how rarely that matters (unless you actually do a lot of text processing). And the functions that matter (like I/O) deal with io_lists anyway. And since strings in Elixir are binaries, when you actually need to work with binaries, you're back to the same/similar syntax: <<0:1, 0:1, 1:1, 1:1>> == <<3:4>> %% Erlang <<0::1, 0::1, 1::1, 1::1>> == <<3::4>> ## Elixir > Keyword lists in erlang are unpretty Keyword lists in Elixir are nice, that's true.
- literallyWTF 6y agoMy god, it’s like Perl but somehow worse. How do you even keep track of what’s going on?
- astrowilson 6y agoThat’s not a representative example of none of the languages. It is also just plain invalid for Elixir. I recommend checking actual code examples on their websites to form a better opinion.
- dmitriid 6y agoIt's not that bad, really. As with most languages, syntax is the easy part. From personal experience: - You're comfortable with Erlang syntax within half a day. There's just so much less of it - You're comfortable with Elixir syntax within a day of two of active coding. Function captures may trip you up once or twice more, but then it's fine.