Sadraskol

The alien erlang syntax choices

Some developers still argue about which punctuation is the best. Some would support the C syntax with semicolon ; at the end of each line, something that would look like:

int main() {
  int a = 6;
  int b = 3;
  if (a > b) // notice this line has no punctuation
    printf("a is greater than b \n");
  return 0;
}

Others will say the best syntax is a ruby/python-like with no punctuation. You can write in elixir (very close to ruby):

def print_file do
  # notice the punctuation in the method
  File.stream!("scratch.txt")
  |> Enum.each(&IO.puts/1)
end

As you can notice, both school still compromise with or without punctuation when they need to. So the answer is not as simple as a yes or no. There is even a language for which learning the punctuation is rather difficult when coming from other languages: Erlang.

Punctuation in Erlang

Read this snippet taken from stackoverflow and try to focus on the punctuation at the end of the lines.

foo(X) when X > 0; X > 7 ->
    Y = X * 2,
    case Y of
        12 -> bar;
        _  -> ook
    end;
foo(0) -> zero.

The answer is much clearer than me, but if you don't want to open the link, here's the explaination. There are 4 possibilities to end the lines:

I think punctuation is always here in some way and there is no right or wrong in it. Erlang syntax is easier to read once you get used to it, but it's also more error prone. It's a matter of balance and personal preference here. I hope you won't blame Java and C to have constraining syntaxes anymore!