We need to kill C syntax for declaring function types
Don
nospam at nospam.com
Mon Oct 4 02:07:07 PDT 2010
A great example of how C syntax is hurting us.
---
I found this bit of code in std.container, inside BinaryHeap:
size_t insert(ElementType!Store value)
{
static if (is(_store.insertBack(value)))
{
...
}
else ...
What does the static if do? It's *intended* to check if _store has a
member function insertBack(), which accepts type of a 'value'.
But instead, it ALWAYS silently does the 'else' clause.
Unless _store.insertBack is a valid *type*, (eg, alias int insertBack;).
In which case it gives an error "declaration value is already defined".
Why?
This happens because
x(y); is valid C syntax for declaring a type 'y', such that &y is of
type 'x function()'.
The C syntax is unspeakably ridiculous, useless, and downright
dangerous. It shouldn't compile.
In the past, Walter has mentioned a weak argument for retaining C-style
array declaration syntax, although I personally find it very
unconvincing. But C's hideous function pointer syntax is on a whole
other level. It's really hurting us. I believe it should be deprecated
immediately. But the 'function type' syntax shouldn't be allowed even as
a deprecated syntax. It's horrible.
Patch included in Bug 4987.
More information about the Digitalmars-d
mailing list