by TekMol · 3y ago · 0 comments
defmodule Math do
def sum(a, b) do
a+b
end
end
Compare that with Python: def sum(a, b):
return a+b
Having the name of the file be the name of the module and whitespace defining the blocks is the perfect approach for me.That said, code volume is never the issue, code clarity is. Right now you're comparing trivial examples, but what does in this case Pinterest's high volume spam detection code look like? I wouldn't judge a language on microscopic code snippets, or disregard them as "too noisy" when it usually isn't a deciding factor in programming languages.
Huh? TekMol explicitly points out that the python code also includes a module definition. It's just that the python module definition takes up zero characters in the source file. (Note that this is not always true, but in this case it is.)
It takes more than that, in the name of the file, but the Elixir file will also have to have a name, and the comparison ignores both of those equally.
Besides, the equivalent of Elixir's module (a struct with functions) is Python's class, not a plain file.
Sure, if you don't like having the name of a module/class at the top of a file that excludes a lot of language.
def sum(a, b), do: a+b -module(math).
sum(A, B) ->
A + B.