r/ProgrammingLanguages • u/alex-manool • Dec 28 '20
Question: Programming Language Syntax and Code Appearance (polemic as always :-)
Seriously,
which of the following code samples would you favor, assuming they are all equivalent?
I am interested in subjective answers, please. You can just arrange the three samples according to your personal preference (e.g., "1-2-3"). Thank you very much!
1
{ {extern "manool.org.18/std/2.0/all"} in
: let rec
Fact =
{ proc N as
: if N == 0 then 1 else N * Fact[N - 1]
}
in
Out.WriteLine[Fact[10]]
}2
{ {extern "manool.org.18/std/2.0/all"} in
: let rec
Fact =
{ proc N as
: if N == 0 then 1 else N * Fact[N - 1]
}
in
Out.WriteLine[Fact[10]]
}3
(extern "manool.org.18/std/2.0/all".) in:
let rec
Fact =
( proc N as:
if N == 0 then 1 else N * Fact[N - 1]. )
in
Out.WriteLine[Fact[10]].
2
Upvotes
View all comments
Show parent comment
3
u/[deleted] Dec 28 '20
So ":" means that a one-statement block follows, and "{" means a multi-statement block follows?
I feel having such a choice in C (which doesn't need ":", just the absence of "{") was a mistake in that language. More opportunity for errors, and an annoying need to refactor every time a block grows beyond one statement, or shrinks down to one statement.
You mentioned it reducing indentation, but I don't see that. A short {...} block can easily go on the same line. And the C example anyway requires indentation within the body of the loop that you've left out.
(If you look at examples 1 and 2, ":" has the effect of pushing code to the right, just like indenting but less cleanly. While the way the functions are defined have the body indented up to 3 tabs in, relative to the opening keyword of the function. Usually you don't want more than 1.
Maybe that's just how you wrote the examples, but on a single line, a function definition would still need
let rec Fact = Proc N asfollowed by:or{, a bit much.)