@resuna OK, then let's talk about basics. What's the difference between while (foo)
and for (;foo;)
in C?
Or let's say I want to get element i
of array a
in C++. Which one of these is correct?
a[i]
a<:i:>
i[a]
*(a + i)
0<:i+a]
(Spoilers: It's all of them.)
How do I write logical conjunction? Is it a and b
or a && b
? (Answer: both.)
We could also talk about how the class
keyword in C++ is 100% redundant: 95% of its use could be replaced by struct
, the other 5% by typename
.
Or let's say I want to declare an integer constant:
const int answer = 42;
const int answer (42);
const int answer = { 42 };
const int answer { 42 };
const int (answer) = 42;
int const answer = 42;
signed const answer = 42;
int const signed answer = 42;
As far as I know, these are all valid.
(Half of them are valid C, too. The C example of a fully redundant keyword is auto
. The only thing that saves signed
from being redundant is the existence of signed char
, which is not a syntactic issue, but requires genuine language lawyering to fully explain.)
As for Python, I'm less familiar with it so I don't have a big list of examples ready. But I still found the following within a few minutes of looking:
What's the difference between 'abc'
, "abc"
, u'abc'
, u"abc"
, U'abc'
, and U"abc"
?
What's the difference between def succ(x): return x + 1
and succ = lambda x: x + 1
?
I have a variable x = 42
. Which of the following is the correct way to print its value?
print("x is", x)
print("x is " + str(x))
print(f"x is {x}")
print("x is %d" % x)
print("x is %d" % (x,))
No gratuitous extra syntax, my behind.
In my opinion there is nothing wrong with syntactic sugar in general. Having extra syntax doesn't necessarily make a language bad, let alone broken. (Let alone "deliberately broken"; no language outside of the esoteric/joke language group is deliberately broken.)
But somehow it is only Perl that gets a bad rap for admitting (and embracing) that usually "there is more than one way to do it".